JRehkemper.de

Manually recover and boot form GRUB Shell

If you boot your computer and all you see is this

grub> _

something went wrong with your bootloader. But do not panic. This is not too difficult to solve..

The grub-shell gives you the possibility to browse your disks and find your existing operating system. It also allows you to boot your system manually.

How does Grub normally work

Normally when you boot your system you are greeted by the grub-menu. This is usually a very minimalistic list of your installed boot-partitions and operating systems. Every entry is nothing more than an explanation for grub where to find the necessary partitions to boot your system. Based on these information grub will execute some commands to execute the selected boot-target.

How to boot manually

Luckily we can execute the commands from the grub-entry manually on the grub-shell to rescue our system.

Identify the right Partition.

First you will need a list of your available partitions and partitiontables. This is done with the ls command.

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

msdos mean you are using an MBR partitiontable. Otherwise it would display gpt.

Next we need to find our root-filesystem. To do that use the ls command again and specify a partition as parameter. You can omit the labels of the partitiontable.

grub> ls (hd0,1)/
lost+found/ bin/ boot/ cdrom/ dev/ etc/ home/  lib/
lib64/ media/ mnt/ opt/ proc/ root/ run/ sbin/ 
srv/ sys/ tmp/ usr/ var/ vmlinuz vmlinuz.old
initrd.img initrd.img.old

You can also read files with cat.

grub> cat (hd0,1)/etc/os-release
NAME="CentOS Stream"
VERSION="9"
ID="centos"
ID_LIKE="rhel fedora"
...

This is useful if you have multiple operating systems installed and need to find out which one is the right one.

Specify Boot Parameters

To boot our system we need to tell grub where to find the important parts of the operating system.

First the root partition.

grub> root=(hd0,msdos1)

Then the Kernel to use.

grub> linux /boot/vmlinuz-5.14.0-410.el9.x86_64 root=/dev/sda1

Here we need to specify the root-partition again, but this time as /dev/ device. The translation looks like this:

hd0,1 = /dev/sda1
hd1,1 = /dev/sdb1
hd2,1 = /dev/sdc1
hd2,2 = /dev/sdc2

At last we need to define the initramdisk. It needs to have the same version as the kernel.

grub> initrd /boot/initramfs-5.14.0-410.el9.x86_64.img

Now we can boot our system.

grub> boot

If we’ve done everything right, you will be welcomed by your operating system. If not you have either specified a wrong path or your partition is gone.

GRUB Rescue

If you are in the GRUB Rescue shell, things are a little different. The Rescue shell is far more limited, since it couldn’t find the normal.mod file. Therefore we need to specify it first before we execute the same procedure as above. Again we assume that our root-partition is hd0,1.

grub rescue> set prefix=(hd0,1)/boot/grub
grub rescue> set root=(hd0,1)
grub rescue> insmod normal
grub rescue> normal
grub rescue> insmod linux
grub rescue> linux /boot/vmlinuz-5.14.0-410.el9.x86_64
grub rescue> initrd /boot/initramfs-5.14.0-410.el9.x86_64.img
grub rescue> boot

Making permanent Repairs

Everything you do in the GRUB-Shell is not permanent. That means you can not do any damage, but cannot fix anything either.

Once you booted into your os again, you should modify your grub configuration before the next boot. This is done by the update-grub script.

$ sudo update-grub

After that you need to install the configuration to the boot-sector of your disk. Since you install it to the disk and not the partition, you don’t need to provide a partition number.

$ sudo grub-install /dev/sda

After you should be able to safely reboot your system without getting stuck in the grub-shell again.

Addition Tricks

Enable Paging

If you need to scroll through a lot of output from a command, you should use a pager. That way you can go through the output page by page.

grub> set pager=1
profile picture of the author

Jannik Rehkemper

I'm an professional Linux Administrator and Hobby Programmer. My training as an IT-Professional started in 2019 and ended in 2022. Since 2023 I'm working as an Linux Administrator.