This is a step-by-step guide, mostly for my own reference, but you might find this useful too.
Disclaimer: This article is about clean installation of operating system, where “clean” means that, if you follow these instructions, all existing contents of the hard drive will be destroyed. Do not follow these instructions except on an empty hard drive. I shall not be held responsible for any loss of data.
Boot using the FreeBSD 9.0 DVD.
Proceed with installation until the installer asks you how to partition the disk. Choose “Shell”.
Wipe out any existing partition table on the disk (da0 in this example):
# dd if=/dev/zero of=/dev/da0 bs=1m count=128
128+0 records in
128+0 records out
134217728 bytes transferred in 1.475510 secs (90963625 bytes/sec)
Initialize the disk with a GUID partition table (GPT), then install stage 1 (GPT) boot code “pmbr” into the MBR:
# gpart create -s GPT da0
da0 created
# gpart bootcode -b /boot/pmbr da0
bootcode written to da0
Create the boot partition that pmbr expects 1, then install stage 2 boot code “gptzfsboot” into it:
# gpart add -t freebsd-boot -l crimson-boot -s 128 da0
da0p1 added
# gpart bootcode -p /boot/gptzfsboot -i 1 da0
Create a swap partition (1GB in this example):
# gpart add -t freebsd-swap -l crimson-swap -s 1G da0
da0p2 added
Create a ZFS partition, then create a ZFS pool with it:
# gpart add -t freebsd-zfs -l crimson-root da0
da0p3 added
# zpool create -o altroot=/mnt -o cachefile=/tmp/zpool.cache crimson gpt/crimson-root
# df -h /mnt
Filesystem Size Used Avail Capacity Mounted on
crimson 897G 31k 897G 0% /mnt
Make the ZFS pool available for booting 2:
# zpool set bootfs=crimson crimson
Set the mountpoint of the root filesystem to / 3:
# zfs set mountpoint=/ crimson
Copy zpool.cache, which was created earlier when we ran zfs create) into /boot/zfs 5:
# mkdir -p /mnt/boot/zfs
# cp -p /tmp/zpool.cache /mnt/boot/zfs/zpool.cache
Add the swap partition:
# echo '/dev/gpt/crimson-swap none swap sw 0 0' >> /tmp/bsdinstall_etc/fstab
Return to the installer:
# exit
Continue with regular installation procedure, until it asks you: “The installation is now finished. Before exiting the installer, would you like to open a shell in the new system to make any final manual modifications?” Choose “Yes”, which will drop you into a shell again.
Now we need to do additional, ZFS-specific configuration. But before doing so, first mount /dev:
# mount -t devfs devfs /dev
Load the ZFS kernel module when booting:
# cd /boot
# echo 'zfs_load="YES"' >> loader.conf
Instruct that the ZFS root pool (“crimson”) is also the root filesystem:
# echo 'vfs.root.mountfrom="zfs:crimson"' >> loader.conf
Tell ZFS not to disable prefetch:
# echo 'vfs.zfs.prefetch_disable="0"' >> loader.conf
Enable ZFS in /etc/rc.conf:
# cd /etc
# echo 'zfs_enable="YES"' >> rc.conf
Exit the shell.
# exit
Installation is completed; the system will ask you to reboot. Do so, with your fingers crossed. :-p
1
^ pmbr locates a GUID partition of freebsd-boot type then loads and executes the next-stage boot code from it.
2
^ gptzfsboot locates a ZFS pool with the bootfs (boot filesystem) property set, then loads and executes BTX loader (a.k.a. /boot/loader) from that filesystem.
3
^ In fact we don't have to do this, at least as of FreeBSD 8.1/8.2/9.0. As a little-known and undocumented side effect of specifying an altroot at the time of pool creation, the mountpoint property of root filesystem has already been set to /. I included this step just in case the default behavior of “zpool create -o altroot=…” changes in a future version of ZFS.
5
^ zpool.cache contains information about system pools (i.e. pools imported without the -R option). Various stages of booting process need it in order to locate the root/boot pool.