Grub Entry to Boot FreeBSD

Thomas D. Dean tomdean at
Wed Jun 2 04:10:38 UTC 2021

I have a remote system with Linux and FreeBSD.  I want to select the 
next boot OS at runtime and boot it.

I can do that with
    grub-set-default 'Ubuntu'
    grub-set-default 'FreeBSD'
and reboot.

My problem is with the FreeBSD entry.  How do I write the entry?

The disks are:
nvme0n1     259:0    0 931.5G  0 disk
|-nvme0n1p1 259:4    0   512M  0 part /boot/efi
`-nvme0n1p2 259:5    0   931G  0 part /
nvme1n1     259:1    0 931.5G  0 disk
`-nvme1n1p1 259:3    0 931.5G  0 part
nvme2n1     259:2    0 931.5G  0 disk
|-nvme2n1p1 259:6    0   512K  0 part
|-nvme2n1p2 259:7    0   928G  0 part
`-nvme2n1p3 259:8    0   3.5G  0 part

/dev/nvme0n1p2: UUID="55626001-0033-445b-bd2b-0bf4766e25bb" TYPE="ext4"
/dev/nvme0n1p1: UUID="7076-258D" TYPE="vfat" PARTLABEL="EFI System
    Partition" PARTUUID="16a50609-64b2-47ad-8802-c3cbb4be263f"
/dev/nvme1n1p1: UUID="e26e4bf7-6e65-4fac-b2b4-f84019f70c08" TYPE="ext4"
/dev/nvme2n1p1: PARTUUID="3fed2b68-c26f-11eb-a073-18c04d84849a"
/dev/nvme2n1p2: UUID="60b57d7bd4b24f00" TYPE="ufs"
/dev/nvme2n1p3: PARTUUID="3fedfa22-c26f-11eb-a073-18c04d84849a"

Device              Start        End    Sectors  Size Type
/dev/nvme2n1p1         40       1063       1024  512K FreeBSD boot
/dev/nvme2n1p2       1064 1946157095 1946156032  928G FreeBSD UFS
/dev/nvme2n1p3 1946157096 1953525127    7368032  3.5G FreeBSD swap

Ubuntu  is on nvme0n1, or, I think hd0,1 in grub terms.
FreeBSD is on nvme2n1, or, I think hd2,2

But, grub thinks hd2 is just hd2 or hd2,msdos1

I have
 > cat /etc/grub.d/40_custom
exec tail -n +3 $0
# This file providesan easyway toadd custom menu entries.Simply type the
# menu entries youwant toadd after this comment.Be careful not to change
# the 'exec tail' line above.
menuentry 'FreeBSD' {
   insmod ufs2
   set root=(hd2,2)
   chainloader /boot/loader.elf

I tried
menuentry 'FreeBSD' {
     insmod ufs2
     set root=(hd2,1,a)
     search --no-floppy -fs-uuid --set 3fed2b68-c26f-11eb-a073-18c04d84849a
     kfreebsd /boot/loader

When I reboot after grub-set-default 'FreeBSD', the remote system hangs. 
  Grub can not find hd2.

More information about the freebsd-questions mailing list