Introduction / Why This Is Needed
GRUB (Grand Unified Bootloader) is the first program that runs when a computer with Linux is powered on. Its task is to load the operating system, displaying a selection menu if there are multiple options. Due to failures (kernel updates, disk errors, incorrect configuration changes), GRUB can become corrupted, leading to errors like grub rescue> or a complete inability to boot. This guide will help you restore the bootloader's functionality using a Live CD/USB bootable media. After completing these steps, you will see the GRUB menu again and be able to boot your system.
Prerequisites / Preparation
Before you begin, ensure you have:
- A Live USB bootable media with any Linux distribution (Ubuntu, Fedora, or any other GRUB-supported distro is recommended). You can create it using Rufus, BalenaEtcher, or
dd. - Access to BIOS/UEFI to boot from the USB drive (usually the F2, F12, or Del key during startup).
- Basic terminal skills: ability to enter commands and change directories.
- Knowledge of the root password or the ability to run commands with
sudoin the Live environment (often therootpassword is disabled; usesudo). - Information about disk partitions: if you know where your root partition (
/) and possibly a separate/bootor EFI System Partition (ESP) are located, it will speed up the process.
💡 Tip: If you are unsure about your partition layout, don't worry—we will show you how to identify it in Step 2.
Step-by-Step Instructions
Step 1: Prepare the Live Media and Boot from It
If you don't have a Live USB yet, create one:
- Download a distribution image (e.g., Ubuntu Desktop).
- Write it to a USB drive (minimum 4 GB) using BalenaEtcher or the
ddcommand (on Linux/macOS):sudo dd if=/path/to/your/image.iso of=/dev/sdX bs=4M status=progress && sync
Replace/dev/sdXwith your USB drive's device (e.g.,/dev/sdb). Caution: selecting the wrong disk will result in data loss! - Reboot the computer, enter BIOS/UEFI (the key at startup, often F2, F12, Del), and configure booting from the USB device.
- Select the Try Ubuntu (or similar) option—this will launch the live environment without installing.
After booting, open a terminal (Ctrl+Alt+T).
Step 2: Identify Disk Partitions
In the Live environment, all disks are accessible but may have different names (e.g., your system disk /dev/sda might become /dev/sdb). Identify the root partition:
lsblk
You will see a list of devices and their mount points. Example output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 238,5G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi # EFI partition (UEFI)
├─sda2 8:2 0 64G 0 part /
├─sda3 8:3 0 16G 0 part [SWAP]
└─sda4 8:4 0 157,9G 0 part /home
Or use sudo fdisk -l for more detailed information.
What to look for:
- Root partition (
/)—usually the largest, typeLinux filesystem. In the example, this is/dev/sda2. - EFI System Partition (ESP)—small (100–500 MB), type
EFI System. In the example,/dev/sda1. If you have BIOS (an older PC), the ESP may be absent. - Separate /boot (rare)—type
Linux filesystem, mount point/boot.
Note the disk name (e.g., /dev/sda) and partition names. For subsequent commands, replace /dev/sda2 and /dev/sda1 with your own.
Step 3: Mount the Root File System
Now we will mount the root partition into the /mnt directory (the standard location for temporary mounts):
sudo mount /dev/sda2 /mnt
If you have a separate /boot partition (not part of the root), mount it:
sudo mount /dev/sdaX /mnt/boot # replace sdaX with your /boot partition
If you have UEFI (an ESP exists), mount it to /mnt/boot/efi (or /mnt/efi if the structure differs):
sudo mount /dev/sda1 /mnt/boot/efi
⚠️ Important: For UEFI, the ESP must be mounted at
/boot/efiinside the chroot environment; otherwise,grub-installwill not find the EFI files.
If you have BIOS, skip this step—an ESP is not required.
Step 4: Reinstall GRUB
Now we will "enter" the mounted system using chroot—this gives access to its utilities and files as if it were the real system.
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
You will be inside your system's root (the command prompt may change). Now perform the reinstall depending on your firmware type.
For BIOS (older PCs):
grub-install --target=i386-pc /dev/sda
Where /dev/sda is the entire disk, not a partition. GRUB will be written to the MBR (first sector).
For UEFI (modern PCs, most from 2012 onward):
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB
--efi-directoryspecifies the ESP mount point (should be/boot/efi).--bootloader-idis the bootloader's name in the UEFI menu (you can keepGRUBor setubuntu,debian, etc.).
If the command completes without errors, GRUB is installed.
Step 5: Update GRUB Configuration
After installation, you need to generate a new grub.cfg configuration file, which contains the list of kernels and partitions.
For Ubuntu/Debian and derivatives:
update-grub
For CentOS/RHEL/Fedora:
grub-mkconfig -o /boot/grub/grub.cfg
You should see output listing detected kernels and operating systems (e.g., "Found Windows Boot Manager on /dev/sda1").
Step 6: Reboot and Verify
Exit the chroot and unmount the partitions:
exit
sudo umount -R /mnt
Now reboot the computer:
sudo reboot
Remember to remove the Live USB drive when the manufacturer's logo appears, otherwise you will boot into it again.
If everything was done correctly, you will see the GRUB menu and be able to boot Linux (or Windows, if it was installed).
Verification
- The system boots without
grub rescue>orerror: no such partitionerrors. - The GRUB menu appears on startup (it might be hidden; press Shift or Esc to display it).
- All installed operating systems are available in the menu.
- After booting into Linux, run
sudo grub-install --recheck --target=i386-pc /dev/sda(for BIOS) orsudo grub-install --target=x86_64-efi --efi-directory=/boot/efi(for UEFI)—the command should complete successfully without warnings.
Potential Issues
Error: error: no such partition.
- Cause: GRUB cannot find the root partition specified in its configuration. Often, after a failure, the disk received a new name (e.g.,
/dev/sda2→/dev/sdb2). - Solution: Ensure the correct partition names are specified in
grub.cfg(file/boot/grub/grub.cfginside chroot), e.g.,(hd0,gpt2)for UEFI or(hd0,msdos2)for BIOS. It's best to regenerate the config viaupdate-grubfrom within chroot.
Error: grub rescue> or unknown filesystem.
- Cause: GRUB or its modules are corrupted; the partition is not found.
- Solution: Manually specify the correct partition in
grub rescue>:
Then boot and reinstall GRUB following the guide. Replaceset prefix=(hd0,gpt2)/boot/grub set root=(hd0,gpt2) insmod normal normalgpt2with your actual partition (uselsin rescue to check).
System still fails to boot after GRUB reinstall.
- Cause: The wrong disk was selected for
grub-install(e.g., installed on/dev/sdbbut booting from/dev/sda). - Solution: Ensure the
grub-installcommand targets the disk from which the system boots (usually the first SATA disk/dev/sda). Check the boot order in BIOS/UEFI.
UEFI grub-install error: failed to get canonical path of /boot/efi.
- Cause: The EFI partition is not mounted at
/boot/efiinside chroot or is not formatted as FAT32. - Solution: Verify the ESP is mounted at
/mnt/boot/efibeforechroot. If the partition is not FAT32, format it (mkfs.fat -F32 /dev/sda1) only if you are certain it contains no important data (usually ESP only holds bootloaders).
update-grub does not find Windows.
- Cause: Windows is installed in UEFI mode, but its bootloader is on a different disk, or the partition is hidden.
- Solution: Ensure all disks are connected. Run
sudo os-prober(in Ubuntu/Debian)—if it finds Windows butupdate-grubignores it, check that the lineGRUB_DISABLE_OS_PROBER=falsein/etc/default/grubis not commented out. Rerunupdate-grub.
Not enough space on ESP (UEFI) for GRUB installation.
- Cause: The EFI System Partition (usually 100–500 MB) is full of old bootloaders.
- Solution: Clean the ESP: mount it (e.g.,
sudo mount /dev/sda1 /mnt/efi) and delete old folders (likeubuntu,debian,Microsoft, etc.), keeping only the current ones. Be careful—deleting theMicrosoftfolder may make Windows unbootable.
GRUB menu does not appear after reinstall (auto-boot).
- Cause: GRUB configuration has a timeout of 0 or the menu is hidden.
- Solution: Edit
/etc/default/grubinside chroot:
Set:sudo nano /etc/default/grub
Save and runGRUB_TIMEOUT=10 GRUB_TIMEOUT_STYLE=menuupdate-grub.
Additional Recommendations
- Back up your ESP (for UEFI) or MBR (for BIOS) before making changes:
- BIOS:
sudo dd if=/dev/sda of=~/mbr-backup.img bs=512 count=1 - UEFI: copy the contents of
/boot/efito a safe location.
- BIOS:
- Use
efibootmgr(install theefibootmgrpackage in the Live environment) to manage UEFI boot entries:sudo efibootmgr -vshows all bootloaders,sudo efibootmgr -o 0001,0002sets the boot order. - For complex cases (RAID, LVM, encryption), additional configuration may be needed (e.g.,
grub-installwithlvmorcryptodiskmodules). Refer to your distribution's documentation.
After restoring GRUB, it is recommended to update your system (sudo apt update && sudo apt upgrade on Ubuntu/Debian) and check disk health (sudo smartctl -a /dev/sda).
This article covers the main GRUB recovery scenarios. If the problem persists, specify your motherboard model, firmware type (BIOS/UEFI), and the output of lsblk and sudo fdisk -l in the comments—this will help provide more precise advice.