Booting from the GRUB command line

There are many reasons why you might have to boot your computer manually from the GRUB command line. They range from the simple, “I installed a new kernel and deleted the old without updating grub,” to, “oh crap, something terrible happened and I need to get into my computer!”

There are two versions of the GRUB command line. The first one, and hopefully one you’ll see most often is the standard prompt of:

grub>

The second, and more severe, occurs when GRUB cannot find you grub.cfg file, typically in /boot/grub/grub.cfg

grub rescue>

Unfortunately, both have different syntax.

Lets start with the “normal” prompt first. In order to see the disks installed in your system, you use the same ls command as you would if your computer would have booted.

grub> ls

To list the contents of a hard drive, you use ls but add the hard drive. Here I use the first hard drive (drive 0) and the first partition (partition 1).

grub> ls (hd0,1)/

Oh, and if you need to see long results, setting the pager will be quite helpful:

grub> set pager=1

In order to actually boot your system, you will need to set the location of the linux kernel and the root partition. In my example, these are /boot/vmlinuz-3.13.0-29-generic and /dev/sda1 respectively.

grub> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1

If you computer uses an initial ramdisk to boot (which is most likely does unless you have compiled or setup your own system), you need to set that as well.

grub> initrd /boot/initrd.img-3.13.0-29-generic

With those items set, you can finally issue the command to boot.

grub> boot

Once you get booted, you’ll probably want to remake your grub configuration file (though this is not strictly mandatory) and then update grub.

grub-mkconfig -o /boot/grub/grub.cfg
update-grub

If your system went down a little harder, you’ll see the rescue prompt. The ls command works the same.

grub rescue> ls
grub rescue> ls (hd0,1)/

But you have a few additional steps to preform.

First, you’ll need to set the prefix for where your grub install is located. In the below case, if is on the first partition of the first hard drive, in the /boot/grub directory:

grub rescue> set prefix=(hd0,1)/boot/grub

Similarly, you need to set the root location:

grub rescue> set root=(hd0,1)

Next up is loading the normal.mod and linux.mod modules:

grub rescue> insmod normal
grub rescue> normal
grub rescue> insmod linux

Now, as before, in the “normal” prompt, you’ll need to set the location of your linux kernel, the root directory, and the location of the initial ramdisk:

grub rescue> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1
grub rescue> initrd /boot/initrd.img-3.13.0-29-generic

Finally, you can issue the command to boot your system.

grub rescue> boot

If all goes well, you’ll be up and running in no time! Remember to remake your grub configuration file and update grub. Remaking the configuration file in this case is mandatory, as the reason GRUB went to the rescue prompt in the first place is because it could not locate the grub.cfg file.

grub-mkconfig -o /boot/grub/grub.cfg
update-grub

Hope this helps get a few non-bootable systems up and running again!

Tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.

Protected by WP Anti Spam