Introduction
Grand Unified Bootloader (GRUB) is a tool for booting and loading operating system kernels. It is the default bootloader for systems based on the Linux kernel.
Attempting to boot another OS alongside Linux may result in the other system's bootloader overwriting GRUB. Without GRUB, Linux cannot boot up.
This article will show how to fix Linux boot failure using GRUB Rescue commands and the Boot Repair tool.
Prerequisites
- An account with sudo privileges.
- Command-line access.
Note: The tutorial below is written for GRUB 2, the current iteration of the GRUB bootloader.
What Causes GRUB Boot Issues?
The most frequent reason for GRUB not booting into the operating system involves another OS's bootloader overwriting GRUB boot configuration. Another cause may be an accidental removal of GRUB configuration files.
When GRUB cannot boot the system, a GRUB Rescue prompt appears.
The example above shows GRUB displaying the "no such partition" error before displaying the grub rescue
prompt. Another frequent GRUB error is "unknown filesystem," followed by the same prompt.
Sometimes, the screen may only show the grub
prompt.
GRUB Rescue Commands
Below is the list of the commonly used GRUB Rescue commands. Use the commands at the prompts mentioned in the previous section.
Command | Description | Example |
---|---|---|
boot | Start booting (shortcuts: F10, CTRL + x). | The command is issued without arguments. |
cat | Write the contents of a file to standard output. | cat (hd0,1)/boot/grub/grub.cfg |
configfile | Load a configuration file. | configfile (hd0,1)/boot/grub/grub.cfg |
initrd | Boot the system by loading an initrd.img file. | initrd (hd0,1)/initrd.img |
insmod | Load a module. | insmod (hd0,1)/boot/grub/normal.mod |
loopback | Mount an image file as a device. | loopback loop0 (hd0,1)/iso/image.iso |
ls | Display the contents of a directory or partition. | ls (hd0,1) |
lsmod | Display a list of loaded modules. | The command is issued without arguments. |
normal | Activate the normal module. | The command is issued without arguments. |
search | Search for devices. Option --file searches for files, --label searches for labels, --fs-uuid searches for filesystem UUID. | search -file [filename] |
set | Set an environment variable. If issued with no arguments, the command prints the list of all environment variables and their values. | set [variable-name]=[value] |
How to Fix GRUB Boot Failure
This tutorial covers two ways to resolve GRUB boot issues: the GRUB Rescue prompt and the Boot Repair tool.
Via GRUB Terminal
GRUB Terminal features commands that help diagnose and fix boot-related issues. Proceed with the steps below to fix the system's bootloader via GRUB Terminal:
1. Use the set command with no arguments to view the environment variables:
set
The example output shows that GRUB is set up to boot from the (hd0,msdos3)
partition:
2. Enter the ls command to list the available partitions on the disk:
ls
The output shows the partition list.
3. Find the partition containing the boot
directory:
ls [partition-name]
The example shows the boot
directory in the (hd0,msdos1)
partition.
4. Set the boot partition as the value of the root
variable. The example uses the partition named (hd0,msdos1)
:
set root=(hd0,msdos1)
5. Load the normal
boot mode:
insmod normal
6. Start the normal
boot mode:
normal
The normal
mode enables you to issue more complex commands.
7. Load the Linux kernel using the linux
command:
linux /boot/[linux-kernel-version] root=[partition]
For example:
linux /boot/vmlinuz-6.8.0-40-generic root=/dev/sda1 ro
8. Enter the boot
command.
boot
Check if the system now boots properly.
Via Live image
Another way to fix your GRUB boot issues is to use a Linux live image to boot from an external device:
1. Download a live Linux ISO image. This example uses the Ubuntu 24.04 LTS.
2. Use a tool such as Etcher to write the Linux image to an SD card or a USB flash drive.
3. Insert the bootable device and start the computer.
4. Choose language and keyboard, connect to the internet, then select Try Ubuntu.
5. Once the system loads, open the terminal and type the following command to add the repository for the Boot Repair tool:
sudo add-apt-repository ppa:yannubuntu/boot-repair
Press Enter and wait for the repository to be added.
6. Update the repository information:
sudo apt update
7. Install the Boot Repair tool:
sudo apt install boot-repair -y
8. Start the Boot Repair tool via the terminal:
boot-repair
9. Select the Recommended repair option.
Wait for the tool to finish repairing the bootloader.
Note: The Boot Repair tool is available as a live image, so you can boot it from an external drive without using another live OS.
How to Update GRUB Config File
When the system successfully boots up, ensure the GRUB configuration is current by running the following command:
update-grub
The command checks and installs the latest GRUB release on the system.
How to Reinstall GRUB
Follow the steps below to reinstall GRUB on your Linux system:
1. Mount the partition containing the OS installation. The example mounts the /dev/sda1
partition to the /mnt
directory.
sudo mount /dev/sda1 /mnt
2. Bind the /dev
, /dev/pts
, /proc
, and /sys
directories to the corresponding directories in the /mnt
folder.
sudo mount --bind /dev /mnt/dev &&
sudo mount --bind /dev/pts /mnt/dev/pts &&
sudo mount --bind /proc /mnt/proc &&
sudo mount --bind /sys /mnt/sys
3. Install GRUB.
sudo grub-install -root-directory=/mnt/ /dev/sda
4. Unmount the directories when the installation completes successfully.
sudo umount /mnt/sys &&
sudo umount /mnt/proc &&
sudo umount /mnt/dev/pts &&
sudo umount /mnt/dev &&
sudo umount /mnt
Conclusion
After reading this tutorial, you are better acquainted with tools that fix Linux boot failures on your system. The article introduced two utilities for fixing GRUB: GRUB Rescue and Boot Repair.
If you need more ways to fix boot-related issues, read How to Use fsck Command.