Rescuing a Non-Booting GRUB2 Environment
When the GRUB bootloader fails to find its configuration file or its partition, you are dropped into one of two shells: the GRUB Shell (grub>) or the GRUB Rescue Shell (grub rescue>). This guide covers how to access these shells and manually boot your system.
Accessing the GRUB Shell
Section titled “Accessing the GRUB Shell”If the system doesn’t drop you into a shell automatically, you may need to interrupt the boot process manually.
1. Reaching the GRUB Menu
Section titled “1. Reaching the GRUB Menu”Depending on your system configuration (BIOS vs. UEFI), use the following keys immediately after the BIOS/Manufacturer splash screen:
- BIOS/Legacy: Hold the Shift key.
- UEFI: Tap the Esc key repeatedly.
2. Entering Command Mode
Section titled “2. Entering Command Mode”Once the GRUB menu (the list of available kernels) is visible:
- Press
c: This opens the GRUB shell (grub>). - Press
e: This allows you to edit the boot parameters of the selected entry.
Scenario A: The GRUB Shell (grub>)
Section titled “Scenario A: The GRUB Shell (grub>)”This shell appears when GRUB can load its modules but cannot find the grub.cfg file.
1. Identify Partitions
Section titled “1. Identify Partitions”List all partitions known to GRUB:
grub> ls2. Find the Boot Files
Section titled “2. Find the Boot Files”Inspect the partitions to find your kernel (vmlinuz) and initrd files:
grub> ls (hd0,1)/Note: If you have a separate /boot partition, the files will be in the root of that partition. If not, look in (hd0,1)/boot/.
3. Set Root and Load Kernel
Section titled “3. Set Root and Load Kernel”Once identified, set the root partition and point to the specific kernel and initrd versions:
grub> set root=(hd0,1)grub> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1grub> initrd /boot/initrd.img-3.13.0-29-generic4. Boot
Section titled “4. Boot”grub> bootScenario B: The GRUB Rescue Shell (grub rescue>)
Section titled “Scenario B: The GRUB Rescue Shell (grub rescue>)”This limited shell appears when GRUB cannot find its own directory (/boot/grub).
1. Set the Environment
Section titled “1. Set the Environment”Tell GRUB where its modules and root partition are located:
grub rescue> set prefix=(hd0,1)/boot/grubgrub rescue> set root=(hd0,1)2. Load Normal Mode
Section titled “2. Load Normal Mode”grub rescue> insmod normalgrub rescue> normalNote: If normal loads successfully, you will transition to the standard grub> prompt.
3. Load Linux and Boot
Section titled “3. Load Linux and Boot”If the system stays in the rescue environment after normal, load the Linux module manually:
grub rescue> insmod linuxgrub rescue> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1grub rescue> initrd /boot/initrd.img-3.13.0-29-genericgrub rescue> bootPost-Boot: Permanent Fixes
Section titled “Post-Boot: Permanent Fixes”Manual booting is temporary. Once you are back in your OS, you must repair the bootloader.
For Debian/Ubuntu Systems:
Section titled “For Debian/Ubuntu Systems:”sudo grub-install /dev/sdasudo update-grubFor RHEL/AlmaLinux/Fedora Systems:
Section titled “For RHEL/AlmaLinux/Fedora Systems:”sudo grub2-install /dev/sdasudo grub2-mkconfig -o /boot/grub2/grub.cfg