Unix & Linux
linux boot grub2 uefi
Updated Fri, 20 May 2022 06:27:36 GMT

How to recreate EFI boot partition?

I've installed Fedora on my machine with / partition, swap partition and ESP partition for EFI booting.

Now, I was installing Elementary OS instead of Fedora.

  1. I have formatted the / partition (/dev/sda3)
  2. Formatted the swap partition (/dev/sda4)
  3. But did not format the EFI boot partition (/dev/sda1)

Now when i boot, i get my old grub menu that's was installed by Fedora. I can only boot into Elementary OS by:

  1. Entering the boot menu.
  2. Selecting boot from EFI file
  3. Navigate through /dev/sda1/, to get the elementary directory that contains grubx64.efi file. Which is /boot/efi/EFI/elementary/grubx64.efi.

How can i fix that ? I thought of formatting the boot partition /dev/sda1/ with fat16 or something then re-installing grub on it.

My /dev/sda1 now contains this :

root@rafael:/home/rafael# ls /boot/efi/
EFI  mach_kernel  System
root@rafael:/home/rafael# ls /boot/efi/EFI/
BOOT/       elementary/ fedora/     
root@rafael:/home/rafael# ls /boot/efi/EFI/fedora/
BOOT.CSV  fonts  gcdx64.efi  grub.cfg  grubx64.efi  MokManager.efi  shim.efi  shim-fedora.efi
root@rafael:/home/rafael# ls /boot/efi/EFI/elementary/

Here's my efibootmgr output :

BootCurrent: 003D
Timeout: 0 seconds
BootOrder: 2001,2002,2003
Boot0000* Notebook Hard Drive
Boot0010* Internal CD/DVD ROM Drive
Boot0011* Internal CD/DVD ROM Drive (UEFI)
Boot0012* Fedora
Boot0013* Fedora
Boot0014* Fedora
Boot0015* Fedora
Boot0016* Fedora
Boot0017* Fedora
Boot0018* Fedora
Boot0019* Fedora
Boot001A* Fedora
Boot001B* Fedora
Boot001C* Fedora
Boot001D* Fedora
Boot001E* Fedora
Boot001F* elementary
Boot2001* USB Drive (UEFI)
Boot2002* Internal CD/DVD ROM Drive (UEFI)

Any help would be appreciated.


I did it !

First of all, I removed all the unnecessary boot entries by:

efibootmgr -b <entry_hex_number> -B

Then, Reformatting the ESP partition with FAT32 filesystem.

mkfs.vfat -F32 /dev/sda1

Then installed grub to /dev/sda NOT /dev/sda1

grub-install /dev/sda

Comments (2)

  • +3 – You don't need grub-install which writes MBR. I don't know if you distro's grub does the two things together, but what you need is to copy grubx64.efi (or shim.efi) to /boot/efi/EFI/$distro/ and efibootmgr -c -l /boot/efi/EFI/$distro/grubx64.efi. — Jul 21, 2013 at 08:37  
  • +1 – grub-install has learned to grok EFI (you can force it to with --target=x86_64-efi but efivars.ko must be loaded by that time anyways). — Sep 04, 2013 at 10:50