Thursday, March 21, 2024

Reinstalling grub on my Debian 12 LVM LuksCrypt dual-boot laptop

So, Microsoft's latest Windows 11 update decided to blow away my dual-boot config because Microsoft apparently hasn't been involved in an antitrust lawsuit recently enough.  (Seriously, I liken this to buying a Ford vehicle and then discovering that it actively disables any non-Ford vehicles also parked in your driveway.  Not cool, Microsoft.)

Anyhow, since I run Debian 12 with LVM and an encrypted root filesystem, recovering the grub bootloader was a very manual process.  I'm adding the steps I used here for my own future reference.  Yours will probably be different.  This assumes you know your way around Linux, hardware device mappings, &etc.  Please don't ask me for help recovering your own system unless you're also offering me $200/hr for my time.

1. Boot Debian 12 install media, Advanced Options, "Rescue Mode"

2. Follow the prompts but then "continue with no root filesystem", drop to an installer shell

3. The encrypted LVM logical volume should already be in /dev/mapper.  Open it with 

    cryptsetup luksOpen /dev/mapper/$LVNAME $LVNAME_crypt

4. mount /dev/mapper/$LVNAME_crypt /mnt

5. Double check /mnt/etc/fstab to make sure the root fs name you used in cryptsetup is the one also here.  If not, unmount /mnt, close the luksCrypt mapping, and go back to step 3 but use the correct root mount point name for the mapping.

6. fdisk -l /dev/nvme0n1  (or whatever your drive is) to find the /boot and /boot/EFI partitions

7. mount them under the new rootfs:

        mount /dev/nvme0n1p4 /mnt/boot

        mount /dev/nvme0n1p1 /mnt/boot/efi

8. Attach all the virtual filesystems needed to make everything function:

        mount --bind /proc /mnt/proc

        mount --bind /dev /mnt/dev

        mount --bind /dev/pts /mnt/dev/pts

        mount --bind /sys /mnt/sys

9. chroot /mnt

10. Mount efivarfs under efivars 

        mount -t efivarfs none /sys/firmware/efi/efivars

11. Reinstall grub on the drive (not on one of the partitions)

        grub-install /dev/nvme0n1  # or whatever drive is appropriate

12. exit chroot and reboot to get back into your orphaned Debian OS.

Note:  I wasn't able to get grub-prober to find the Windows boot manager in rescue mode, so this returns the system to being able to boot Debian but not to the original multiboot. 

13. Boot into Debian 12

14. Re-enable os-prober in /etc/default/grub

15. grub-mkconfig >/boot/grub/grub.cfg

16. grub-install

Now everything should be back to the way it was.  Bill, I'll send you an invoice for the two hours of my morning you just stole from me.