How To Install FreeBSD within a ZFS Boot Environment

With the data extracted, time to edit the configuration.

There are three files we need to edit to get the system running, the /etc/rc.onf file needs to be configured to enable ZFS, this tells the system to auto-mount mountable ZFS dataset on boot. I would also recommend at least setting your host name and configuring the network interface to DHCP, and enabling the SSH Daemon at this point as well.

cat << EOF >> /mnt/etc/rc.conf

The /etc/fstab file needs to have a line added to tell the system where to find the swap partition, of course as you can boot without it, so if you want you can leave this step until later. since the swap partition is using GEOM Mirror, for redundancy it also needs to be initialized first, so now's a good time to do that.

kldload geom_mirror
gmirror label -b load -F swap /dev/gpt/swap0 /dev/gpt/swap1
cat << EOF >> /mnt/etc/fstab
/dev/mirror/swap none swap sw 0 0

Note:  kldload: loads the kernel module supporting GEOM Mirrors into memory gmirror label: creates the mirror, -b load tells it to balance reads based on load, -F tells it to not synchronize after crash, not necessary since all valid data is written after the new boot, swap is the label, fololowed by the backing devices.

Since ZFS and GEOM Mirror modules are not included in the standard kernel we also have to edit the /boot/loader.conf file to tell the system to load these modules at boot time.

cat << EOF >> /mnt/boot/loader.conf