How to reinstall GRUB and GRUB2 on UEFI-based machines?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 10
  • Red Hat Enterprise Linux 9
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 6

Issue

  • The host does not boot into the GRUB menu.
  • The motherboard was replaced and is now not booting to GRUB.
  • /boot/efi/EFI/redhat/grub.cfg was deleted or corrupted

Resolution

Red Hat Enterprise Linux 7 and above

  • Run the below commands to reinstall the various packages need for booting uefi, this will reinstall all of the files under /boot/efi/EFI/.

    # yum reinstall grub2-efi-x64 shim-x64
    or
    # rpm -ivh --replacepkgs --replacefiles grub2-efi-x64-<version>.rpm shim-x64-<version>.rpm
    
Additional step for RHEL 9 and later

To recover a deleted /boot/efi/EFI/redhat/grub.cfg, it's required to reinstall grub2-common which triggers a scriptlet that generates /boot/efi/EFI/redhat/grub.cfg.

# yum reinstall grub2-common
  • After the packages above have been successfully reinstalled, it may be necessary to add a new uefi boot entry for example, if the motherboard was replaced then replace the disk part shown in the below command with the disk that /boot/efi is located.
    Warning: If the system is currently booted from a different system than what the OS disks normally use (for example, if the disks have been attached to a rescue virtual machine), do not run the efibootmgr command. This command updates the NVRAM on the motherboard; running it from a different system will update the NVRAM of the currently booted environment, which can leave that system in a broken state. For any questions or concerns, please open a new or update an existing Red Hat Support Case.

    # efibootmgr -c -d /dev/<disk> -p 1  -l \\EFI\\redhat\\shimx64.efi -L "Red Hat Enterprise Linux <insert  7 or 8 or 9 or 10 here depending on system version>"
    

If issue still remains

  • Check if the new boot entry is added properly, by running the below command.

    # efibootmgr -v
    
  • If the entry is added correctly, please create a case with support and include the output of the above command.

Red Hat Enterprise Linux 6

  • Run the below commands to reinstall the grub package, this will reinstall the /boot/efi/EFI/redhat/grub.efi file in case it is corrupt or removed.

    # yum reinstall grub
    or
    # rpm -ivh --replacepkgs --replacefiles grub-<version>.rpm
    
  • After the grub package has been successfully reinstalled, it may be necessary to add a new UEFI boot entry, for example, if the motherboard was replaced. Replace the disk portion shown in the command below with the disk where /boot/efi is located (e.g., sda).
    Warning: If the system is currently booted from a different system than what the OS disks normally use (for example, if the disks have been attached to a rescue virtual machine), do not run the efibootmgr command. This command updates the NVRAM on the motherboard; running it from a different system will update the NVRAM of the currently booted environment, which can leave that system in a broken state. For any questions or concerns, please open a new or update an existing Red Hat Support Case.

    # efibootmgr -c -d /dev/<disk> -p 1  -l \\EFI\\redhat\\grub.efi -L "Red Hat Enterprise Linux 6"
    

Root Cause

  • Common reasons for needing to reinstall GRUB for uefi installs:
    • motherboard replacement
    • The /boot/efi directory being wiped or corrupted
    • The wrong uuid is included in /boot/efi/EFI/redhat/grub.cfg
SBR
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.