The GNU GRand Unified Bootloader automatically enters the rescue shell when it fails to find the root device or the path to its configuration file. This problem usually happens when you change the partition scheme without updating GRUB or write over some of the bytes in the master boot record. Use the GRUB rescue shell to manually set the root device and the path to the configuration file, and when GRUB enters this fallback mode, you need to reinstall the bootloader.
GRUB Rescue Shell
GRUB Rescue offers a limited set of commands to help you configure a one-time normal boot and repair GRUB from your operating system. Just because GRUB doesn't load properly doesn't mean your operating system is unbootable; the Linux filesystem is usually still intact and in good condition. However, Linux may be unbootable if you performed an unsafe operation such as moving a bootable partition. From the rescue shell, list the connected drives by entering “ls” (without quotes, here and throughout) at the prompt. A drive's number corresponds to the letter in its block ID. For example, (HD0, 1) stands for /dev/sda1, (HD1, 2) stands for /dev/sdb2, (HD2, 5) stands for /dev/sdc5 and so on.
Setting the Configuration Path
Use the “set” command to temporarily point GRUB to your root device and configuration file. After finding the device ID, enter the following commands to set the root and configuration path variables:
set root=(HD0, 2) set prefix=(HD0, 2)/boot/grub
Use the appropriate device ID in place of “(HD0, 2)” in the example. The “prefix” variable points GRUB to the grub.cfg file, which is located in /boot/grub on the primary partition. If your partition has moved or has a new name, pointing GRUB to the new location may still work.
Finding the Kernel and Initrd Image
To boot Linux, GRUB needs the kernel and initrd image locations as well as the root and configuration file paths. These files are located in the /boot directory along with the grub/ folder, but you must name them properly for GRUB to find them. Substitute your device ID in the following command to list the file names:
ls (HD0, 2)/boot
Set the kernel and initrd variables using the following commands:
linux (HD0, 2)/boot/vmlinuz-linux root=/dev/sda2 ro initrd (HD0, 2)/boot/initrd.img
Substitute your device for (HD0, 2) and the correct file names for “vmlinuz-linux” and “initrd.img” in the example. Alternatively, you may be able to type part of the file name and press “Tab” to complete the file name.
Booting Linux and Repairing GRUB
After setting the necessary variables, you can manually open the GRUB menu and boot as normal. Enter the following commands to load the normal module and open the GRUB menu:
insmod normal normal
Select your primary operating system using the arrow keys, then press “Enter” to boot. After booting into Linux, open a terminal window and reinstall GRUB on the device MBR. The installation command varies between Linux distributions, but in Ubuntu, you can use the following command:
sudo grub-install /dev/sda
Substitute your device's block ID for “/dev/sda” in the example, and do not specify a partition number, such as “/dev/sda2.”