LINUXMAKER, OpenSource, Tutorials

Repair GRUB in a live or rescue system

If you get into a system upgrade or kernel upgrade that allows you to boot into the system because Grub produces error messages, then the whole thing can be handled elegantly via a live system or rescue system. It does not matter if this is a rescue CD or a system started by the provider via PXE. The main thing, you are in the rescue system.

Preparing the chroot directory

As root su - you must first integrate the system partition, usually '/' on /dev/sda3 or a Raid1 /dev/md0 or an LVM like /dev/vg00-root, at a suitable place. We do this as follows.

mkdir /tmp/mnt
mount $ROOT /tmp/mnt

Now all active /dev, /proc and /sys directories are included, the root directory is placed on the new directory and finally all mounts are included.

for x in dev sys proc run; do
    mount --rbind /$x /tmp/mnt/$x
chroot /tmp/mnt
mount -a

Repair GRUB, install kernel images, leave chroot

From this point you can check or initiate the initdr by checking the initdr's.

update-initramfs -c -k all (4.19.0-5-amd64)
grub-install /dev/sda
grub-install /dev/sdb

Now you just need to unmount the whole thing as much as possible and create a reboot.