GRUB2-EFI boot problem

I managed to get a system working with grub2-efi last year, but can't get it installed properly now. Could it be related to a newer version of FreeBSD?

I have a disk which boots OK from an EFI partition, but when I install grub2-efi it boots up into grub rescue mode.

Does anyone have grub2-efi working with FreeBSD 11.1?
 
Could it be related to a newer version of FreeBSD?
I can't help much with Grub or EFI booting as I don't have either. But I don't think things have changed that much, if you got it working before it should still work the same way.
 
After reading the FreeBSD Wiki on UEFI it may well be that the EFI partition created was too small... I used this:
Code:
gpart add -t efi -s 100M -l MBefi -a1M da0
and then copied /boot/boot1.efi to this partition,,, maybe I should have used /boot/boot1.efifat.

What I can't work out from the Wiki is if the EFI partition should be the first one on the disk...

It also says - " The path to the loader may be set by an EFI environment variable, with a default of /EFI/BOOT/BOOTX64.EFI."
But where is this environment variable set?
 
Hello,
the /boot/boot1.efi bootloader is only capable of booting FreeBSD, as far as I know. But that doesn't really matter on UEFI (more on that later). The easiest way to achieve this is to create 800k efi partition and clone the /boot/boot1.efifat content there:
Code:
gpart add -t efi -s 800k /dev/<your_device>
dd if=/boot/boot1.efifat of=/dev/<your_new_efi_partition>
The boot1.efifat is actually an image of 800k FAT filesystem with boot1.efi stored as /EFI/BOOT/BOOTX64.EFI. So you can also manually create a FAT filesystem and copy the boot1.efi there:
Code:
gpart add -t efi -s 300m /dev/<your_device>
newfs_msdos -F 32 -L efi /dev/<your_new_partition>
mount -t msdosfs /dev/<your_new_partition> /mnt
mkdir -pv /mnt/EFI/BOOT
cp -v /boot/boot1.efi /mnt/EFI/BOOT/BOOTX64.EFI
umount /mnt
but I strongly suggest the former method.

balanga said:
What I can't work out from the Wiki is if the EFI partition should be the first one on the disk...
As far as I know, it doesn't have to. There can even be more of these partitions on your device.

balanga said:
" The path to the loader may be set by an EFI environment variable, with a default of /EFI/BOOT/BOOTX64.EFI."
But where is this environment variable set?
It is set in your motherboard NVRAM. There are tools to manipulate it. Linux has it's efibootmanager, grub-install does it for efi target (making use of efibootmanager), I'm unsure which tool to use in FreeBSD. However, the default EFI bootloader resides on efi-type partition with FAT filesystem as '/EFI/BOOT/BOOTX64.EFI' by standard. So a good motherboard should find such a bootloader on it's own and you shouldn't be required to do anything. If your motherboard doesn't find the loader or if you want to name it differently or put it into another directory, you must teach your motherboard where to find it.

I'm afraid I can only tell you how to do it via the efibootmanager at the moment. Say your efi partition is /dev/ada0p1 (which will probably be /dev/sda1 in Linux). Boot some efi-enabled Linux installation media and then:
Code:
efibootmgr -c -d /dev/sda -p 1 -l '\EFI\BOOT\BOOTX64.EFI' -L FreeBSD
Note: the backslashes are correct here.
Note2: /dev/ada0 doesn't have to be /dev/sda in some Linux distributions, it can also change over reboots. You need to make sure which device to use.

It will create a new entry in your NVRAM stating where to find the specific bootloader. This way you may teach your motherboard as many loaders on as many FAT partitions as you like (there can be more bootloaders on one partition, more bootloaders on more partitions, ...). A potential scheme like this shouldn't be a problem:
Code:
/dev/ada0
  |- /dev/ada0p1 (efi, FAT32) |- /EFI/FREEBSD/boot1.efi
                              |- /EFI/GENTOO/grub.efi
   .....
  |- /dev/ada0p5 (efi, FAT32) |- <some Windows boot stuff>
   .....
/dev/ada1
  |- /dev/ada1p1 (efi, FAT32) |- <some super exotic stuff>
   ...
You can teach your motherboard to boot all this.
 
Hello,
the /boot/boot1.efi bootloader is only capable of booting FreeBSD, as far as I know. But that doesn't really matter on UEFI (more on that later). The easiest way to achieve this is to create 800k efi partition and clone the /boot/boot1.efifat content there:
Code:
gpart add -t efi -s 800k /dev/<your_device>
dd if=/boot/boot1.efifat of=/dev/<your_new_efi_partition>
The boot1.efifat is actually an image of 800k FAT filesystem with boot1.efi stored as /EFI/BOOT/BOOTX64.EFI. So you can also manually create a FAT filesystem and copy the boot1.efi there:
Code:
gpart add -t efi -s 300m /dev/<your_device>
newfs_msdos -F 32 -L efi /dev/<your_new_partition>
mount -t msdosfs /dev/<your_new_partition> /mnt
mkdir -pv /mnt/EFI/BOOT
cp -v /boot/boot1.efi /mnt/EFI/BOOT/BOOTX64.EFI
umount /mnt
but I strongly suggest the former method.

Why the different sizes?
Code:
gpart add -t efi -s 800k /dev/<your_device>
Code:
gpart add -t efi -s 300m /dev/<your_device>

I see that the size of /boot/boot1.efifat is 819200 bytes, so I guess that 800k would be adequate...

I created an EFI partition of 100M but am unable to mount it using mount -t msdosfs /dev/ada0p1 /mnt
I get
mount_msdosfs: /dev/ada0p1: Invalid argument

Maybe I should delete the current EFI partition and create a smaller one...
 
Hello,

the different sizes are just an example. Of course, if you dd the boot1.efifat, the partition should have 800k, since that's the size of the image. If you create your own partition and format it yourself, the size doesn't really matter, but I experienced some problems while creating a new FAT32 filesystem when a partition was too small. Personally, I created 800k efi partition and copied the boot1.efifat image via dd and that works OK.

balanga said:
I created an EFI partition of 100M but am unable to mount it using mount -t msdosfs /dev/ada0p1 /mnt
I get
mount_msdosfs: /dev/ada0p1: Invalid argument

I tried it now and I see what you describe. For some reason, the newfs_msdos -F 32 complains about too few clusters when the partition is too small. I only succeeded when the partition was >= 3G. If the partition is smaller, I succeeded with newfs_msdos -F 16 instead of 32, but I'm not sure if this is the optimal solution.

Unfortunately, when I mount my efi partition (the one created from boot1.efifat), both df -T and mount -v only show that it is a msdosfs filesystem. They don't provide any other detail as to the FAT type. I'm afraid you'll have to experiment with these options a little. I can only say that I've never had any problems with the boot1.efifat image.
 
Does anyone have grub2-efi working with FreeBSD 11.1?

I have been trying to figure this out for some time also and succeeded just a moment ago thanks to these: (1), (2) and (3).

EDIT 1: Filesystem: UFS2, (3) Used grub2-efi package instead of using ports.

EDIT 2: Reboot displayed GRUB2 menu with two FreeBSD boot options. I then installed Devuan Jessie without (re)installing GRUB2 boot loader, i.e. selected "Continue without boot loader" in the Devuan installer main menu, "Finish(ed) the installation", rebooted and... the FreeBSD Boot Menu was displayed. :what: Back to testing...
 
Back
Top