44

I was trying to rescue GRUB in Linux. I was able to login in the OS following this tutorial:

https://www.lisenet.com/2014/grub2-rescue-mode-error-unknown-filesystem/

I have to upgrade GRUB to fix the problem. However, when I run grub-install, I get an error:

$ grub-install /dev/sda
grub-install: error: cannot find EFI directory.

My file system contains sda4, sda5, and sda6 for the EFI system, Linux swap, and Linux file system respectively.

I am not very experienced using mount or other commands.

0

5 Answers 5

38

When you run grub-install by default it assumes the EFI system is mounted as /boot/efi

It depends on your distribution where EFI system is mounted and on some distributions it isn't mounted after boot.

First check if /boot/efi is mounted with

mount | grep /boot/efi

If that doesn't work first try the following to see if it is mounted elsewhere.

mount | grep /dev/[efi device]

If neither of those work do:

mount /dev/[efi device] /mnt

Now run:

grub-install --efi-directory=[efi dir]
grub-mkconfig -o /boot/grub/grub.cfg

where [efi dir] is either /boot/efi or /mnt and [efi device] is the device with the EFI system partition. If you don't know use the command lsblk -o NAME,PARTTYPE,MOUNTPOINT | grep -i "C12A7328-F81F-11D2-BA4B-00A0C93EC93B"

10
  • 3
    Thanks, In the grub-install --efi-directory=/boot/EFI as i chroot into /mnt. Nov 26, 2017 at 19:20
  • 1
    Maybe stupid Q but I don't have an EFI dir. Where do I get one? I mean it is supposed to contain files, which command can recreate it? Aug 29, 2019 at 0:18
  • @LennartRolland If you have a UEFI compatible system then your system drive will be GPT partitioned and contains a "UEFI System partition." usually the first partition and will be of the type EF00. Many distributions will mount this by default as /boot/efi to among other things allow the GRUB boot loader to update its files. If not you'll have to mount it yourself and add it to fstab. You might also have a UEFI system but that is using legacy mode which means your partitions will be msdos type and you won't have a /boot/efi. Weirder configurations exist but that covers the majority of them.
    – jdwolf
    Sep 8, 2019 at 20:43
  • 1
    @giusti Probably better to just not make specific device name references.
    – jdwolf
    Oct 19, 2019 at 18:10
  • 1
    @jdwolf when I typed"mount | grep /dev/[efi device]" I got "grep: Unmatched [, [^, [:, [., or [="..... maybe a misspelling? Aug 11, 2020 at 21:20
11

The efi directory must be in /boot/efi/

To know in which partition the efi is, we must examine the partition table, so if your main disk is /dev/sda then.

fdisk -l /dev/sda
Device             Start        End   Sectors   Size Type
/dev/sda1           2048     309247    307200   150M EFI System
/dev/sda2         309248  964843519 964534272 459.9G Linux filesystem
/dev/sda3      964843520 1000214527  35371008  16.9G Linux filesystem

In the result search for something like EFI System or EFI (FAT-12/16/32)

Once you know the partition number then (in this case sda1), we must mount it in /boot/efi.

If for some reason the directory /boot/efi/ does not exist, create it:

mkdir /boot/efi

and mount the efi into that directory:

mount /dev/sda1 /boot/efi/

And I think that is all, you must be able to install grub in your disk.

2
  • Note that grub is case-sensitive while the EFI filesystem is case-preserving. If your boot directory is /boot/EFI, the UEFI firmware can find it, but grub can't.
    – Mark
    Jul 1, 2022 at 6:00
  • @Mark also worth noting that you'll end up with /boot/efi/EFI once everything is correctly set up
    – cod3monk3y
    Sep 8 at 2:27
7

I just now encountered this issue. I booted a rescue USB stick. Let me describe the fix that worked for me.

Prowling around with gdisk -l /dev/sda I can see that my original root partition is /dev/sda2. To access it, I type sudo mount /dev/sda2 /mnt

So far, so good. Let me first describe what didn't work, and then a solution. Some pages advise chroot /mnt and then grub-install, but this won't work; giving the grub-install: error: cannot find EFI directory. error.

Following other suggestions, I see that my EFI partition is /dev/sda1 so I try sudo mount /dev/sda1 /mnt/boot/efi and chroot again. Now, grub complains about missing /dev so I mount --bind /dev/ /mnt/dev. ... But then grub complains about something else. It's snowballing out of control. chroot is not the answer.

What did work was this: grub-install -d /mnt/usr/lib/grub/x86_64-efi --boot-directory=/mnt/boot /dev/sda

Note that the -d flag is mandatory, as otherwise, grub tries to use /usr/lib/grub/i386-pc from the rescue image, which does not contain the correct stuff.

Yayy! My system is now bootable again!

2
  • 2
    This saved my day Feb 24 at 20:20
  • Just wanted to mention that when you run fdisk -l you'll likely see a Linux File System partition and a separate EFI partition. What you should do then is: 1. Mount your Linux FS partition under /mnt 2. Mount your EFI partition under /mnt/boot/efi 3. Run what Linas suggested and remember to use your Linux FS partition in the final part of the command, ie: grub-install -d /mnt/usr/lib/grub/x86_64-efi --boot-directory=/mnt/boot <linux FS partition> Apr 29 at 20:45
5

Grub rescue mode can be treated as

set root=(hd0,gpt6)
set prefix=(hd0,gpt6)/boot/grub
insmod normal
normal

Once you login, enter sudo update-grub && sudo grub-install /dev/sda.

3
  • Should the grub-install not the done before the update-grub? Oct 18, 2018 at 22:13
  • when I typed the first command, I got "bash: syntax error near unexpected token `('" Aug 11, 2020 at 21:19
  • 1
    @Another.Chemist: the commands given should go to the GRUB interactive console, I think. That would be before the kernel boots. Your error looks like you have typed the commands into Bash.
    – Gogowitsch
    Dec 17, 2020 at 16:43
-4
sudo apt-get --purge autoremove  grub-efi-amd64-signed
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .