GRUB is a fairly simple yet crucial component of GNU/Linux operating systems. It’s the first program that is loaded at system boot and its task is to detect and load all the OSes installed on the machine. Even the slightest of issues with GRUB could yield an unbootable system. In such cases, the easiest solution is to reinstall GRUB altogether 👇
Chroot
For starters, you have to boot into the live environment of a Linux distribution of your choice, ideally the same one you are troubleshooting. Once inside the live environment you have to detect the root partition and mount it inside the /mnt
directory of the live system:
sudo mount <root-partition> /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --rbind /sys /mnt/sys
sudo mount --make-rslave /mnt/sys
sudo mount --bind /run /mnt/run
💡 You can use the lsblk
command to identify the partitions on your system.
If an EFI partition is present, mount that as well:
sudo mount <efi-partition> /mnt/boot/efi
Now you should be able to chroot into the installed system:
sudo chroot /mnt
Reinstalling GRUB
The command to reinstall GRUB takes different parameters if you’re running Legacy BIOS or UEFI.
Legacy BIOS
grub-install --target=i386-pc /dev/<disk>
⚠️ Choose the disk containing the root partition, not the root partition itself.
UEFI
grub-install --target=x86_64-efi --efi-directory=/boot/efi
⚠️ Check if the UUID matches the one specified in the /etc/fstab
file.
Now you have to regenerate GRUB’s configuration file. Type the following command:
grub-mkconfig -o /boot/grub/grub.cfg
Type exit
to get out of the chroot. Unmount all mounted filesystems:
sudo umount -R /mnt
Restart the PC. Now everything should be good to go ✌️