So here’s the situation: I’ve recently had to remove the CMOS battery on my system. This resulted in my PC getting past POST again but it also removed all UEFI entries.

The official fedora documentation tells you to just to dnf reinstall grub2-efi shim. If that works for you, great! No need to read on.

If for some reason it didn’t, here’s what I did to fix it:

Solution

Grab an USB-Stick loaded with a Live-Distribution and boot from it. I used a Fedora Workstation 29 image.

Make sure you boot your live-image in UEFI-mode!

You can check whether your running in UEFI-mode by entering the following in a shell:

$ efibootmgr
If the output is: UEFI variables are not supported on this machine. you are not running in UEFI mode.

The next step is finding out the hard-drive where your linux is located and mounting it in a folder on the live system.

Use fdisk to locate the correct drive.

$ fdisk -l /dev/sd*
...
Disk /dev/sdb: 232,9 GiB, 250059350016 bytes, 488397168 sectors 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes           
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: F3095B76-A14B-4988-B252-C2A896FE2A33           

Device       Start       End   Sectors   Size Type
/dev/sdb1     2048    411647    409600   200M EFI System        
/dev/sdb2   411648   2508799   2097152     1G Linux filesystem  
/dev/sdb3  2508800 488396799 485888000 231,7G Linux filesystem  
...

Now we’re going to mount our broken system in /mnt on the live-system:

# X is the drive name and Y the partition
$ cryptsetup luksOpen /dev/sdXY cryptroot # only needed if you are using full disk ecryption!
$ mount /dev/mapper/fedora-root /mnt/ # your device name for the root mountpoint might be different
$ mount /dev/sdXY /mnt/boot/
$ mount -t proc proc /mnt/proc
$ mount -t sysfs sys /mnt/sys
$ mount -o bind /dev /mnt/dev
$ mount -t devpts pts /mnt/dev/pts
$ mount -o bind /etc/resolv.conf /mnt/etc/resolv.conf
$ mkdir /mnt/run/lvm
$ mount -o bind /run/lvm /mnt/run/lvm

Now we can chroot into our broken system and mount our EFI partition and the efivarfs:

$ chroot /mnt/
$ mount /dev/sdXY /boot/efi/
$ mount -t efivarfs efivarfs /sys/firmware/efi/efivars/

As the last step we’re going to generate a new EFI bootentry and regenerate the grub2 config:

$ efibootmgr -c --disk /dev/sdX -p Y -w -L fedora -l "\\EFI\\fedora\\grubx64.efi"
# Verify that your entry was created with:
$ efibootmgr -v 
$ grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg