Update: If you also want to encrypt everything except /boot, refer to
this version.
Update: This works for FreeBSD 8.2 as well.
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 8.1 DVD.
Drop into the fixit shell, using “CDROM/DVD” as the fixit media.
Load necessary kernel modules:
Fixit# chroot /mnt2 kldload nullfs zfs
Wipe out any existing partition table on the disk (da0 in this example):
Fixit# dd if=/dev/zero of=/dev/da0 bs=1m count=128
128+0 records in
128+0 records out
134217728 bytes transferred in 3.627965 secs (36995321 bytes/sec)
Initialize the disk with a GUID partition table (GPT):
Fixit# gpart create -s GPT da0
da0 created
Install GPT boot code “pmbr” into the MBR:
Fixit# gpart bootcode -b /mnt2/boot/pmbr da0
da0 has bootcode
Create the boot partition that pmbr expects 1, then install stage 2 boot code “gptzfsboot” into it:
Fixit# gpart add -t freebsd-boot -l crimson-boot -s 128 da0
da0p1 added
Fixit# gpart bootcode -p /mnt2/boot/gptzfsboot -i 1 da0
Create a swap partition (1GB in this example):
Fixit# gpart add -t freebsd-swap -l crimson-swap -s 1G da0
da0p2 added
Create a ZFS partition, then create a ZFS pool with it:
Fixit# gpart add -t freebsd-zfs -l crimson-001 da0
da0p3 added
Fixit# zpool create -o altroot=/mnt -o cachefile=/tmp/zpool.cache crimson gpt/crimson-001
Fixit# df -h /mnt
Filesystem Size Used Avail Capacity Mounted on
crimson 6.8G 18K 6.8G 0% /mnt
Make the ZFS pool available for booting 2:
Fixit# zpool set bootfs=crimson crimson
Set the mountpoint of the root filesystem to / 3:
Fixit# zfs set mountpoint=/ crimson
Now we will copy the FreeBSD installer (sysinstall) into the new filesystem and run it in a chroot-ed environment 4. sysinstall needs a couple of things, and we have to prepare them. First, make /dev and /dist (FreeBSD installation DVD) available inside the filesystem:
Fixit# mkdir /mnt/dev /mnt/mnt
Fixit# mount -t devfs devfs /mnt/dev
Fixit# mount_nullfs /dist /mnt/mnt
Copy sysinstall and friends, residing in /stand:
Fixit# find -xd /stand -print0 | cpio -pdum0 /mnt
5172 blocks
sysinstall expects a number of tools in /usr/bin; copy them:
Fixit# mkdir -p /mnt/usr/bin
Fixit# (cd /stand && find gunzip cpio -print0 | cpio -pdum0 /mnt/usr/bin)
We will instruct sysinstall to emit progress messages to a file named sysinstall.debug. Start dumping its contents onto ttyv4 (accessible by pressing Alt-F5):
Fixit# tail -Fc+0 /mnt/sysinstall.debug > /dev/ttyv4 &
Fixit# stty -f /dev/ttyv4 $(stty -g)
Now chroot into the filesystem and run sysinstall there:
Fixit# env debug=YES chroot /mnt /stand/sysinstall
In the main menu, go to the “Configure” menu.
In the configuration menu, choose “Media.”
In the media selection menu, choose “File System.”
sysinstall asks you where the installation file is. Enter “/mnt” (without quotes).
Back in the configuration menu, choose “Distributions.”
In the distribution selection menu, select all that you want to install, then select “Exit.” You will at least need the base and kernels at the very minimum.
sysinstall starts installation of selected distributions. Wait until installation finishes, and you are brought back to the configuration menu.
Configure the installed system further as necessary. Common tasks include:
- Setting root password;
- Setting the system timezone;
- Adding initial user/group;
- Setting at least one network interface (where you will set the hostname too);
- Enabling sshd.
- Exit to the main menu, then select “Exit Install” to end sysinstall.
Now we need to do additional, ZFS-specific configuration. First, copy zpool.cache, which was created earlier when we ran zfs create) into /boot/zfs 5:
Fixit# cd /mnt/boot
Fixit# mkdir -p zfs
Fixit# cp -p /tmp/zpool.cache zfs/zpool.cache
The previous sysinstall installed the kernel not in /boot/kernel but in /boot/GENERIC. Instruct BTX loader to look for the kernel there instead:
Fixit# echo 'kernel="GENERIC"' >> loader.conf
Load the ZFS kernel module when booting:
Fixit# echo 'zfs_load="YES"' >> loader.conf
Load geom_eli too, so that we can use encrypted swap:
Fixit# echo 'geom_eli_load="YES"' >> loader.conf
Instruct that the ZFS root pool (“crimson”) is also the root filesystem:
Fixit# echo 'vfs.root.mountfrom="zfs:crimson"' >> loader.conf
Tell ZFS not to disable prefetch:
Fixit# echo 'vfs.zfs.prefetch_disable="0"' >> loader.conf
Enable ZFS in /etc/rc.conf:
Fixit# cd /mnt/etc
Fixit# echo 'zfs_enable="YES"' >> rc.conf
Add the swap partition:
Fixit# echo '/dev/gpt/crimson-swap.eli none swap sw 0 0' >> fstab
Exit the fixit shell and go back to the FreeBSD installer:
Fixit# exit
Go to the main menu, then select “Exit Install” to reboot.
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. 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 altroot=…” changes in a future version of ZFS.
4
^ Note that an instance of sysinstall is already running on ttyv0, accessible by pressing Alt-F1; that's where we started the fixit shell in the first place. We are going to start another instance of sysinstall from the fixit shell on ttyv3 (Alt-F4).
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.