Revive Your Linux Bootloader with GRUB Rescue

Revive Your Linux Bootloader with GRUB Rescue

Fixing a broken Linux boot process can be daunting, but with GRUB Rescue, it's easier than you think Learn how to use the GRUB shell and rescue shell to get your computer up and running again Plus, explore other potential remedies to keep in your arsenal

There's no denying the sinking feeling that comes along with a computer that won't boot up. After all, without a functioning operating system, your computer is nothing more than an expensive paperweight. Unfortunately, diagnosing the root cause of the problem can be difficult, especially if you don't have access to Linux. That's where GRUB comes in. As the software that controls the boot process, GRUB allows you to choose which operating system you want to use. However, if supporting files or configurations are missing or damaged, GRUB won't work properly and your computer won't boot up.

GRUB 2, the advanced version of GRUB released in 2012, changed the way the "grub.cfg" file was created and allowed for booting from removable media. If an operating system cannot be loaded, the user may be left with a prompt in the minimalist GRUB shell, which can still perform basic actions to potentially resurrect the computer. The two types of GRUB shells are the "grub>" prompt and the GRUB rescue shell prompt.

Revive Your Linux Bootloader with GRUB Rescue


When your computer's boot process goes awry, you may find yourself stuck in the GRUB rescue shell. While more limited than the regular GRUB shell, this interface still offers enough functionality to help you boot your computer and address the root cause of the issue. However, keep in mind that the available commands differ from the usual Linux versions. For example, the ls command in GRUB shell functions differently from its Bash counterpart. To see the available commands, use the --help option.

The ls command in this context has only five available options, which is significantly less than the numerous options supported by ls in Bash. However, even with this limited set of commands, we can still address the issue at hand. To execute the command, simply type "ls" at the prompt and hit "Enter."

Revive Your Linux Bootloader with GRUB Rescue

The output must always include the placeholders

Revive Your Linux Bootloader with GRUB Rescue

and

Revive Your Linux Bootloader with GRUB Rescue

.

This computer has three items listed, including the first hard drive labeled as (hd0), followed by the first partition on the first hard drive labeled as (hd0,gpt1), and the second partition on the first hard drive labeled as (hd0,gpt2). The label "gpt" represents GUID partition table and is not necessary to be included when referring to a partition, although we must include the brackets "()". To inspect each partition individually, we will utilize the ls command.

ls (hd0,1)

ls (hd0,2)

Revive Your Linux Bootloader with GRUB Rescue

We’ve found that the second partition has a Linux file system on it. We’ll investigate a little further by looking at the root directory of that partition.

ls (hd0,2)/

Revive Your Linux Bootloader with GRUB Rescue


The partition containing the boot directory and necessary files for Linux, including GRUB files and boot images, is clearly identified. To issue commands on this computer, we will reference partition (hd0,2). However, on your computer, refer to the partition where your Linux installation is located. To view text files, the cat command can be used by adding the directory path and filename to the partition name, such as (hd0,2)/etc/issue. This is a helpful method for confirming the correct partition in multi-boot setups and for examining configuration files.

Revive Your Linux Bootloader with GRUB Rescue


Listing the files in the “/boot” directory is done using the ls command with the -l (long) and -h (human readable sizes) options. This can be achieved with the following command: ls -lh (hd0,2)/boot. To successfully boot the computer, it is necessary to inform GRUB that the Linux partition contains the boot files by setting root=(hd0,2). Additionally, the kernel to be booted from must be specified using the linux command along with the root directory specified using the standard Linux hard drive and partition naming convention.

To boot up our Linux system, we need to specify the root directory and kernel image. In this case, we're using the "vmlinuz-6.2.0-20-generic" kernel image located in "/boot" directory and the root directory is set to "/dev/sda2". However, the exact location and name of the kernel image can vary depending on your system's configuration. Additionally, we need to specify the RAM-based file system image to use during boot up, which should match the numerical component of the Linux kernel being used. The "initrd.img-6.2.0-20-generic" file in the "/boot" directory is used for this purpose.

Type "boot" and press "Enter" to start the system up into Linux. Although this has resolved the issue temporarily, it is necessary to fix GRUB to avoid the need of performing this step every time the computer is started. To accomplish this, execute "update-grub" to scan the system, determine the operating systems, and create a new GRUB configuration. It is essential to perform this task as the root user, hence, run "sudo update-grub". In some cases, it may also be required to reinstall the GRUB bootloader by using "grub-install".

Revive Your Linux Bootloader with GRUB Rescue


To install GRUB on your Linux drive, simply run the command "sudo grub-install /dev/sda" without specifying a partition. After rebooting your computer, it should start up normally. However, if you encounter a boot problem and end up in the GRUB rescue mode, your prompt will display as "grub rescue>".

Using the GRUB Rescue Shell

To execute the required commands in this shell, we need to utilize the ls command to locate the Linux partition, similar to how it's done in the GRUB shell. Once the partition is identified, proceed with the following commands. It's important to ensure that the drive identifiers and kernel version numbers are appropriate for your system. The insmod command is responsible for loading kernel modules.

- set prefix=(hd0,2)/boot/grub

- set root=(hd0,2)

- insmod normal

- insmod linux

To fix boot file issues in Linux, you can enter the following commands:

linux /boot/vmlinuz-6.2.0-20-generic root=/dev/sda2

initrd /boot/initrd.img-6.2.0-20-generic

Revive Your Linux Bootloader with GRUB Rescue


Simply type “boot” and hit “Enter” to reboot your computer. Once you have logged in, update GRUB with the update-grub command.

Other Possible Remedies

In case of missing boot files, like the “vmlinuz” and “initrd.img” files, you can use a Live DVD or a bootable Linux USB flash drive to boot your computer and copy the missing files into place.

Note that the “vmlinuz” and “initrd.img” files must have the same version numbers in them, because they work as a matched pair.