Home Linux How to repair boot failure in GRUB 2 rescue mode – CentOS 7

How to repair boot failure in GRUB 2 rescue mode – CentOS 7

by SupportPRO Admin

GRUB denotes GRand Unified Bootloader. GRUB is a multiboot boot loader software program that first runs when a computer/server starts. Its role is to carry forward from BIOS during the boot, load itself, load the kernel into memory, and then switch over execution to the kernel. Once the kernel picks over, GRUB has fulfilled its task and it is no longer needed. GRUB 2 is a descendant of GRUB. The GRUB 2 configuration file “grub.cfg” is normally located under the directory /boot/grub2.

Here we are discussing the boot issue and how we can repair Linux boot failure in GRUB 2 rescue mode.

We may see one of the “grub>” modes on the screen when a boot fails. It provides the first sign of what might be causing the trouble to boot. The system failed to boot and ended up with this screen.

This prompt occurs when GRUB has found everything except the configuration file “grub.conf” during the booting process. That is GRUB 2 had loaded modules but was unable to get the “grub.cfg” file.

These are a few basic commands that you can use when you enter the GRUB 2 terminal mode.

  1. ls (Lists the contents of a partition/folder; ls, ls /boot/grub)
  2. cat (view the contents of config or txt files; cat (hd1,1)/boot/grub/grub.cfg, cat (md/md2)/boot/grub2/grub.cfg)
  3. set (Review current settings, or set a variable such as prefix, root.)
  4. insmod (Loads a module; insmod normal)
  5. normal (Activate the normal module, if loaded)

If the GRUB fails to load the “normal” module, you will get a rescue shell. If the cause for the failure is that the “prefix” is incorrect, it refers to an incorrect device or the location of “/boot/grub” was incorrect with respect to the device. Then you need to manually fix the same and get into the normal mode.

You can inspect the current prefix and other preset variables by executing the command: set

You will probably have an output similar to this:

Your output may vary but you will get the information needed. Then, you can determine which devices are available by executing the command: ls

In some cases, there are chances to have a software raid on the server. In that case, when executing the “ls” command, you will probably be seeing device names like md2 or md3, etc. You can view the contents of config or txt files using the “cat” command. Once you identified the device, verify or view the path of the contents of the grub config file as below.

cat (md/md2)/boot/grub2/grub.cfg

The”set” command will list values of variables necessary for a successful boot. Do take a note of values for root and prefix and assign them to GRUB manually. Here I’m showing an example for a server having a software raid.

Set the root value you got from the listing:

grub> set root=(md/md2)

(this has to be prepared according to your drive name)

Set the prefix value you got from the listing:

grub> set prefix=(md/md2)/boot/grub2

(this has to be prepared according to your drive name)

Then run the following commands to get out of the rescue mode to the normal terminal mode.

grub> insmod normal

grub> normal

The system will boot without any issue now to normal mode. Once the server is booted to a normal mode, you need to restore Grub in UEFI boot. For UEFI boot only, execute the below commands:

# efibootmgr -v

Then run: grub-install

# grub-install /dev/sda

 

We hope this works for you! Thank you!

 

 

Leave a Comment