Dual-boot Gentoo and FreeBSD zfs

This article suppose that you have Gentoo installed on zfs already.

Also consider this how-to as highly experimental and check all the commands that you know what are you doing.

Requirements (starting point)

 * Boot partition on ext2 (min 500MB).
 * grub:0 or grub:2 installed on boot

Update your zfs layout to something like this:

rpool                         47,1G  10,9G   160K  /rpool rpool/GENTOO                  15,6G  10,9G   168K  /rpool/GENTOO rpool/GENTOO/distfiles        4,49G  10,9G  4,49G  /rpool/GENTOO/distfiles rpool/GENTOO/opt              1,93G  10,9G   984M  /rpool/GENTOO/opt rpool/GENTOO/portage          1,40G  10,9G   897M  /rpool/GENTOO/portage rpool/GENTOO/root             7,79G  10,9G  4,67G  legacy

It is needed to create layout that will not colide on both systems.

Boot partition looks like this:

Create ZFS datasets
First we need to create zfs layout for freebsd:

zfs create rpool/FREEBSD zfs create rpool/FREEBSD/ports zfs create rpool/FREEBSD/ports/distfiles zfs create rpool/FREEBSD/ports/packages zfs create rpool/FREEBSD/root

Set some optional variables:

zfs set atime=off rpool/FREEBSD zfs set compression=lz4 zfs set compression=off rpool/FREEBSD/ports/distfiles zfs set compression=off rpool/FREEBSD/ports/packages

Unpack FreeBSD tarballs
cd /rpool/FREEBSD/ wget ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/9.2-RELEASE/base.txz wget ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/9.2-RELEASE/kernel.txz wget ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/9.2-RELEASE/ports.txz

cd root xzcat ../base.txz | tar -xv xzcat ../kernel.txz | tar -xv ln -s /rpool/FREEBSD/ports usr/ports xzcat ../ports.txz | tar -xv

Prepare boot directory
Copy boot contents to boot partition.

mkdir /boot/boot cd /rpool/FREEBSD/root mv boot/* /boot/boot/ mv boot bootdir ln -s bootdir/boot boot

Set new boot parition in new FreeBSD fstab.

echo '/dev/ada0s1 /bootdir ext2fs rw 0 1' > etc/fstab

Setup FreeBSD files
These settings are needed to make FreeBSD boot. For other options check freebsd handbook.

echo 'zfs_load="YES"' > /boot/boot/loader.conf echo 'vfs.root.mountfrom="zfs:rpool/FREEBSD/root"' >> /boot/boot/loader.conf echo 'ext2fs_load="YES"' >> /boot/boot/loader.conf

Set some variables to rc.conf

echo 'hostname="xxx"' > etc/rc.conf

Setup grub
Since I use grub-legacy, this apply to it. But not much different in grub-2.

Set menu entry in grub:

title FreeBSD root (hd0,0) kernel /boot/loader

Finish
Now if everything will goes well, you can reboot to new FreeBSD installation. For other setups consult freebsd handbook/wiki/forums.