How to Restore Grub Bootloader in Linux

A photograph of a person using a laptop in a table.

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.”

A window showing the welcome screen for Ubuntu Live.
  1. Open a terminal in your live distro environment.
A screenshot of the Ubuntu Live environment.
  1. 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$"
A window showing the current root filesystem for the machine.
  1. Mount your system’s root partition to your live distro’s “/mnt” directory:
sudo mount /dev/sda1 /mnt
A window showing the root partition being mounted inside the live session.
  1. Reinstall your GRUB binaries:
sudo grub-install --force --boot-directory=/mnt/ /dev/sda1
A window showing the GRUB reinstallation process for Ubuntu.
  1. Shut down the PC. Remove the USB drive and boot it up again. It should boot into your Linux OS.
  1. Refresh your system’s GRUB configuration file to reflect your machine’s current state:
sudo update-grub
A window showing the GRUB update process for Ubuntu.

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.

A screenshot showing the live Arch Linux environment.
  1. Determine your system’s root partition using lsblk:
lsblk
A screenshot showing all the available partitions in the current session.
  1. Mount your root directory to your live environment:
mount /dev/sda1 /mnt
  1. 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
A screenshot showing the process for mounting special files.
  1. Change the root of your current session over to your system:
chroot /mnt /bin/sh -i
  1. Reinstall your system’s bootloader binaries by running the following:
/sbin/grub-install --target=i386-pc /dev/sda
A window showing the reinstallation process for GRUB in Arch Linux.
  1. Reload your system’s GRUB configuration file:
/sbin/grub-mkconfig > /boot/grub/grub.cfg
  1. Press Ctrl + D to log out from your system’s root.
A screenshot showing grub-mkconfig program recreating the system's GRUB configuration.
  1. Test your new bootloader by rebooting your system:
reboot
A screenshot showing the reboot command in Arch Linux.

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.

A screenshot of the default Fedora live session.
  1. Find your machine’s root partition:
sudo fdisk -l | grep "Linux filesystem$"
A window showing the Linux filesystem partitions in the live session.
  1. 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
  1. Move the root filesystem to your “/mnt” directory:
sudo chroot /mnt/root bash
mount /dev/sd3 /
mount /dev/sda2 /boot
A window showing the chroot and additional mounts for Fedora.
  1. Remove all of the existing bootloader configuration files in your system:
rm -f /etc/grub.d/*
rm -f /etc/sysconfig/grub
A window showing the removal process for the default GRUB files.
  1. Create a new GRUB configuration file for your system:
grub2-mkconfig -o /boot/grub2/grub.cfg
  1. Install GRUB to your machine’s boot partition:
grub2-install --target=i386-pc /dev/sda
A window showing the GRUB reinstallation process for Fedora.

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 grub2-mkconfig to
“/boot/efi/EFI/fedora/grub.cfg.”

Image credit: Unsplash. All alterations and screenshots by Ramces Red.

Is this post useful?
Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Ramces Red
Ramces Red - Staff Writer

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.