Restore a UEFI entry (Grub)

on 2015-11-16 automatically translated

Windows 7/8/10 updates and replacing the BIOS battery sometimes unexpectedly delete my Linux (dual-boot) UEFI entry from the BIOS. Until now, I had always repaired this using a rescue Linux system on a USB stick, but there is a more elegant method that I do not want to forget, so I am documenting it here.

You need to know that having .EFI files on the EFI partition is not enough to boot them. The UEFI firmware has its own list, which must contain the bootable operating systems. (I mean the list shown when pressing the <Boot Menu> key (F11 in my case) during boot.)

Step 1: Start Linux (Fedora in my case) through the UEFI shell

  • F11
  • Select UEFI Shell
  • Select the EFI partition: Display all partitions with mm or map. On my system, the partitions are called fs0 through fs4 or blk0 through blk4. Switch to a partition with:
    Shell> fs0:
  • (In the English keyboard layout, the colon is on SHIFT-Ö.)
  • Test whether it was the correct partition, because the EFI partition contains a directory called EFI:
    Shell> cd EFI
  • If this fails, use another partition, for example with Shell> fs1:, then try Shell> cd EFI again.
  • Find the correct .EFI file.
  • fs0> cd <press the Tab key repeatedly until FEDORA or UBUNTU or the name of your Linux distribution appears>
  • fs0> <press the Tab key repeatedly and make a note of all *.EFI files>
  • (Tab completion works here even when you have not entered any letters yet.)
  • Try the EFI files one by one; in my case, both GRUBX64.EFI and SHIM.EFI work.
  • fs0> GRUBX64.EFI
  • Make a note of the directory and file used!

Now add a boot entry to UEFI (from the console of the started Linux system).

  • You may need to install efibootmgr:
    sudo apt-get install efibootmgr…
    sudo dnf install efibootmgr…
  • View boot entries and boot order:
    $ sudo efibootmgr
    BootCurrent: 0003
    Timeout: 1 seconds
    BootOrder: 0001,0002,0003
    Boot0001* WINDOWS BOOT MANAGER
    Boot0002* Hard Drive
    Boot0003* UEFI: Built-in EFI Shell
  • Find the EFI partition's device and partition number:
    $ mount | grep efi
    efivarfs                 on  /sys/firmware/efi/efivars        type  efivarfs         (rw,......)
    /dev/sdb1                on  /boot/efi                        type  vfat             (rw,......)
  • The drive is /dev/sdb here (without the number), and the partition is 1 (the number).
  • Restore the Linux entry:
    sudo efibootmgr -c -L "My Linux" -l /EFI/FEDORA/GRUBX64.EFI -d <drive> -p <partition number>

Adjust the boot order

  • sudo efibootmgr
  • The line “BootOrder: 0004, 0001, …” shows the current boot order; the first number is started first. The numbers refer to the BootXXXX lines.
  • Decide on a new order and activate it:
  • sudo efibootmgr -o 1,0,2,3

At least, this works with my ASRock motherboard.