# Detect FreeBSD from GRUB on EFI



## Dylanus (Nov 28, 2018)

Hi all,

I'm posting my question here because it seems like my problem is specific to FreeBSD. I have a Dell laptop with Windows installed. I have installed Arch Linux on another partition, and it successfully detects Windows and allows me to boot it from the GRUB menu. I have also installed FreeBSD, but GRUB will not detect that.
When I mount the FreeBSD partition in Linux, `os-prober` detects an "unknown Linux", but GRUB does not create an entry for it. I have tried creating a custom entry in GRUB, but it requires the line 
	
	



```
set root=(hdX, Y)
```
. When I booted into this entry it told me that hd0 did not exist. I thought this would be the name, as I only have one drive. The names of the partitions are /dev/nvme0n1pX, which I assume is a Windows convention. I tried entering a GRUB shell as someone suggested on this forum, in order to figure out what the drive is called, to run `find /boot/grub/stage1`, but the GRUB shell does not recognise `find` as a command. This is an SSD, and there is only one, so I'm not sure what it would be called.
So, my problem is that I know where FreeBSD is installed, and I can get `os-prober` to recognise it, but I can't get GRUB to detect it. I can make a custom entry, but I don't know what my SSD is called to the computer prior to booting.
As I said, I think this is a BSD issue, as GRUB was able to detect Windows, and I've always been able to pick up other Linux OSes before. If any other information or output would help with diagnosing this, please let me know.

Thanks

*UPDATE:*
When I mount the FreeBSD slice in Arch Linux, it now shows up for `os-prober` and `grub-mkconfig`, however GRUB will not write an entry for it. I have tried writing the following entry in /etc/grub.d/40_custom:

```
menuentry "FreeBSD" {
    set root='(hd0,gpt10)'
    insmod ufs2
    kfreebsd /boot/loader
    chainloader +1
}
```
This is copied from here: https://forums.freebsd.org/threads/cannot-boot-freebsd-with-grub.60952/
This entry shows up in the GRUB menu, but when I select it, it tells me 
	
	



```
Invalid EFI path
```
.
I have confirmed that (hd0,gpt10) is the correct partition. When I list it in the GRUB shell it shows a UFS filesystem.
When I compared this with the entry generated for Windows, I noticed that the entry for Windows says 
	
	



```
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
```
This makes me think that the entry for BSD requires a path that GRUB can find to a FreeBSD EFI loader. Does that exist? Do I need to create one at installation?

Based on the information on UEFI here: https://wiki.freebsd.org/UEFI I have also tried copying boot1.efi from the FreeBSD /boot to the Linux /boot/EFI/Boot/ directory. I then changed the custom GRUB entry to read 
	
	



```
chainloader /EFI/Boot/boot1.efi
```
When I booted it said 
	
	



```
Error: file '/EFI/Boot/boot1.efi' not found
```
So it seems like the custom entry worked, but GRUB does not know how to find that file or boot the OS. I tried putting the file in /boot/EFI/GRUB/boot1.efi and editing 40_custom to reflect that, but I got the same results.
I've also noticed that when GRUB detects Windows it lists the partition it's located on as well as the filename of the EFI file, but for the "unknown Linux" entry it only lists the partition. I imagine the filesystem FreeBSD uses is partly responsible for this, but I'm not sure how to get around this problem.


----------



## Vull (Nov 29, 2018)

I think the file you're looking for is called /boot/loader.efi, and it should already be on your FreeBSD system in the /boot directory. I've used the following menuentry successfully for a Linux-hosted UEFI grub bootloader configuration on a modern Acer Aspire model A315-21-95KF laptop. Hopefully this might be just what you need, too:


```
menuentry "FreeBSD11.2-STABLE" {
  insmod ufs2
  root=(hd0,gpt7)
  chainloader /boot/loader.efi
}
```

For comparison, this next menuentry is what I'm using now on my Dell Dimension 4700 mini-tower. It's kind of a strange hybrid system from about 2008, or so which supports GPT partitions, but still requires using the old BIOS booting conventions:


```
menuentry "FreeBSD11.2-RELEASE" {
  insmod ufs2
  root=(hd0,gpt2)
  kfreebsd /boot/loader
 }
```

Hope this helps.


----------



## kpa (Nov 29, 2018)

Vull said:


> Dell Dimension 4700 mini-tower. It's kind of a strange hybrid system from about 2008, or so which supports GPT partitions, but still requires using the old BIOS booting conventions:



I would use a different wording about your system. It's a standard BIOS system that happens to be unbroken enough to honor the standard boot code conventions and not choke on slightly oddish partition layout on the MBR partition table of  GPT partitioned disk that uses the protective MBR code and partition table for MBR compatibility.


----------



## b6s6d6 (Nov 29, 2018)

The way it always works for me is pointing GRUB to the EFI partition, not the UFS/ZFS one. I use something like this:

```
menuentry "FreeBSD" {
    insmod part_gpt
    insmod fat
    set root=(hd0,gpt1)
    chainloader /efi/boot/bootx64.efi
}
```
Remember to change 'set root=(hd0,gpt1)' if your FreeBSD EFI partition is located elsewhere, then proceed to add this custom entry to /etc/grub.d/40_custom
Finally, run:
`# grub-mkconfig -o /boot/grub/grub.cfg`
so your changes are saved.


----------



## Vull (Nov 29, 2018)

kpa said:


> I would use a different wording about your system. It's a standard BIOS system that happens to be unbroken enough to honor the standard boot code conventions and not choke on slightly oddish partition layout on the MBR partition table of  GPT partitioned disk that uses the protective MBR code and partition table for MBR compatibility.


Perhaps "unusual" would've been a better word than "strange." Meant no disrespect to the Dell, which has served me well over the years, from a time when they were sort of in a race with AMD to get to the 64 bit finish line. Pretty competitive in its time, Intel Pentium 4 with 2.80 GHz clock speed, dual core, & hyperthreading, but no long mode addressing or UEFI. Things that work on it might not work on other 32 bit hosts. Presently it hosts 3 different Linux distros plus 7 FreeBSD development installs on a 1TB hard drive. Very flexible for its time and I kinda love it, but I hesitate to go on too much about it, since this might be considered a bit off topic in some venues. I'm new here and trying to stay inside the lines as well as I can. Great forum. Thanks for your interesting comment. I totally agree.


----------

