Discussion:
Grub Entry to Boot FreeBSD
Thomas D. Dean
2021-06-02 04:10:32 UTC
Permalink
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.
Thomas D. Dean
2021-06-02 17:43:09 UTC
Permalink
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?
  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 used Freebsd from 0.1 386bsd to FreeBSD 11. Then switched to linux for
a major application. Now, I have a couple applications to run on
FreeBSD. It did not seem so hard earlier...

There are many 'different' examples that turn up when I google. But,
none of them seem to work.

I give up.
Navdeep Parhar
2021-06-02 18:50:03 UTC
Permalink
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?
   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
infoomatic
2021-06-03 11:10:52 UTC
Permalink
May I suggest using UEFI? With UEFI you can install refind, and in the
EFI partition there is a refind.conf where you can edit the default boot
option. Its really simple to setup and work with, the only small issue
is with an update on the Linux side it changes the efi boot order, but
with efibootmgr you can change it back...
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?
  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.
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to
Thomas D. Dean
2021-06-03 15:10:43 UTC
Permalink
Post by infoomatic
May I suggest using UEFI? With UEFI you can install refind, and in the
EFI partition there is a refind.conf where you can edit the default boot
option. Its really simple to setup and work with, the only small issue
is with an update on the Linux side it changes the efi boot order, but
with efibootmgr you can change it back...
I am willing to use grub, since it is already installed. I do not want
additional, unknown code.
Post by infoomatic
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?
  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.
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
Thomas D. Dean
2021-06-05 01:35:00 UTC
Permalink
I have another system with FreeBSD on the 3rd disk.

menuentry "FreeBSD" {
insmod part_gpt
insmod ufs2
search --no-floppy --set root --file /boot/loader
echo "$root"
kfreebsd /boot/loader
}

works there.

But not on this system with nvme ssd's.

Thanks for the help. I have no more time for this.

Loading...