43

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.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
krishnakant
  • 598
  • 2
  • 6
  • 15

5 Answers5

35

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"

jdwolf
  • 4,887
  • 1
  • 13
  • 28
  • 3
    Thanks, In the `grub-install --efi-directory=/boot/EFI` as i chroot into `/mnt`. – krishnakant Nov 26 '17 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? – Mr. Developerdude Aug 29 '19 at 00: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 08 '19 at 20:43
  • Your instructions if EFI is not mounted are wrong. See my edit. `mount | grep /dev/sda6` doesn't work. If EFI is not mounted, you have to check the partitions for type. – giusti Oct 02 '19 at 17:06
  • 1
    @giusti Probably better to just not make specific device name references. – jdwolf Oct 19 '19 at 18:10
  • 1
    @jdwolf when I typed"_mount | grep /dev/[efi device]_" I got "_grep: Unmatched [, [^, [:, [., or [=_"..... maybe a misspelling? – Another.Chemist Aug 11 '20 at 21:20
  • grub-install: error: install device isn't specified. – jjxtra Jul 17 '21 at 16:10
  • @jdwolf, what if I don't have EFI partition at all? Because I have deleted it... – James Bond Dec 07 '21 at 16:45
  • Mounting `/mnt/boot/efi` and chrooting doesn't work. grub then complains about missing `/dev` in the chroot. OK, so `mount --bind /dev/ /mnt/dev` but then grub complains about other things. What did work was this: `grub-install -d /mnt/usr/lib/grub/x_86_64-efi --boot-directory=/mnt/boot /dev/sda` – Linas Dec 21 '22 at 20:48
9

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.

sbasurto
  • 91
  • 1
  • 1
  • 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 01 '22 at 06:00
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.

defalt
  • 449
  • 3
  • 8
  • 16
5

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!

Linas
  • 173
  • 1
  • 5
  • 1
    This saved my day – DaniyalAhmadSE Feb 24 '23 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 ` – FlavioEscobar Apr 29 '23 at 20:45
-4
sudo apt-get --purge autoremove  grub-efi-amd64-signed
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
  • 2
    Welcome to the site, and thank you for your contribution. Would you mind adding some explanation on why/how this would solve the OPs problem? – AdminBee Jun 10 '21 at 07:41
  • Welcome to Unix & Linux! [Brevity is acceptable, but fuller explanations are better](https://unix.stackexchange.com/help/how-to-answer). – Kusalananda Jun 10 '21 at 08:20