Grub 2 toolbox


by - posted

Grub 2 toolboxGrub 2 toolbox Introduction

This article is designed as Grub 2 toolbox. If you run into boot problems, use the appropriate section to resolve it. With this minimal information, you should be capable to cover most of the Grub 2 problems. By the way, this document is also my toolbox in case of boot problems.

GRUB 2 device notation

In Grub 2, they harmonized the Grub 2 and Linux partition notation, for example hdn,1 represents sdx1 and so on. This was not the case in Grub legacy !

GRUB 2           Linux       harddisk    partiton

hd0,1               sda1        first             first
hd0,2               sda2        first             second
hd0,3               sda3        first             third
hd0, msdos6   sda6        first             sixth
hd1,1               sdb1        second       first
hd2,1               sdc1        third            first
hd3,1               sdd1        fourth         first

GRUB 2 directories

Grub 2 has basically three directories : user settings, scripts and one for the menu, etc.

/etc/default/grub            user settings
/etc/grub.d/                     scripts
/boot/grub/                      menu, environment data, fonts, modules, language files

/boot/grub/grub.cfg        menu configuration file (generated by scripts)

Installation with a live CD

A fresh Grub 2 installation can be done easily with a live media (CD…). After detecting the boot device, you run simply the installation. Remember that the installation works only with an intact partition table !

– Boot the Linux Live CD
– Detect the boot device :         # fsdisk -l  (The boot device will be “hda”, “sda”…)
– Write GRUB 2 to the MBR :    # grub-install /dev/sda    – replace sda with your boot device
– Reboot without the Live CD

GRUB 2 error displays

There are three error messages, namely the Grub 2 command prompt, the rescue prompt and the single word Grub.

– grub>
GRUB 2 has found the boot information but has been either unable to locate or unable to use the menu/configuration file grub.cfg.

– grub rescue>
GRUB 2 is unable to find the grub folder /boot/grub/ or its contents are missing/corrupted. A common reason for the grub rescue> prompt is an incorrect path to the /boot/grub/ folder. Other reasons for the prompt also include a failure to update GRUB 2 after certain system or partition operations or a failed installation.

– GRUB
This single word appears at the top left of the screen, with no prompt and no cursor.
The presence of the word GRUB indicates that GRUB 2 can not find it’s image files.

GRUB 2 repair

The methods below are working, if the kernel and the essential GRUB files are in place and not damaged !

Without a live CD

boot the kernel via the grub command prompt : grub>  or  grub rescue>  (details see below “Boot from GRUB 2 …”)
then : # update-grub
then : # grub-install /dev/sda        – replace sda with your boot device !

With the “rescatux” boot CD

boot the CD
choose GRUB 2
choose detect OSes
boot the appropriate kernel
then : # update-grub
then : # grub-install /dev/sda        – replace sda with your boot device !

Boot from the GRUB 2 CL

Booting will work with the following commands, if the kernel and the essential GRUB files are in place and not damaged !

Booting Linux

– find the boot device

grub>search -f /vmlinuz    shows for example : (hd0,1 or hd0,msdos1)

– boot the OS

Variant 1
grub>set root=(hd0,1)
grub>linux /boot/vmlinuzTAB root=/dev/sda1
grub>initrd /boot/initrdTAB
grub>boot

Variant 2
grub>linux (hd0,1)/boot/vmlinuzTAB root=/dev/sda1
grub>initrd (hd0,1)/boot/initrdTAB
grub>boot

use TAB for completion

Booting Windows

– boot the OS (standard)

grub>set root=(hd0,1)
grub>chainloader +1
grub>boot

Boot from GRUB 2 rescue

To successfully boot from the grub rescue> prompt, the grub folder must exist and contain the necessary GRUB 2 files and modules.
You have to detect first the the correct partitions (with a live CD), before starting the following commands.

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-3.13.0-29-generic root=/dev/sda1
grub rescue> initrd /boot/initrd.img-3.13.0-29-generic
grub rescue> boot

The GRUB rescue shell commands are different then the grub> shell commands. Tab completion should start working after you load the normal.mod and linux.mod modules.

If the configuration changes

Changes
After installing/removing an OS, run  # update-grub – this will call the scripts in /etc/grub.d/ then the /boot/grub/grub.cfg will be modified.

Menu
Changes should be made by the appropriate script files and NOT to the /boot/grub/grub.cfg file itself !

The GRUB 2 command shell

Some examples :

grub> cat /etc/fstab  :  do

grub> help  :  do

grub> exit  :  do or use ESC

grub> normal  :  extended GRUB menu

grub> ls  :  partition names

grub> chainloader (hd0TAB  :  list partition details

grub> ls /  :  filesystem

grub>ls (hd0,1) /  :  filesystem

grub> set  :  see where grub is located

grub> lspci  :  list all PCI devices

Further reading

If you enjoyed this article, you can :

– get post updates by subscribing to our e-mail list

– share on social media :

Leave a comment Cancel reply