Reinstalling grub after losing dual boot

The situation is the following: I was running an TW/Windows dual boot on my laptop. I wanted to upgrade my SSD, so swapped out the SSD and installed W10 on it. When swapping back to my old SSD, it immediately boots to Windows. I guess it’s a EFI problem.

I followed a combination of this and this guide to reinstall grub/EFI on my encrypted BTRFS partition. I came up with the following steps, but run into trouble at step 6.

  1. Find right partition
    # fdisk -l

  2. Decrypt and mount partition

# cryptsetup luksOpen /dev/sda5 crypt
# mkdir /mnt/volume
# mount /dev/mapper/crypt /mnt/volume
  1. Find BTRFS subvolumes @, @/var, @/boot/grub2/x86_64-efi, @/boot/grub2/i386-pc
    # btrfs subvolume list /mnt/volume
    My BTRFS subvolumes look exactly like the ones in the openSUSE guide.

  2. Mount subvolumes using the correct ID from command above

# mkdir /mnt/my-root
# mount /dev/mapper/crypt -o subvolid=<ID for path @> /mnt/my-root
# mount /dev/mapper/crypt -o subvolid=<ID for path @/var> /mnt/my-root/var
# mount /dev/mapper/crypt -o subvolid=<ID for path @/boot/grub2/x86_64-efi> /mnt/my-root/boot/grub2/x86_64-efi
# mount /dev/mapper/crypt -o subvolid=<ID for path @/boot/grub2/i386-pc> /mnt/my-root/boot/grub2/i386-pc
  1. Bind /proc, /sys, /dev
# mkdir /mnt/my-root/proc
# mkdir /mnt/my-root/sys
# mkdir /mnt/my-root/dev
# mount /proc -o bind /mnt/my-root/proc
# mount /sys -o bind /mnt/my-root/sys
# mount /dev -o bind /mnt/my-root/dev
  1. Chroot
    # chroot /mnt/my-root

This returns:
chroot:failed to run command '/bin/bash': no such file or directory

When I execute #ls /mnt/my-root it returns boot dev etc home opt proc root srv sys usr var, so bin seems to be missing. What am I missing here?

That is wrong for Tumbleweed since a long time. The root subvolume is one of snapshots and should be default subvolume, so simple mount /dev/mapper/crypt /mnt/my-root should mount it. After mounting, show full output of

btrfs subvolume list /mnt/my-root
btrfs subvolume get-default /mnt/my-root
1 Like

Thanks for the quick response! This is what I get:

btrfs subvolume list /mnt/volume
ID 256 gen 31 top level 5 path @
ID 257 gen 6421 top level 256 path @/var
ID 258 gen 6065 top level 256 path @/usr/local
ID 259 gen 6065 top level 256 path @/srv
ID 260 gen 6417 top level 256 path @/root
ID 261 gen 6135 top level 256 path @/opt
ID 262 gen 6421 top level 256 path @/home
ID 263 gen 6016 top level 256 path @/boot/grub2/x86_64-efi
ID 264 gen 6016 top level 256 path @/boot/grub2/i386-pc
ID 265 gen 6327 top level 256 path @/.snapshots
ID 669 gen 6420 top level 265 path @/.snapshots/402/snapshot
ID 669 gen 6420 top level 265 path @/.snapshots/421/snapshot
and a few more snapshots

The get-default returns
ID 669 gen 6420 top level 265 path @/.snapshots/402/snapshot

That is your root. Just do

mount /dev/mapper/crypt /mnt/my-root
chroot /mnt/my-root
mount -a
1 Like

This is what I did now:

# cryptsetup luksOpen /dev/sda5 crypt
# mkdir /mnt/my-root
# mount /dev/mapper/crypt /mnt/my-root
# mount /proc -o bind /mnt/my-root/proc
# mount /sys -o bind /mnt/my-root/sys
# mount /dev -o bind /mnt/my-root/dev
# chroot /mnt/my-root
# mount -a

mount -a returns a lot of errors:

mount: /var: special device /dev/mapper/cr_root does not exist.
              dmesg(1) may have more information after failed mount system call.

And the similar errors for /usr/local, /srv, /root/, /opt, /home,/boot/grub2/x84_64-efi, /boot/grub2/i386-pc and /.snapshots.

Not sure if that can be ignored, but:

  • update-bootloader --reinit runs fine
  • grub2-install reports the following errors:
Installing for x86_64-efi platform.
EFI variables are not supported on this system.
EFI variables are not supported on this system.
grub2-install: error: efibootmgr failed to register the boot entry: no such file or directory.

efibootmgr -v gives the EFI variables are not supported on this system. error when chrooted, while on the host system it does successfully return output. What is missing?

Well, you obviously have to use the same names that are listed in your /etc/fstab or mount them manually.

Yes, you need additionally bind-mount /sys/firmware/efi/efivars.

Instructions that you were following are long outdated.

1 Like

For the mount -a that means I would have to manually mount the subvolumes? E.g.:
mount / -o subvol=/@/var /var

I also found out I was missing the binding of /sys/firmware/efi/efivars. :slight_smile:

I was able to reinstall grub and now am able to dual boot again. There is one problem though. The ability to boot from read-only snapshots is gone in grub. Could that have to do with the mount -a errors?

EDIT: nvm, sudo grub2-mkconfig -o /boot/grub2/grub.cfg resolves the issue. Thank you very much for the help @arvidjaar

Btw, would this be the correct way to manually mount the subvolumes?
# mount /dev/mapper/crypt -o subvol=/@/var /var

Yes, but it would have been easier to create /dev/mapper/cr_root instead.

Could be - likely, /.snapshots was not mounted.

1 Like

Got it; again, thank you very much!

I didn’t know how to do it, but I did it the dumbest way possible.

I copied the EFI folder of openSUSE and replaced it with the EFI folder of windown11, and I got it working !

1 Like