Grub Entry to Boot FreeBSD

Navdeep Parhar nparhar at gmail.com
Wed Jun 2 18:50:08 UTC 2021


On 6/2/21 10:43 AM, Thomas D. Dean wrote:
> On 6/1/21 9:10 PM, Thomas D. Dean wrote:
>> 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'
>>     -or-
>>     grub-set-default 'FreeBSD'
>> and reboot.
>>
>> My problem is with the FreeBSD entry.  How do I write the entry?
>>
>> The disks are:
>>    NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
>> 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"
>>     PARTUUID="2b247e80-cf2e-4be1-b6d7-61152af7132f"
>> /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"
>>     PARTUUID="beccec5f-01"
>> /dev/nvme2n1p1: PARTUUID="3fed2b68-c26f-11eb-a073-18c04d84849a"
>> /dev/nvme2n1p2: UUID="60b57d7bd4b24f00" TYPE="ufs"
>>     PARTUUID="3fed7a4f-c26f-11eb-a073-18c04d84849a"
>> /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
>> #!/bin/sh
>> 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.
>>
> 
> It seems impossible to boot FreeBSD with grub.  In grub, I can find the 
> Freebsd /boot directory and load some files.  But, it will not boot.
> 

I boot FreeBSD with grub all the time but my setup is ZFS only.  There 
are multiple versions of FreeBSD, each installed into its own ZFS pool, 
on the system and I use grub to select which one to boot.

My grub.cfg looks like this and works with BIOS and UEFI:

---
insmod part_msdos
insmod part_gpt
insmod chain
insmod fat
insmod bsd
insmod zfs
load_env

menuentry "FreeBSD 13" {
         search -s -l bsd13
         kfreebsd -D /@/boot/zfsloader
         set default="${chosen}"
         save_env default
}

menuentry "FreeBSD 12" {
         search -s -l bsd12
         kfreebsd -D /@/boot/zfsloader
         set default="${chosen}"
         save_env default
}

and so on...
---

The most complicated FreeBSD entry that I can find in all the grub.cfg 
files that I have is this old one (BIOS only).  It boots the system from 
an mfsbsd ISO:

menuentry "mfsBSD 11.2-RELEASE" {
         loopback loop /boot/mfsbsd-11.2-RELEASE-amd64.iso
         kfreebsd -D (loop)/boot/kernel/kernel.gz
         kfreebsd_loadenv (loop)/boot/device.hints
         kfreebsd_module (loop)/boot/kernel/ahci.ko
         kfreebsd_module (loop)/mfsroot.gz type=mfs_root
         set kFreeBSD.console="comconsole,vidconsole"
         set kFreeBSD.comconsole_speed="115200"
         set kFreeBSD.vfs.root.mountfrom="ufs:/dev/md0"
         set kFreeBSD.mfsbsd.autodhcp="YES"
}

Regards,
Navdeep



More information about the freebsd-questions mailing list