top of page
Search

Rescue Grub & Reinstalling Grub

Updated: Apr 20

It's happened to the best of us. You reboot your computer after a fresh Linux installation and all you've got is the grub rescue> prompt. You may have accidentally deleted the wrong partition or maybe an update/upgrade changed the boot order but you just aren't sure what went wrong.






In this article, I'll be giving you some instructions, tips and how to's when your bootloader: Grub gets hosed.


Step one is try not to panic. Easier said than done, I know. However; staying in panic or worry mode really won't help. The key is to focus on fixing it.


Ramces Red wrote this article and I'm so glad I found it! Kudos to him and a very special thanks!


At the time of need when faced with the grub rescue> prompt last weekend I had a .iso image of Debian 12 so I used that to rescue my system.


I simply plugged in the USB thumb drive with Debian 12 Live and rebooted. Upon reboot the Live session of Debian was up and running. Once to the desktop I started to run these commands using the terminal.


The commands used in Mr. Red's article are Ubuntu based so I had to change them a bit.

By change them, I mean that Debian commands are similar but written out differently.


Debian doesn't recognize:

sudo fdisk -l | grep "Linux filesystem$"

Debian uses: sudo fdisk -l


That's a small letter L at the end of fdisk.


Then run this command. Just be certain to type the command for the correct root partition. The partition /dev/sda1is the root partition normally on the very first drive in Linux. It's also the first distribution installation listed at the very top of the bootloader.


sudo mount /dev/sda1 /mnt



This command is used for Ubuntu:


sudo grub-install --force --boot-directory=/mnt/ /dev/sda1



Debian uses:


sudo apt install --reinstall grub /dev/sda1


See the *closer to the bottom of this article for the Debian WiKi on Grub EFI Reinstall. It's clear to use:


grub-install /dev/sdx


The x in /dev/sdx indicates the drive so be certain to type the desired drive on your machine.


To be sure that grub was installed you can download the boot info. script on Source Forge. The text.txt file that confirms that grub exists on each drive will be sent to the same directory that you downloaded the script to.

On this page click on the blue letters that says 'latest version'.


If you are already running Debian it's best to use the boot-info-script that's in the repository.

https://packages.debian.org/bullseye/boot-info-script


Normally this would have worked however; it did not for me as something was wrong that I discovered later. I'll explain why, what happened and what else can be done.


Somehow the boot order in the BIOS was switched around from the original order. And the partitions on a third drive ( /dev/sdc ) were labeled as /dev/sda. Baffling, I know.


Entering into the BIOS and navigating to the boot section I discovered that the original order that I set it to was a jumbled mess!


My Western Digital drive ( /dev/sdc ) was first in the boot order. The first drive my San Disk ( /dev/sda ) should have been at the top of the boot priority list. The Hitachi drive ( /dev/sdb ) wasn't in the proper place either. Once I put all of drives in their proper order, saved the changes in the BIOS and rebooted I had the Grub Menu again.


Depending on the grub prompt, the Grub configuration files are either missing or Grub just needs to be re-installed. The initramfs-linux.img and the vmlinuz-linux images are the most important in the /boot directory. So cd into the boot directory.


When you are at the grub rescue prompt type: cd /boot and press enter. Then type 'ls' without the quote marks and press enter to see the listing.


  1. At the grub rescue prompt type: The forward slash at the end of msdos1shows all of the folders in the root directory.

  2. grub> ls (hd0,msdos1)/


3. To set that drive as root type:

set root=(hd0,msdos1)



4. Then type at the grub rescue prompt:

init


Next type:

linux/boot/vmlinuz-linux root=/dev/sda1


5. Here you have to know the devices and the partitions on your system well. You want the regular Linux image not the fallback one!

initrd/boot/initramfs-linux.img



6. Then the last command to type is:

boot


Your system should boot and be on your way to the Linux desktop.


IF Grub is completely gone, meaning the config's are missing, run these commands in order.


*** Arch Linux and Slackware use grub-mkconfig ***

*** Debian uses update grub ***


1. #[root@Debian~] grub-mkconfig -o /boot/grub/grub.cfg


2. #[root@Debian~] grub install /dev/sda   


*(Don't put a number after the 'a' in sda as you are installing Grub to the device not the partition)*


3.#[root@Debian~] reboot


This output is when Grub is missing all of the important files. At this stage there isn't much you can do but to insert the Live Linux media and reboot.


error:file '/boot/grub/i386-pc/normal.mod' not found. Entering rescue mode...grub rescue>


Root at distrolive is just an example of a Live session here.


Step 1. root@distrolive~#mount /dev/sda1 /mnt


Step 2. This can be debian-chroot or mint-chroot, whatever live Linux your using is what you would type.


arch-chroot /mnt


Step 3.


root@distrolive~# mkdir /boot/grub


Step 4. * On Debian it's update-grub


root@distrolive~# grub-mkconfig -o /boot/grub/grub.cfg


Step 5.


root!distrolive~# cd /boot/grub


Step 6. This command should list grub.cfg at the command-line prompt.


root@distrolive~#ls


Step 7. Install Grub to the desired drive.


root@distrolive~# grub-install /dev/sda


Step 8.


root@distrolive~# ls


Upon pressing enter after typing ls, all of those files will come back. Such as fonts, grub.cfg, i386-pc, locale and themes.


Step 9.


root@distrolive~# exit


Step 10.


root@distrolive~# reboot


Chris Titus Tech has a helpful Youtube video titled: "GRUB Rescue | Repairing Grub". I recommend watching his video as he covers this very well.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------AAdditional Information


Most modern desktops and laptops today are equipped with UEFI BIOS. That's Unified Extensible Firmware Interface.

Older desktop's and laptop's use BIOS with boot code that is inside the MGR before the first partition.


As an example I purchased a Sony Vaio laptop approximately 12 years ago. That machine came with and uses the Legacy BIOS.


With UEFI, Grub takes the form of a grubx64.efi file within the esp partition.

When creating a efi partition the esp flag needs to added to the partition.


Grub architecture identifiers are for BIOS i386-pc. Identifiers for UEFI 64-bit x86 hardware are x86_64-efi.


On a machine with only one drive and one operating system Grub is installed to the device not a partition.


When you have a triple booted desktop as I do with 3 different drives and 3 Linux installations then you would install Grub to the /boot partition specifically to the distribution that is in need of it.


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Grub : Grub Rescue & GRUB


When the prompt "grub >" shows on a black screen this is where Grub 2 has found the boot information but has been unable to locate or unable to use an existing Grub configuration file, namely grub.cfg.

The rescue mode. This is when the words "grub rescue>" appear on your screen.

This happens when Grub 2 is unable to find the Grub folder and the contents are either missing or have been corrupted. The Grub 2 folder holds the Grub menu, modules and stored environmental data.


GRUB This is where the word "GRUB" appears at the top left of your screen with no prompt and no cursor. At this point this is where Grub has failed to find the basic information. That information is in the MBR or the boot sector.


*The Debian WiKi for Grub EFI ReInstall is the best way to go. Any time your in doubt you can't go wrong with the authoritative documentation of the distribution you are running.


https://wiki.debian.org/GrubEFIReinstall



IF you do anything today do yourself a favor and download a Linux .iso. Have it already to go and bootable and keep it handy for if and when this happens.


Enjoy your Linux, drive it safe and have a Merry Christmas and a Happy New Year!


Alex

105 views0 comments

Recent Posts

See All
Post: Blog2_Post
bottom of page