The GNU Grand Unified Bootloader (GRUB) is a powerful and flexible utility that links your motherboard’s BIOS to your operating system’s kernel. It works by loading a small program in your motherboard’s memory, which it uses to bootstrap a larger multiboot binary.
However, there are instances where GNU GRUB fails to load your operating system’s kernel. For example, a dual-boot setup with Linux and Windows often results in the latter wiping out the GNU bootloader. This tutorial shows you how you can recover your system by reinstalling GRUB using some of the most popular Linux distributions.
Restoring GRUB on Ubuntu and Debian
One of the quickest ways to reinstall GNU GRUB in Ubuntu and Debian is by booting a live copy of either distro. Doing this allows you to mount your system’s root partition and use the live distro’s GRUB binaries to recreate your system’s bootloader.
Note: once you boot the live USB, click “Try Ubuntu” to access the Desktop. Do not click “Install Ubuntu.”
- Open a terminal in your live distro environment.
- Find the device name of your system’s root partition. You can do that by running the following command:
sudo fdisk -l | grep "Linux filesystem$"
- Mount your system’s root partition to your live distro’s “/mnt” directory:
sudo mount /dev/sda1 /mnt
- Reinstall your GRUB binaries:
sudo grub-install --force --boot-directory=/mnt/ /dev/sda1
- Shut down the PC. Remove the USB drive and boot it up again. It should boot into your Linux OS.
- Refresh your system’s GRUB configuration file to reflect your machine’s current state:
Tip: while reinstalling GRUB will fix most multiboot issues, beginners may find the command line daunting. To that end, you can also fix GRUB through the graphical Boot Repair Utility.
Restoring GRUB on Arch Linux
Aside from Ubuntu and Debian, it is also possible to use a live copy of Arch Linux to restore your bootloader. One advantage of this is that live Arch Linux does not rely on any graphical display, so you can easily restore GRUB even on headless machines over SSH.
- Determine your system’s root partition using lsblk:
- Mount your root directory to your live environment:
mount /dev/sda1 /mnt
- Bind the live system’s process on your system’s root directory:
mount --bind /sys /mnt/sys mount --bind /proc /mnt/proc mount --bind /run /mnt/run mount --bind /dev /mnt/dev
- Change the root of your current session over to your system:
chroot /mnt /bin/sh -i
- Reinstall your system’s bootloader binaries by running the following:
/sbin/grub-install --target=i386-pc /dev/sda
- Reload your system’s GRUB configuration file:
/sbin/grub-mkconfig > /boot/grub/grub.cfg
- Press Ctrl + D to log out from your system’s root.
- Test your new bootloader by rebooting your system:
Good to know: Arch Linux can be a tough operating system for a novice user. Learn how it works and how you can install it even without extensive Linux knowledge.
Restoring GRUB on Fedora
Similar to Ubuntu and Debian, restoring Grub on Fedora is equally easy.
- Find your machine’s root partition:
sudo fdisk -l | grep "Linux filesystem$"
- Mount your system’s root partition and create a bind mount between it and your live session:
sudo mount /dev/sda3 /mnt sudo mount --bind /sys /mnt/root/sys sudo mount --bind /proc /mnt/root/proc sudo mount --bind /run /mnt/root/run sudo mount --bind /dev /mnt/root/dev
- Move the root filesystem to your “/mnt” directory:
sudo chroot /mnt/root bash mount /dev/sd3 / mount /dev/sda2 /boot
- Remove all of the existing bootloader configuration files in your system:
rm -f /etc/grub.d/* rm -f /etc/sysconfig/grub
- Create a new GRUB configuration file for your system:
grub2-mkconfig -o /boot/grub2/grub.cfg
- Install GRUB to your machine’s boot partition:
grub2-install --target=i386-pc /dev/sda
FYI: Systemd-boot is a next-generation bootloader binary for Linux. Learn what makes it special and how systemd-boot stacks up against the venerable GRUB.
Frequently Asked Questions
Is it possible to restore GRUB if my system is using LVM?
Yes. You can still restore GRUB even if your system is using LVM. To do this, run
ls /dev/mapper/*--vg-root to determine the absolute file path for your machine’s root partition. Use this absolute path instead of the traditional “/dev/sda1.”
Will restoring GRUB erase other operating systems in my disk?
No. A bootloader, by design, only knows where to find the first few bytes of an operating system’s kernel. Replacing your bootloader will not affect any existing operating system on your disk.
Is it possible to reinstall GRUB on a UEFI system?
Yes. To do this, you need to make sure that you have properly mounted the “/boot/efi” partition of your UEFI system. You also need to modify the value of the
--boot-directory flag in
grub-install to “/boot/efi.”
For Fedora, you also need to change the
-o flag for
Image credit: Unsplash. All alterations and screenshots by Ramces Red.
Our latest tutorials delivered straight to your inbox