The following is the GNU All-permissive License as recommended in https://www.gnu.org/licenses/license-recommendations.en.html
Copyright (C) 2024 Free Software Foundation sysadmin@fsf.org
Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.
Contributions are welcome. See https://savannah.gnu.org/maintenance/fsf/.
Why?
Grub has failed to install, upgrade, or be configured properly to the point the system cannot boot. The grub recovery console is not available in times like this.
How?
To boot strap yourself into grub, the best way is to chroot the system from a fully working system. A live USB/CD image would do this, as well as simply pulling the drive and mounting it on ones workstation. Once you have access to a working system, this is the proccedure:
In this setup we will assume the following:
- You are booting off a USB image, /dev/sda.
- Your target system (broken grub) is /dev/sdb.
- /dev/sdb1 is /boot
- /dev/sdb2 is /
Mount the target
Mount the target system, in this example we will use /mnt
mount /dev/sdb2 /mnt
Next, mount the /boot partition into the `/mnt' target.
mount /dev/sdb1 /mnt/boot
Bind mount your system to the target
We wil have to bind mount /dev, /sys, and /proc into the target
/mnt' system so that we can trick
grub-install' into thinking our system is really running:mount -o bind /dev /mnt/dev mount -o bind /proc /mnt/proc mount -o bind /sys /mnt/sys
Chroot to the target, and install grub.
Now we can do what we came here for, chroot and install grub. First, chroot:
chroot /mnt
If the above command worked, you can now install grub to the target disk, /dev/sdb:
grub-install /dev/sdb
Exit the chroot, and cleanup
Exit the chroot:
exit
Remove all the bind mounts, then unmount the partitions:
umount /mnt/sys umount /mnt/proc umount /mnt/dev umount /mnt/boot umount /mnt