How To Install FreeBSD within a ZFS Boot Environment

Creating the Disk Partitions

Now that you have a blank canvas its time create some partitions, we are going to need three identical partitions on each drive. The first is a tiny partition of 256K, which will contain the boot code. This will be the only partition that is not configured as a mirror as this doesn't change we will just have a copy of it on each drive, so if the primary drive fails the secondary will be able to boot. The second partition is the swap partition, it can be done in ZFS but I prefer to keep it outside ZFS, I am using 4G for its size, I chose this size, because my test environment had 4G of RAM. (A little low for a ZFS file server, but it will perform fine in a test environment) This one is going to be mirrored using geom mirror, so that if one drive fails while the system is up it can still access anything that might be in swap. The third is the ZFS partition, which will be mirrored by ZFS zpool, this of course is where all the important data is so the mirror is vital to keep a hard drive failure from causing data loss. (I am going to assume if you think your ready for this tutorial, that you know a mirror doesn't count as backup) I am just going to allow it to use all the remaining space, but you may want to size it slightly smaller to leave a buffer in case a replacement drive is slightly smaller. If you have worked on PCs as long as I have, you have likely learned the hard way, that not all hard drives of the same size are created equal.

gpart create -s GPT da0
gpart create -s GPT da1
gpart add -t freebsd-boot -l bootcode0 -s 256k da0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da0
gpart add -t freebsd-boot -l bootcode1 -s 256k da1
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da1
gpart add -t freebsd-swap -a 4k -l swap0 -s 4G da0
gpart add -t freebsd-swap -a 4k -l swap1 -s 4G da1
gpart add -t freebsd-zfs -a 4k -l zroot0 da0
gpart add -t freebsd-zfs -a 4k -l zroot1 da1

Note:  gpart create, creatse the partition table -s GPT, tells it to use GPT as the schema

Note:  gpart add, adds partitions, -t ? is the type of partition. freebsd-boot, is a boot partition type. freebsd-swap is the swap partition type. freebsd-zfs is the ZFS partition type.

Note:  gpart bootcode writes the bootcode to the boot partition, -b tells it to write the /boot/pmbr to the the bootstrap of the partitioning scheme, and -p tells it to write the partition bootcode (/boot/gptzfsboot) to the partition referenced by the index (-i) of the device (da0 & da1).

Note:  -a 4k, Means to align the partition on 4k, necessary if using newer 4k sector sized disks to keep them performing well, and doesn't seem to have much if any negative effect on older 512b sector disks.

Note:  -l ?, is just a named label, we will use these later instead of referencing the disks as da0p1, which if you ever change the order of the drives saves time and trouble, by not requiring corrections to the setup because the label stays with the partition even if the drive changes from da0 to da1 or da2, etcetera.