Does this answer work for UEFI computers?

One of my most popular answers is instructions on how to repair grub. Over time, others have contributed bug fixes to the answer. A recent comment, though, made me wonder if it works on newer UEFI hardware.

Gabor wrote:

I get a "cannot find EFI directory" at step 7 and cannot boot. Any ideas?

All my hardware is older, pre-UEFI hardware. So my question is this: Are my instructions, particularly step 7, applicable to UEFI hardware? If not, what changes need to be made?


Solution 1:

If you have EFI, then there will be an EFI System Partition (ESP) on the disk. This partition has to be mounted on /boot/efi, so that GRUB can use it. The partition:

  • is formatted FAT32,
  • is usually small (100MB < size < 500MB)
  • will have the boot flag enabled
  • contains an EFI folder
  • could be labelled EFI by the OEM, but no guarantees

I don't have one on hand, but you can see examples of how such a partition will look:

  • Super User post about creating one, with parted -l output:

    enter image description here

  • Unix & Linux post, also about creating one, with a GParted screenshot:

    enter image description here

So, the task here is, somewhere around steps 3 & 4:

  1. Find the ESP
  2. Mount it:

    sudo mount /dev/sdXY /mnt/boot/efi
    

Then you can proceed with your usual answer. I have done it myself. Consider it similar to mounting a /boot partition if you have one separate.

You can mount it anywhere you like. In that case, just specify the mount directory to GRUB while installing:

grub-install --efi-directory=/foo/bar /dev/sdX

Solution 2:

In your original answer, you wrote:

When you install Windows, Windows assumes it is the only operating system (OS) on the machine, or at least it does not account for Linux. So it replaces GRUB with its own boot loader.

This isn't true under EFI. Well, Windows is still pretty rude, and could be said to assume it's the only OS, but it does not replace GRUB. Under EFI, multiple boot loader coexist on the EFI System Partition (ESP), and Windows does not delete or replace GRUB.

That said, the average user might not notice any difference in symptoms between a BIOS-mode and an EFI-mode installation of Windows after Ubuntu, because what Windows does in EFI mode is to set its own boot loader as the default. Thus, the computer ends up booting Windows instead of Ubuntu. This looks like the same problem as under BIOS, but it's not.

Something similar to your solution may work under EFI, but it's overkill, and therefore has the potential to create more problems than it solves. In outline, the simplest way to get GRUB back after installing Windows under EFI is:

  1. Boot to Windows.
  2. Download and install EasyUEFI.
  3. Using EasyUEFI, move the ubuntu entry to the top of the boot order list.
  4. Reboot. Ubuntu should boot, but there will be no Windows option.
  5. In Ubuntu, type sudo update-grub in a Terminal window.

At this point, Windows should show up as an option in the GRUB menu on the next reboot.

An alternative would use the built-in Windows program bcdedit instead of EasyUEFI, but EasyUEFI is, well, easier, despite being a third-party program that must be downloaded and installed.