This article will provide the step by step procedure to recover the GRUB on REHL 7 / CentOS 7. GRUB corruption / lost is one of the most common issues on Linux servers/workstations. The possible reasons for grub corruption could be due to bad disk/bug on the firmware or powered off the system abruptly. Systems ships with BIOS/ UEFI firmware and you should know what OS is using currently. Here is the way to identify BIOS vs UEFI on Linux servers. To recover GRUB on RHEL7 /CentOS 7, you must have the latest DVD or ISO image.
Common Errors in GRUB:
If GRUB is corrupted or lost, the system will not boot and it will be stuck in grub like below.
GNU GRUB version 0.97 (638K lower / 3143616K uper memory) [ Minimal BASH-like line editing is supported. For the first word. TAB lists possible command completions. Anywhere else TAB lists the possible completions of a device/filename.] grub>
The system gets stop with the following message.
GRUB loading stage 2
In such cases, Please follow the below instructions.
Recover/Restore the GRUB – BIOS Based system:
1. Insert RHEL 7 / CentOS 7 latest DVD on the server or attach ISO image using ILO.
2. In case of a Virtual machine, attach the ISO image to the VM.
3. Boot the server using the DVD/ISO image.
4. Choose troubleshooting option once the system is booted in DVD/ISO.
5. Choose the rescue mode.
6. Press 1 to continue to find the OS image and get the shell prompt.
7.chroot to the OS image.
8. Starting RHEL 7/CentOS 7, GRUB 2 is the default bootloader. The GRUB 2 configuration file is /boot/grub2/grub.cfg. Install grub boot loader on root disk. (Default : /dev/sda).
9. Navigate to /boot/grub2 directory and confirm the existence of “grub.cfg” . Here “grub.cfg” file is not exists.
10. Let’s generate “grub.cfg” file.
If you are missing grub2-mkconfig command, install “grub2-tools.x86_64” package in rescue mode . Since you have booted from DVD, the package should be available in that.
Grub.cfg recreated using grub2-mkconfig
11. Exit from the chroot and reboot the system.
This will work only on BIOS-based X86 servers and virtual machines but will not work with UEFI firmware servers and VMs.
Here is the link to identify that what firmware type was used to boot the system.
Andrzej says
Thank you. It just worked based on this precised description.
It saved me a lot of time and trouble. In my case the grub.cfg got broken during the update. Installation of the firmware package caused together with grub2 update truncated the grub.cfg to the size of 0.
mallek says
thanks it was very helpfull my virtual box died by mistake and i am able to rapire it
best regards
Mallek
Sourav says
Even if you go to rescue despite all well in your system, you wont find grub.cfg in /boot/grub2. Infact grub2 itself wont be visible and will not be shown as present. So there is no need to recreate grub.cfg using grub2-mkconfig
Adnan says
Hi I tried the tutorial listed (all the steps you listed ) but when I reboot I get the same results , any help please !
Gary says
You saved my butt…thank you. I had a weird scenario where I had to restore a CentOS server to a smaller drive. I appreciate this.
Vasya says
Thanks, you really help me! You save me 100+ hours work time.