Grub Rescue Commands to Fix Boot Issues

Written by: Bobbin Zachariah   |   Last updated: June 14, 2022

GRUB stands for GRand Unified Bootloader. It is the first software program which be run when your computer starts. The bootloader is in charge of loading and booting the operating system kernel. GRUB is the default bootloader for Linux kernel-based operating systems.

In some cases, you have to run both Linux and Windows on the same machine (Laptop or PC), and you may encounter some issues with GRUB. For example, if you install Windows after Linux installation, the Windows initiate its own bootloader on the MBR (Master Boot Record). So, GRUB is no longer available and you can't boot into the Linux OS.

This tutorial will go through some scenarios that make the GRUB unbootable and how to use GRUB commands in order to rescue your Linux OS from boot.

When will the grub rescue commands be used?

Nowadays, most Linux systems are using GRUB2 (grub version 2). GRUB2 is a replacement for GRUB bootloader.

If the GRUB can not find the grub folder or the contents inside are corrupted, The GRUB prompt looks like:

error: no such partition.
grub rescue > _

or

error: unknown filesystem.
grub rescue > _

or

grub > _

This error prevents you from booting into your operating system. The following sections will explain the way to fix this problem.

General Node: Getting into grub mode is general a very common issue when you do a dual boot. Most of the time the fix is to boot using Live USB and chroot into your installed system, then use os-prober and grub install

Grub rescue Commands

Each of GRUB failed modes can be fixed by the grub terminal or live CD installer.

At the grub command prompt, enter 'ls' to see the disk drives and available partitions:

grub > ls
(hd0) (hd0,msdos2) (hd0,msdos1)
grub > _

Where:

hd0: the hard disk

msdos: the partition type

Normally, the OS is booted from the first partition of the hard disk. In this case, to verify that the bootable partition is 'msdos1', let's run the following command:

grub > ls (hd0,msdos1)/

Next, let's explore the grub2 directory by running:

grub > ls (hd0,msdos1)/grub2

Output:

device.map  fonts  grub.cfg  grub.cfg.1590068449.rpmsave  grubenv  i386-pc  locale

As you can see, the grub in Linux has its own configuration file: 'grub.cfg'.

If you don't see this file, you can create it by running the command:

grub2-mkconfig

In order to boot your system, let's type:

grub > set root=(hd0,msdos1)

Output:

linux (hd0,msdos1)/vmlinuz-3.10.0-1127.13.1.el7.x86_64 root=/dev/sda1

Running the 'set root' will define the bootable partition. The default kernel is linux v3.10.

Now, we have to define the path to grub2 directory:

grub > set prefix=(hd0,msdos1)/grub2
grub > insmod normal

Then:

initrd (hd0,msdos1)/initramfs-3.10.0-1127.13.1.el7.x86_64.img

Here also, you will need to change the partition to your boot partition.

If you are unable to boot your system (which might be due to bad filesystem, or due to missing GRUB configuration file), you will need to boot from some other medium. You can use some bootable rescue CD or the Live CD of your distribution if available.

Once you have booted into your system, you might need to create the GRUB configuration files, if missing or if misconfigured. To create these configuration files, run:

$ update-grub

This command needs superuser privileges. So run this command (and the following commands in this article) as root.

The next step is to install GRUB on the MBR. This will fix the problem caused by Windows, in which Windows installs its bootloader on MBR, after installation of Windows over Linux. Here I assume that you have booted from the Live or rescue CD.

Now, before we go to the details of installing GRUB on MBR, we need to mount the root partition of Linux.

$ sudo mount /dev/sda1 /mnt

Here, the root partition is assumed to be '/dev/sda1'. This partition is mounted on /mnt directory. You can choose your own mount point, and your root filesystem partition may be different.

Now, we are ready to install GRUB. Run the following command:

$ sudo grub-install --root-directory=/mnt/ /dev/sda

This will install the GRUB on Master Boot Record. If you wish to install it on some partition, replace the last argument of the above command with the proper partition.

Grub rescue by boot-repair

Another way to rescue the grub on Ubuntu and almost of Linux distributions is using boot-repair tool. It's a graphical utility that can repair the Grub2 bootloader by some clicks.

You need to prepare a Live USB/DVD installer and boot into the live Linux environment. Then, let's connect your live OS to the Internet, install boot-repair by running the following commands:

$ sudo add-apt-repository -y ppa:yannubuntu/boot-repair
$ sudo apt-get update
$ sudo apt-get install -y boot-repair && boot-repair

The boot-repair tool will be launched and you can select the 'Recommend repair' button and follow the next steps to repair your bootloader.

Conclusion

In this tutorial, we learned how to use grub rescue command to fix the OS boot error. Thanks for reading and please leave your suggestion in the below comment section.

About The Author

Bobbin Zachariah

Bobbin Zachariah

Bobbin Zachariah is an experienced Linux engineer who has been supporting infrastructure for many companies. He specializes in Shell scripting, AWS Cloud, JavaScript, and Nodejs. He has qualified Master’s degree in computer science. He holds Red Hat Certified Engineer (RHCE) certification and RedHat Enable Sysadmin.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

2 Comments

2 thoughts on “Grub Rescue Commands to Fix Boot Issues”

  1. Hi.
    When I type “grub > set root=(hd0,msdos1)” I get no output.
    Should I just go on or is something already wrong ?

    (note : I actually typed grub > set root=(hd0,gpt2) since that’s where my root partition is)

    Reply

Leave a Comment