Repairing Corrupt Boot Partition

As an extra layer of security, albeit minor, I have my EFI and boot partition on a removable USB stick. The other day that drive shifted the bit and my system was left unbootable. I am so accustom to fixing problems with my Gentoo machine that I had to stop and think about how I was going to repair my Debian laptop. The general process is the same for each distribution:

  • Install necessary drivers and packages (i.e., mdadm or cryptsetup)
  • Start mdadm and/or LVM if needed.
  • Decrypt partitions or volumes and mount
  • Format boot partitions or volumes
  • Bind mount virtual filesystems
  • chroot
  • Re-install kernel package and grub
  • Done

Requirements

  • Live CD/DVD image burned on bootable media

Process

Download and burn the Live CD/DVD to whatever your preferred media is and boot from it.

Debian


apt-get update && apt-get -y upgrade
apt-get install -y lvm2 mdadm
mdadm --assemble --scan
vgchange -ay
cryptsetup open /dev/mapper/vg-root root
mount /dev/mapper/root /mnt
parted /dev/sdc mklabel gpt mkpart "" 1MiB 3MiB mkpart "" vfat 3MiB 4099MiB mkpart "" ext4 4099MiB 8195MiB set 1 grub_bios on set 2 esp on 
mkfs.vfat /dev/sdc2
mkfs.ext4 /dev/sdc3
mount /dev/sdc3 /mnt/boot
mkdir /mnt/boot/efi
mount /dev/sdc2 /mnt/boot/efi
for i in /dev /dev/pts /proc /sys /run; do mount -B $i /mnt$i; done
chroot /mnt
apt-get install --reinstall linux-image
grub-install /dev/sdc
grub-update

Gentoo


mdadm --assemble --scan
vgchange -ay
cryptsetup open /dev/mapper/vg-root root
mount /dev/mapper/root /mnt/gentoo
parted /dev/sdc mklabel gpt mkpart "" 1MiB 3MiB mkpart "" vfat 3MiB 4099MiB mkpart "" ext4 4099MiB 8195MiB set 1 grub_bios on set 2 esp on 
mkfs.vfat /dev/sdc2
mkfs.ext4 /dev/sdc3
mount /dev/sdc3 /mnt/gentoo/boot
mkdir /mnt/gentoo/boot/efi
mount /dev/sdc2 /mnt/boot/efi
for i in dev proc sys ; do mount --types $i /mnt/gentoo/$i ; mount --rbind /$i /mnt/gentoo/$i ; done
chroot /mnt/gentoo
genkernel all
grub-install /dev/sdc
grub-update

Links