freebsd – How to Create a GRUB Entry for FreeBSD on ZFS Installation

dual-bootfreebsdgrub2zfs

To be clear what I want is a FreeBSD GRUB2 entry that boots FreeBSD on a ZFS (name: zroot) with BIOS firmware (not UEFI). The operating system GRUB is installed on is Arch Linux if it helps, Arch is using a ext4 root, it is FreeBSD that is using ZFS.

My partition table is (GPT):

/dev/sda1 - BIOS boot (1M) 
/dev/sda2 - Linux swap (4G) 
/dev/sda3 - Linux filesystem (ext4, 50G) 
/dev/sda4 - FreeBSD boot (128k) 
/dev/sda5 - FreeBSD ZFS filesystem (74G)

I've seen this answer but it pertains to FreeBSD on a UFS root, and I've also seen this answer which pertains to Arch Linux on ZFS, not FreeBSD on ZFS.

I've tried using this entry:

menuentry "FreeBSD" --class freebsd --class bsd --class os {
    insmod zfs
    insmod bsd
    set root=(hd0,4)
    kfreebsd /boot/kernel/kernel
    kfreebsd_loadenv /boot/device.hints
    set kFreeBSD.vfs.root.mountfrom="zfs:zroot"
    set kFreeBSD.vfs.root.mountfrom.options=rw
    set kFreeBSD.hw.psm.synaptics_support=1
}

but I received this error:

enter image description here

Using FreeBSD's bootloader (which sadly I overrode by installing GRUB to my disk, although it is simple to restore it) I managed to boot my FreeBSD install, so there's nothing wrong with it. I installed FreeBSD and set it up to boot by following what I put in this directory: https://github.com/fusion809/freebsd-scripts/tree/master/zfs-manual-install.

Best Answer

Never mind I found the answer thanks to the FreeBSD forums. This is what I needed in my grub.cfg:

menuentry "FreeBSD" --class freebsd --class bsd --class os {
    insmod zfs
    insmod bsd
    search -s -l zroot
    kfreebsd /@/boot/zfsloader
    kfreebsd_loadenv /@/boot/device.hints
}

To be clear I have tried this successfully, I even tried writing a file and rebooting to check it wasn't just read-only and the file was still there and had not been altered by the reboot in any way (not even its permissions were).

Related Question