Restoring the GRUB bootloader on LVM-encrypted Debian 12

From SolaceWiki
Jump to navigation Jump to search

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: (substitude the Logical Volume name for $LVNAME)
    cryptsetup luksOpen /dev/mapper/$LVNAME $LVNAME_crypt
    mount /dev/mapper/$LVNAME_crypt /mnt
    
  4. 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.
  5. fdisk -l /dev/nvme0n1  (or whatever your drive is) to find the /boot and /boot/EFI partitions
  6. mount them under the new rootfs:
    mount /dev/nvme0n1p4 /mnt/boot
    mount /dev/nvme0n1p1 /mnt/boot/efi
    
  7. 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
    
  8. chroot /mnt 9. Mount efivarfs under efivars
    mount -t efivarfs none /sys/firmware/efi/efivars
    
  9. Reinstall grub on the drive (not on one of the partitions) substitute your primary drive device for nvme0n1
    grub-install /dev/nvme0n1
    
  10. exit chroot and reboot to get back into your orphaned Debian OS.
  11. Boot into Debian 12
  12. Re-enable os-prober in /etc/default/grub
  13. Rebuilt grub.cfg and reinstall it:
grub-mkconfig >/boot/grub/grub.cfg
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.