Error While Installing GRUB2-EFI


I am having an UEFI appliance running FreeBSD 10.3. I wanted to install GRUB in it.
I compiled and made a package for grub2-efi from /usr/ports/sysutils/grub2-efi.

grub2-efi is installed using pkg install grub2-efi
But when I execute "grub-install", I am getting an error message "efibootmgr not found".

Command used : "grub-install --target=x86_64-efi --root-directory=/efi /dev/da0"

I could not find a package with name "efibootmgr" in /usr/ports

disk is partitioned as given below.
=>        6  146239733  da0  GPT  (558G)
          6         10       - free -  (40K)
         16        128    1  freebsd-boot  (512K)
        144     262144    2  efi  (1.0G)
     262288    1048576    3  freebsd-ufs  (4.0G)
    1310864    2097152    4  freebsd-swap  (8.0G)
    3408016    1048576    5  freebsd-ufs  (4.0G)
    4456592     102400    6  freebsd-ufs  (400M)
    4558992   13107200    7  freebsd-ufs  (50G)
   17666192     524288    8  freebsd-ufs  (2.0G)
   18190480  128049248    9  freebsd-ufs  (488G)
  146239728         11       - free -  (44K)

How can I successfully install grub2-efi in FreeBSD 10.3?

The reason you're getting the error is because the system isn't configured to UEFI boot. Judging by the freebsd-boot partition you're using the traditional BIOS boot.
Hi Dice,

The box is booting using UEFI. Itz just that, a partition with name "freebsd-boot" is present.
I even confirmed this by deleting "freebsd-boot" partition.

I've only just come across grub2-efi, was previously using the grub2 pkg, but wanted to use grub with gpt.

In the command in OP, it mentions '--root-directory=/efi'. Is this something that should already exist?
I note when running man grub-install that this option is not displayed.

Has anyone managed to get this working?
I assume that '--root-directory' should be '--efi-directory' and it should refer to the efi partition (/dev/da0p1)... and that needs to be mounted eg mount -t msdosfs /dev/da0p1 /mnt when running grub-install...

Am I correct in thinking the efi partition can be recreated using
dd if=/boot/boot1.efifat of=/dev/da0p1
as I think I may have messed it up...

I thought I had installed it but on reboot I didn't see any Grub menu, so will have to try again.
The dd trick is probably the simplest way to recreate the EFI partition. Here's a sample incantation for GRUB:

grub-install --boot-directory=/rpool/boot --bootloader-id=grub \
 --efi-directory=/mnt/efisys --no-nvram --target=x86_64-efi

Set --boot-directory to wherever you want the grub folder installed on your system (i.e., where you'll keep your grub.cfg). If you don't have any other EFI loaders installed, you can set --bootloader-id=boot to use the default path of /EFI/boot/. Lastly, the --no-nvram option should disable the call to efibootmgr.
Last edited by a moderator:
Thanks for the suggestion... I'm obviously doing something wrong because on reboot the system goes straight into the FreeBSD EFI boot block showing Loader path: /boot/loader.efi. I don't really know what to expect with the Grub EFI loader, but nothing appears, so it doesn't seem to have installed properly even though grub-install showed no errors found.

I did read elsewhere that a small bios-boot partition needed to be installed for grub-efi to work. I have installed one but it is the seventh partition, so I don't know if this is the problem. Also I'm not sure if I've specified '--efi-directory' correctly. I'm assuming that it should point at the the EFI partition on the disk, so if I mount /dev/da0p1 /mnt, should efi directory be /mnt or /mnt/efi?
In your case, you'll want to use --efi-directory=/mnt. And there's no need for a bios-boot partition when using UEFI.

As for the actual problem, if FreeBSD's loader is what you're getting at boot then, presumably, that's what lives on the EFI partition at EFI/boot/bootx64.efi. You can verify this by mounting the partition and comparing this file to /boot/boot1.efi. They should be identical. Unless one is more up-to-date than the other. If that's the case, just hexdump the file and search for "FreeBSD" to verify its contents.

Since you want GRUB to be the default bootloader, the .efi file generated by grub-install will have to be what resides at EFI/boot/bootx64.efi. If you used --bootloader-id=grub then this file will have been installed to EFI/grub/grubx64.efi.
Here is a directory listing of what I have on my EFI partition:-

drwxr-xr-x  1 root  wheel    512 Apr 12  2016 efi
drwxr-xr-x  1 root  wheel    512 Apr 12  2016 boot
drwxr-xr-x  1 root  wheel    512 Apr 26 08:25 efi
-rwxr-xr-x  1 root  wheel  131072 Apr 12  2016 bootx64.efi
-rwxr-xr-x  1 root  wheel      12 Apr 12  2016 startup.nsh
drwxr-xr-x  1 root  wheel  512 Apr 26 08:25 boot
-rwxr-xr-x  1 root  wheel  128512 Apr 26 08:25 grubx64.efi

Are you referring to EFI (above) as the EFI partition or a directory within the EFI partition?

From what I can make out I need to create a grub partition under /dev/da01p1 and copy grubx64.efi to it...

Does that sound OK?
Are you referring to EFI (above) as the EFI partition or a directory within the EFI partition?

Pardon the confusion. Whenever I used EFI in a path it was the name of a directory.

It appears you just nested the install path one level too deep. Try laying things out like this:

./efi/boot/bootx64.efi      # GRUB
./efi/boot/bootx64.efi.old  # FreeBSD's loader
Many thanks, I finally have it working. Don't why it took me so long to sort it, but without your help it would have taken much longer. Now I can finally get my Multiboot USB stick configured to my liking... Still don't know why the EFI partition takes up so much space...
Pardon the confusion. Whenever I used EFI in a path it was the name of a directory.

It appears you just nested the install path one level too deep. Try laying things out like this:

./efi/boot/bootx64.efi      # GRUB
./efi/boot/bootx64.efi.old  # FreeBSD's loader

I thought I had this working, but when trying install grub-efi again on another system, I get:

./efi/boot/bootx64.efi      # 131072   Apr 12 2016
./efi/grub/grubx64.efi      # 120512   Jan  4 2017
and the system boots up, just as before.

Can I just cp ./efi/grub/grubx64.efi ./efi/boot/bootx64.efi?

This is what I ran to install grub:

mount -t msdosfs /dev/da0p1 /mnt
grub-install --boot-directory=/boot --bootloader-id=grub  --efi-directory=/mnt --no-nvram --target=x86_64-efi /dev/da0
Can I just cp ./efi/grub/grubx64.efi ./efi/boot/bootx64.efi?


You can change the name that is used for the subdirectory that grub-install creates in your efi partition using the --bootloader-id option, but I don't recall if there's a way to make it output a file named anything other than grubx64.efi (though I'd be surprised if there wasn't).

And you don't need to pass a device path when using the EFI-variant of grub-install. It is sufficient to specify where your efi partition is mounted using the --efi-directory option.
This grub-efi is driving me nuts! I have it set up successfully on a hard disk with the Grub menu coming up just as I want it, but on a USB stick with FreeBSD installed using gpt with an efi partition, grub-install does not provide Grub menu on booting but does straight into the FreeBSD efi boot.

In an attempt to copy the efi partition from working to none working, I mounted both partitions and copied one to the other, but it made no difference.

Can't think of how to force a UEFI Grub boot... maybe it's something particular to the ThinkPad T420 or X220...
So, there are probably half a dozen things that could be wrong. You're going to have to narrow down the problem.
  1. Make the USB drive the only bootable device;
  2. Ensure there is only one .efi executable in its EFI partition; and
  3. If you have a BIOS bootloader installed on the drive, disable CSM so that the firmware can't fall back to legacy booting.
Then go from there.

You've probably just overlooked something, but it is possible that this is a firmware issue.

One thing I'll briefly mention is that there are limitations to when you can just copy the .efi file that grub-install generates from one location to another, since there are a couple of things that get hard-coded into it: (a) the path to GRUB's files--e.g., device, directory--and (b) the modules it needs to be able to read said files. It's not quite as flexible as FreeBSD's .efi executable when it comes to drop-and-go installation. But that's the price you pay when you need a bootloader that can boot almost anything.