dual boot with root on ZFS

Some time ago I was experimenting on a server with dual booting FreeBSD and Linux from the same ZFS pool.

The idea was, that I could allocate the space dynamically instead of using hard partitions and wasting valuable disk space.

As of writing, ZFSonLinux and FreeBSD use different mechanisms to figure out which partition to mount as the root partition. And this is what makes the dual boot possible at the end.

The following description uses only EFI. I have no idea if this also possible with other boot managers. systemd-boot serves as the boot manager.

disk layout

The disk must contain a EFI system partition and the rest will be made available for ZFS.

zpool settings

Some care must be taken with enabling features on a ZFS pool, because each kernel must be able to understand the flags. For example the ZFS version of a CentOS7 might not be able to use lzma compression. In that case the ZFS driver will just not mount the partition and you might end up with that distribution unbootable.

For FreeBSD to be able to boot, the partition must be set as the boot target directly on the zpool like:

zpool set bootfs=rpool/ROOT/freebsd rpool

zfs partitions

I have used rpool/ROOT as the partition for all OS partitions, so I ended up with:

To make things easier I set the following flags on rpool/ROOT:

This way all OS partitions get the same attributes and I don’t have to remember to set it after creating a new OS tree.

systemd-boot

As for the boot entries I have used systemd-boot and its easily to modify loader entries.

For FreeBSD my loader entry looks like

title FreeBSD
efi /freebsd.efi

where I have copied the freebsd.efi file directly into /boot. FreeBSDs actual /boot partition resides in its partition rpool/ROOT/freebsd.

For my archlinux I use the lts kernel to avoid breakage with new kernel releases which results in the following entry

title Archlinux
linux /vmlinuz-linux-lts
initrd /initramfs-linux-lts.img
options zfs=rpool/ROOT/archlinux rw

installation process

As for the installation process, I first installed archlinux. After that was up and running, I installed FreeBSD via downloading the base.txz and unpacking it into its own partition.

Apart from the default adjustments to /etc/rc.conf and setting a root password nothing further was needed to properly boot the system.

documentation

There is some really good documentation for the details out there, for example

And please do not forget to read the man pages. ZFS and systemd have some really wonderful man pages with tons of knowledge put into them. In most cases there are even some examples at the end.

Enjoy and have fun.