Introduction / Why This Is Needed
Do you see the grub rescue> prompt instead of the regular GRUB menu when booting Linux? This means the bootloader cannot find its files or configuration. The system won't start, but your data on the disk is safe. This guide will help you temporarily boot into rescue mode and fully restore GRUB so you can see the OS selection menu again. We'll cover the most common distributions: Ubuntu, Debian, CentOS, RHEL, Fedora.
Prerequisites and Preparation
Before you begin, ensure:
- You have console access — you are at the
grub rescue>prompt. - You know which partition contains Linux — if unsure, we will find it.
- You have prepared a bootable medium (LiveCD/USB) with any Debian/Ubuntu or CentOS/RHEL-based distribution. It will be needed for the final step — reinstalling GRUB.
- Administrator privileges when working with the LiveCD (usually available by default).
⚠️ Important: If you do not know which specific partition contains your system, do not run the
set rootcommand randomly. This could lead to errors.
Step-by-Step Instructions
Step 1: Identify Disk Partitions in Rescue Mode
At the grub rescue> prompt, run:
ls
You will see a list of devices, for example:
(hd0) (hd0,msdos1) (hd0,msdos2) (hd0,msdos3)
or for GPT:
(hd0) (hd0,gpt1) (hd0,gpt2) (hd0,gpt3)
Now, check each partition for the /boot folder or kernel files (vmlinuz*, linux). For partition (hd0,msdos1):
ls (hd0,msdos1)/
If the output contains boot or files like vmlinuz-5.4.0-42-generic, this partition most likely contains your system. Repeat for all partitions until you find the correct one.
💡 Tip: If
lsshowsFilesystem is unknown, the partition likely does not contain Linux or has an unsupported filesystem (e.g., NTFS). Skip it.
Step 2: Set the Root Partition
Assume you found partition (hd0,msdos1). Set it as the root:
set root=(hd0,msdos1)
GRUB will remember this partition for further operations.
Step 3: Load the Kernel and initrd
Now you need to specify the path to the kernel (vmlinuz or linux) and initrd (initrd.img or initramfs). First, see what's in /boot on your partition:
ls (hd0,msdos1)/boot/
Example output:
vmlinuz-5.4.0-42-generic
initrd.img-5.4.0-42-generic
grub
Load the kernel (substitute your actual filenames):
linux /boot/vmlinuz-5.4.0-42-generic root=/dev/sda1 ro
/boot/vmlinuz-...— path to the kernel relative to root (/).root=/dev/sda1— important: specify the device of your root partition (the one you found in step 1). Usually it's/dev/sda1,/dev/nvme0n1p1, or similar. If unsure, you can temporarily useroot=/dev/sda1, but the exact path is better.ro— mounts the root partition as read-only during boot (standard parameter).
Then load the initrd:
initrd /boot/initrd.img-5.4.0-42-generic
⚠️ Attention: If you have CentOS/RHEL 7+, filenames may differ, for example:
- Kernel:
vmlinuz-3.10.0-1127.el7.x86_64- Initrd:
initramfs-3.10.0-1127.el7.x86_64.imgAlways check the contents of/boot!
Step 4: Boot the System
boot
If done correctly, the system will temporarily boot. This does not fix GRUB permanently, but it gives you OS access for further actions.
Step 5: Reinstall GRUB from LiveCD
After successfully booting (but with GRUB still broken in the current session), reboot using the LiveCD. Then:
- Open a terminal.
- Identify how your root partition is named on the LiveCD (usually
/dev/sda1,/dev/nvme0n1p1, etc.). Uselsblkorsudo fdisk -l. - Mount it to
/mnt:
sudo mount /dev/sda1 /mnt
⚠️ If you have a separate
/bootpartition, mount it too:sudo mount /dev/sda2 /mnt/boot(replacesda2with your/bootpartition).
- For Debian/Ubuntu:
sudo grub-install --boot-directory=/mnt/boot /dev/sda
sudo update-grub
- For CentOS/RHEL/Fedora:
sudo grub2-install --boot-directory=/mnt/boot /dev/sda
sudo grub2-mkconfig -o /mnt/boot/grub2/grub.cfg
- Unmount and reboot:
sudo umount /mnt
sudo reboot
Remove the LiveCD during reboot. GRUB should now work as before.
Verifying the Result
After rebooting, you should see the regular GRUB menu with the OS selection. If the menu appears and the system boots — the problem is solved.
If the error persists, check:
- Did you specify the correct root partition during reinstall (
/dev/sdais the disk, not a partition!). - Did the disk partition layout change after the error appeared? Partition letters may have shifted (e.g.,
sda1becamesda2). Verify withlsblkon the LiveCD.
Possible Issues
| Problem | Solution |
|---|---|
error: unknown filesystem when running ls (hd0,msdos1)/ | The partition does not contain Linux or the filesystem is unsupported by GRUB (e.g., Btrfs without module). Try other partitions. |
linux or initrd not found | Check the exact filenames in your partition's /boot. Different names may be used (e.g., vmlinuz-linux instead of vmlinuz-<version>). |
grub-install fails with No such device | Ensure you specified the correct disk (/dev/sda, not /dev/sda1). Also verify that the /boot partition is mounted (if separate). |
| After recovery, GRUB does not detect Windows | Run sudo update-grub (Ubuntu/Debian) or sudo grub2-mkconfig -o /boot/grub2/grub.cfg (CentOS/RHEL) in the now-booted system. This will add Windows to the menu. |
System boots but immediately crashes with kernel panic | The root= parameter in the linux command may be incorrect. Check which partition is mounted as / in your system (df -h on LiveCD). |
If no partition contains the expected files (boot, vmlinuz*), the Linux partition may have been deleted or corrupted. In this case, data recovery or a system reinstall will be required.