How would I reinstall the grub-efi bootloader on Fedora Linux?

I recently installed Fedora 18 using EFI boot. Like the other current linux distributions, it sets up GRUB2 for me.

I have experience with re-installing the BIOS version of GRUB when things go wrong. I know e.g. how to boot a rescue disc, chroot into the installed system, run grub-install and possibly update-grub / grubby / grub-mkconfig.

How would I reinstall the EFI version of GRUB when things go wrong? (I know things will go wrong: I break them).


Firstly, you will need an EFI-booted linux system. If you still have your original install media (CD/DVD/USB stick), that should usually include an adequate rescue system. It might even have a one-click repair option :).

Alternatively, the Ubuntu community provides an automatic boot-repair image. It claims to support Fedora. If you want to know what it actually does, I suggest you read this third-party explanation in advance.

However I used a general purpose rescue system with console tools. As well as supporting EFI boot, I made sure efibootmgr is in the list of packages. It happened to be called GRML and was based on Debian. Here's the information about console tools and grub-efi I discovered while rescuing my Fedora system:

  1. When running a Fedora 18 system booted by EFI, do not run grub2-install. It will claim success, but it breaks the Fedora grub-efi boot system.

    • The file /boot/EFI/fedora/grub.efi is installed by the grub-efi package. If you do want to reinstall it, use yum reinstall grub-efi. (To do this from a generic rescue system, you can do this after mounting and chrooting into your installed Fedora system). Fedora grub-efi uses the config file /boot/EFI/fedora/grub.cfg (presumably generated by grubby). Fedora on EFI won't generate a file at /boot/grub2/grub.cfg. Running grub2-install will replace grub.efi with an image that tries to read /boot/grub2/grub.cfg, and will therefore fail.

    • grub2-install installs an EFI boot entry for grub.efi. However if you have not disabled Secure Boot in your Windows 8-certified firmware, this entry will fail to boot. You need to boot shim.efi instead (ignore shim-fedora.efi, I'm not sure exactly what that is). See below.

  2. You can lose your EFI boot entry for Fedora if your firmware settings are reset. (Manually, or by firmware upgrade, or because firmware is buggy - the latter has been reported in the wild). Here's how to manually create an EFI boot entry for Fedora with secure boot:

    $ sudo efibootmgr -c -L Fedora -d /dev/sda -p 100 -l \\EFI\\fedora\\shim.efi
    

    This example uses partition number 100 on the first standard disk recognized by linux. You should adjust the options -d /dev/sda and -p 100 to identify the filesystem which Fedora mounts at /boot/efi. This is an EFI system partition. The Fedora installer will have created a dedicated ESP for your Fedora install to use, separate from the ESPs used by any other operating system. (This is different from Ubuntu and OpenSUSE).

    Note the efibootmgr command requires that you run it from an EFI-booted system.


If you are dual-booting with UEFI Windows, there's another possibility. which doesn't require a recovery disk.

You can boot into Windows, open a command line with admin privileges, and run the following command:

bcdedit /set {bootmgr} path \EFI\fedora\shim.efi

This will replace the Windows boot entry in UEFI, with one that boots into GRUB. Assuming your GRUB menu then includes a working entry for Windows, you now have working dual-boot :-). Hopefully this should all work without disabling Secure Boot.

I have just had to do so myself after a Windows update and it seems to have done the trick.

Source and more information: http://nwrickert2.wordpress.com/2013/05/13/notes-on-uefi-windows-and-linux/.


https://fedoraproject.org/wiki/GRUB_2?rd=Grub2#Updating_GRUB_2_configuration_on_UEFI_systems:

dnf reinstall grub2-efi grub2-efi-modules shim

(assuming you have those packages already installed and a previous configuration is existing)