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

Note: DO NOT execute grub-install/grub2-install on the boot disk on uefi systems.

CentOS Linux 7, 8, 9

The following commands will reinstall all of the files in /boot/efi/EFI/ that are required for uefi booting.

# yum reinstall grub2-efi-x64 shim-x64
# rpm -ivh --replacepkgs --replacefiles grub2-efi-x64-<version>.rpm shim-x64-<version>.rpm

A new boot entry may need to be added when all of the aforementioned packages have been successfully installed. For example, if the motherboard was replaced, replace the disk part shown in the below command with the disk that /boot/efi is on.

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

If the issue persists then check if the new boot entry was added properly, by running the below command.

# efibootmgr -v

The /boot/efi directory being erased, or corruption are all common reasons for needing to reinstall GRUB for uefi installs.

CentOS Linux 6

Run the below commands to reinstall the grub package, this will reinstall the /boot/efi/EFI/centos/grub.efi file in case it was corrupted or removed.

# yum reinstall grub
# rpm -ivh --replacepkgs --replacefiles grub-<version>.rpm

After the grub package has been successfully reinstalled, you may need to add a new uefi boot entry, for example if the motherboard was replaced. Replace the disk part shown in the below command with the disk that /boot/efi is on example sda.

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

Leave a Reply