We all have been to a place in our lives where our machine fails to boot with the infamous “GRUB Rescue” command-prompt. This short document explains how to re-install GRUB2 and generate grub.cfg (menu entries).
Requirements:
- Machine on which the boot-loader is to be installed
- Linux Live USB/CD/DVD. Any disk capable of a chroot environment will do
Process:
- Open up a terminal if you’re using a live session
- Execute lsblk and check what node corresponds to the root partition of your distribution (I’ll be using /dev/sda1 as an example)
- sudo bash (get a root bash for all the succeeding commands)
- mount /dev/sda1 /mnt (mount root partition on /mnt)
- mount -t proc none /mnt/proc (mount proc)
- mount –rbind /dev /mnt/dev (mount dev)
- mount –rbind /sys /mnt/sys (mount sys)
- chroot /mnt /bin/bash (changing root to /mnt and bash is shell).
- Make sure GRUB2 is already installed. If not, install it from the package manager. The package may have different names, depending on your distribution. In Arch Linux, it is called grub-bios. In Gentoo, it has to be unmasked before proceeding with the installation
- grub-install /dev/sda (install GRUB to MBR)
- grub-mkconfig -o /boot/grub/grub.cfg (generate grub.cfg)
- exit (exit the fake root environment)
- Unmount all the partitions – umount -l /mnt/dev{/shm,/pts,} && umount -l /mnt/gentoo{/boot,/proc,}
- cd (change directory to default)
- reboot
Well, that’s pretty much it, but here are a few extra pointers:
- A good source of info on GRUB2 can be found here: https://help.ubuntu.com/community/Grub2/Installing Though it is Ubuntu specific in a way, it may help you resolve some of your problems.
- Another excellent source is the Arch wiki: https://wiki.archlinux.org/index.php/GRUB
- Instead of mounting all the temporary file systems (like proc, sys and dev) before chrooting, you can use the arch-chroot script instead. It is part of the arch-install-scripts package.
- If GRUB does not have entries for Windows OS (in case you’re dual booting), make sure you have os-prober installed.
- If your boot resides on a separate partition, you’ll need to mount it too. (mount /boot /<mount-point>/boot).