GRUB (Grand Unified Bootloader) is a tool for booting and loading operating system kernels and the default bootloader for systems based on the Linux kernel. It is the first software to run when a machine is switched on. However, users rarely see GRUB in action. It functions automatically and requires no user input.
You’ll see GRUB in action in a dual-operating system environment where Linux is one of the two OS on the machine. In some cases, the other OS’s bootloader may overwrite GRUB (the bootloader for Linux), resulting in the inability of the Linux system to boot up. In such cases, you may see the GRUB rescue mode where you get a minimal command prompt and limited access to the file system.
This article will show you how to fix Linux boot failure using GRUB rescue commands and the Boot Repair tool, allowing you to restore your GRUB boot loader and access the GRUB menu. We’ll walk you through the steps to regain control over your boot process and get your Linux system up and running smoothly.
Let’s discuss the GRUB boot issue in more detail before we go into the details of fixing the boot failure issues.
Table Of Content
- Why Do GRUB Boot Issues Happen?
- The GRUB Rescue Commands
- How to Use Grub Rescue Commands to Fix Linux Boot Failure
- How to Update GRUB Config file
- How to Reinstall GRUB
Why Do GRUB Boot Issues Happen?
One of the primary reasons for encountering issues with the GRUB bootloader and being unable to boot into the Linux OS is when the other operating system’s bootloader overwrites the GRUB boot configuration. This problem commonly arises when setting up a dual boot configuration with an existing Linux installation.
While rare, the issue can also happen when you accidentally remove GRUB configuration files from the system.
When GRUB encounters difficulties in booting the system due to these issues, it triggers the GRUB Rescue mode, preventing access to the regular GRUB boot menu. At this point, GRUB’s standard functionality is suspended, and you will see the following GRUB Rescue prompt.
GRUB shows the “no such partition” error message before presenting the GRUB rescue prompt. A related (and frequent) GRUB error is “unknown filesystem,” which also leads to the rescue prompt where you can use the GRUB rescue commands.
The GRUB Rescue Commands
This table overviews the GRUB Rescue basic commands, a short description, and example usage.
|boot||Starts booting (shortcuts: F10, CTRL + x).||The command is issued without arguments.|
|cat||Writes the contents of a file to standard output.||cat (hd0,1)/boot/grub/grub.cfg|
|configfile||Loads a configuration file.||configfile (hd0,1)/boot/grub/grub.cfg|
|initrd||Loads the initrd.img file.||initrd (hd0,1)/initrd.img|
|insmod||Loads a module.||insmod (hd0,1)/boot/grub/normal.mod|
|loopback||Mounts an image file as a device.||loopback loop0 (hd0,1)/iso/image.iso|
|ls||Displays the contents of a directory or partition||ls (hd0,1)|
|lsmod||Displays a list of loaded modules.||The command is issued without arguments.|
|normal||Activates the normal module||The command is issued without arguments.|
|search||Searches for devices||search –file [filename]|
|set||Sets an environment variable||set [variable-name]=[value]|
READ: With so many Linux distributions on the market, choosing the right one for your projects can be difficult. To help you out, we recommend our Kali Linux vs Ubuntu, Alma Linux vs CentOS, Rocky Linux vs CentOS, Arch Linux vs Ubuntu, and Amazon Linux vs Ubuntu articles.
How to Use Grub Rescue Commands to Fix Linux Boot Failure
Now that you have a working understanding of the OS boot issues and the common GRUB rescue commands, let’s go into the technicalities of how to use these GRUB rescue commands to fix Linux boot failure.
Prerequisites to Fixing Linux Boot Failures
You will need IPMI or KVM access to the server for booting the server into recovery mode and access to a CLI or shell.
Please note that the following tutorial is written for GRUB 2, the latest version of the GRUB bootloader.
How to Fix Boot Failure
We’ll now discuss two methods to fix GRUB boot issues.
Method #1: Use the Live Image
You can use a Linux live image to boot the system from an external device.
An alternative approach to resolving GRUB boot issues involves using a Linux live image to boot your system from an external device.
Build the Boot Device
Get a live Linux boot image to create the boot device. We’ll use the Ubuntu 20.04 ISO image for this demonstration. Similarly, we’ll use Etcher to transfer the Linux image to a USB drive. You can use the Linux image of your choice for your system.
Boot System With the Linux Image
Insert the bootable device into your computer and restart the system. If required, you should configure the USB boot for the system.
When the system boots, you will see the welcome screen. Click the Try Ubuntu option.
Access the terminal and enter the following command to add the Boot Repair tool repository.
$ sudo add-apt-repository ppa:yannubuntu/boot-repair
Next, update the package index:
$ sudo apt update
Install the Boot Repair tool with the following command:
$ sudo apt install boot-repair
Once the installation finishes, launch the Boot Repair tool from the terminal.
$ sudo boot-repair
Allow the tool to complete the bootloader repair process.
Method #2: Use the GRUB Terminal
The second method uses the GRUB terminal that you see after the error. This method uses a series of commands to repair the boot failure.
Start by using the set command without any arguments to display the Linux environment variables:
You can see that GRUB is configured to boot from the (hd0,msdos3) partition.
Next, use the ls command to display a list of the accessible partitions on the disk.
Next, use the ls command to locate the partition that contains the boot directory.
grub> ls [partition-name]
Assign the boot sector partition as the value for the boot variable. In this demonstration, it’s designated as (hd0,msdos1).
grub> set root=(hd0,msdos1)
Now, command load the normal boot mode.
grub> insmod normal
Initiate the normal boot mode that allows you to use more commands than the GRUB Rescue commands:
Load the Linux kernel by executing the linux command:
linux /boot/vmlinuz-4.2.0-16-generic root=/dev/sda1 ro
Finally, reboot the system with the boot command:
How to Update GRUB Config file
If you haven’t already, we highly recommend upgrading to the latest version to get the maximum benefits of GRUB 2.
To update the GRUB version in Linux, follow these steps that you can use with all popular Linux distros.
Start by running this command in the terminal:
For Debian/Ubuntu-based distributions:
$ sudo update-grub
For RHEL (Fedora, CentOS) distributions:
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
The update process may take a moment as it detects installed operating systems and generates a new GRUB configuration file.
How to Reinstall GRUB
If you need to repair GRUB on your system or reinstall the GRUB bootloader due to boot issues or system changes, follow these steps:
Boot your system from a live Linux device.
Next, you need to identify the partition where your Linux installation resides. You can do this with lsblk or fdisk -l commands. For the purpose of this demonstration, we assume it’s /dev/sda1.
Next, mount this partition with the following command:
$ sudo mount /dev/sda1 /mnt
Remember to replace /dev/sda1 with the actual partition where your Linux installation is located.
To ensure that GRUB can access the necessary system directories, bind mount /dev, /sys, and /proc:
$ sudo mount --bind /dev /mnt/dev
$ sudo mount --bind /sys /mnt/sys
$ sudo mount --bind /proc /mnt/proc
If you’re in the Linux environment, enter the following command to enter a chroot environment:
$ sudo chroot /mnt
Next, use the following command to reinstall GRUB. Remember that you need to specify the correct device where GRUB should be installed (usually the disk, not a partition):
$ sudo grub-install /dev/sda
Replace /dev/sda with the actual drive.
When the process finishes, round off by unmounting the mounted partitions:
$ sudo umount /mnt/dev
$ sudo umount /mnt/sys
$ sudo umount /mnt/proc
$ sudo umount /mnt
Using GRUB rescue commands to fix Linux boot failure is a valuable skill for any Linux user. Whether you’re facing bootloader issues or struggling with a system that refuses to boot, the steps outlined in this guide can help restore your Linux system to working order.
While GRUB Rescue can be a powerful tool, it’s essential to approach it cautiously and ensure you have a backup archive of important data before making any significant changes.
If you’re looking for reliable hosting solutions, consider RedSwitches, a dedicated bare metal hosting provider committed to offering high-performance and secure hosting solutions tailored to your specific needs.
We offer the best dedicated server pricing and deliver instant dedicated servers, usually on the same day the order gets approved. Whether you need a dedicated server, a traffic-friendly 10Gbps dedicated server, or a powerful bare metal server, we are your trusted hosting partner.
Q: What is grub rescue?
A: grub rescue is a command line interface that appears when the bootloader, called GRUB, encounters an error during the boot process.
Q: How can I fix a boot failure using grub rescue?
A: To fix a boot failure using grub rescue, you can use several grub rescue commands at the grub prompt.
Q: What are some common grub rescue commands?
A: Some common commands used in grub rescue include “ls”, “set”, “root”, “insmod”, “normal”, “boot”, and “configfile”.
Q: How can I fix a boot failure if I have a dual boot system?
A: If you have a dual boot system and encounter a boot failure, you can use grub rescue commands to fix the issue by selecting the correct partition and booting into the desired operating system.
Q: How do I check the partition table in grub rescue?
A: In grub rescue, you can use the “ls” command to list the available partitions and their corresponding filesystems.
Q: Can grub rescue fix a boot failure caused by a corrupted file?
A: Grub rescue commands can help fix boot failures caused by corrupted files as long as the issue is related to the bootloader or partition configuration.
Q: What should I do if I can’t boot into any operating system?
A: If you cannot boot into any operating system, you can try booting from a live OS or using another computer to access and repair the affected hard drive.
Q: How can I upgrade the version of GRUB used in grub rescue?
A: To upgrade the version of GRUB used in grub rescue, you will need to follow specific steps depending on your Linux distribution. We recommend referring official documentation for your distribution for the correct procedure.
Q: What are the next steps after using grub rescue to fix a boot failure?
A: After using grub rescue to fix a boot failure, you can proceed to reboot your system and verify if the issue has been resolved. If the problem persists, further troubleshooting may be required.
Q: Can I use grub rescue to repair the Master Boot Record (MBR)?
A: Yes, you can use grub rescue to repair or restore the Master Boot Record (MBR) if it becomes corrupted or damaged.