How to Recover from a Corrupted GRUB Bootloader: A Detailed Guide

Learn how to recover from a corrupted GRUB bootloader with this detailed step-by-step guide, including solutions for dual-boot systems.
GRUB Recovery Cover Image

Table of Contents

What is GRUB?

GRUB (GRand Unified Bootloader) is a crucial component in many Linux systems as it manages the boot process and allows users to choose between different operating systems or kernels. GRUB is flexible and can boot multiple OSes, making it a very versatile bootloader.

However, GRUB can sometimes become corrupted, often due to:

  • Improper shutdowns
  • Disk failures
  • Partition reconfigurations
  • Kernel or system updates gone wrong

Symptoms of a Corrupted GRUB Bootloader

If GRUB is corrupted, you might see one of these errors when you try to boot:

  • GRUB Error: Unknown Filesystem
  • GRUB rescue> prompt
  • grub.cfg not found
  • System stuck at "GRUB Loading..."

Understanding GRUB Corruption

GRUB can become corrupted due to several reasons, such as:

  • GRUB Configuration Errors: Problems in the grub.cfg file located at /boot/grub/
  • Accidental Deletion: Deleting essential boot files can cause GRUB to malfunction.
  • Partition Changes: Altering the partition tables without updating GRUB can break the bootloader.
  • Failed OS or Kernel Update: Sometimes an interrupted system update might leave GRUB in an incomplete state.

Prerequisites for Recovery

Before we start the recovery process, ensure you have the following:

  • A Linux Live CD/USB (e.g., Ubuntu, Fedora)
  • Basic command-line knowledge
  • Internet connection (optional, in case you need to download packages)

Step-by-Step Guide to Recovering GRUB

Step 1: Booting into a Live CD/USB Environment

Since your primary system is unbootable, you’ll need to boot from a Linux Live CD/USB.

  1. Download a Linux distribution ISO (e.g., Ubuntu) and create a bootable USB drive using a tool like Rufus.
  2. Boot from the USB by entering your system’s BIOS/UEFI and changing the boot order.
  3. Once you boot from the USB, select "Try Ubuntu without installing" (or the equivalent for your distro).

Step 2: Identifying Partitions

Now that you're in the live environment, you need to identify the partition where your Linux system is installed.

sudo fdisk -l

This command lists all partitions on your system. Look for the partition that has Linux installed, usually formatted as ext4 or xfs. Make a note of it (e.g., /dev/sda1).

Step 3: Mounting the Linux Filesystem

Next, we need to mount the Linux filesystem to allow us to access and repair the GRUB configuration.

sudo mkdir /mnt/linux

sudo mount /dev/sda1 /mnt/linux

sudo mount /dev/sda2 /mnt/linux/boot

sudo mount --bind /dev /mnt/linux/dev

sudo mount --bind /proc /mnt/linux/proc

sudo mount --bind /sys /mnt/linux/sys

Step 4: Reinstalling GRUB

With the filesystem mounted, you can now reinstall the GRUB bootloader to your primary disk.

sudo chroot /mnt/linux

grub-install /dev/sda

update-grub

exit

The command grub-install installs GRUB on the disk /dev/sda. Adjust the drive name if needed. Then, update-grub updates the configuration file.

Step 5: Verifying and Fixing Boot Issues

After reinstalling GRUB, unmount the partitions and reboot the system to see if the issue is fixed.

sudo umount /mnt/linux/dev

sudo umount /mnt/linux/proc

sudo umount /mnt/linux/sys

sudo umount /mnt/linux

sudo reboot

If everything goes well, your system should boot normally into GRUB, and you'll be able to choose your operating system or kernel to boot.

Example Fix: Recovering GRUB on a Dual-Boot System (Windows & Linux)

Imagine you have a dual-boot setup with Windows and Linux. After performing a Windows update, the Master Boot Record (MBR) is overwritten, causing GRUB to become inaccessible.

Follow these steps to recover GRUB:

  1. Boot into the Linux Live environment, as described earlier.
  2. Identify the Linux partition using the fdisk command:
  3. sudo fdisk -l
  4. Mount the Linux partition. Let's assume it's /dev/sda5 in this case:
  5. sudo mount /dev/sda5 /mnt
  6. Reinstall GRUB on the drive where your OS is located, typically /dev/sda:
  7. sudo grub-install /dev/sda
  8. Update the GRUB configuration to include Windows and other OS options:
  9. sudo update-grub
  10. Once GRUB is reinstalled, unmount the partition and reboot:
  11. sudo umount /mnt
    
    sudo reboot
  12. Upon reboot, the GRUB menu should now appear, allowing you to boot into Linux or Windows.

Conclusion

Recovering from a corrupted GRUB bootloader may seem daunting, but by following the detailed steps above, you should be able to restore your bootloader successfully. Whether you are dealing with a single OS or a dual-boot system, the GRUB recovery process involves booting into a live Linux environment, identifying and mounting your Linux partitions, and reinstalling GRUB.

It’s also good practice to backup your system before making major changes to partitions or installing updates to avoid GRUB-related issues in the future.