ZFS on FreeBSD

posted by Christian in General

This posting is a small wrap-up of how I set-up ZFS on my FreeBSD 7 installation. I am currently in the process of installing FreeBSD 7 on a Compaq 6710b. A complete report about this will follow in a future posting, but this posting is not about the hardware side.

Sun's file system ZFS has a lot of cool features. If you understand german, you can listen to Chaosradio Express episode 49 to learn more about it.

DISCLAIMER: Disk related things always put your data at risk. So keep back-ups of your data. Following anything here might destroy your hard disk (or the data on it). I cannot take any responsibility for that. I only write up what worked for me.

I like to use disk encryption. ZFS in theory supports encryption, but it is not really available for FreeBSD, yet. So I set up GEOM Based Disk Encryption as described in the disk encryption chapter of the FreeBSD handbook. Using geli should work just as fine.

Instead of creating a file system with newfs (step 5) I set up the zfs pool using the geom device.

# zpool create tank ad4s1c.bde

Note that step 6 and 7 are not applicable in this set-up.

I used some tips from the FreeBSD ZFS quick start guide, like enabling compression on the ports tree, except the distfiles directory. However, I choose to have a plain old UFS root partition and normal swap partition. Fortunately, you can use one ZFS partition and still have different subdirectories in your root that use this ZFS partition without using symlinks.

# zfs create tank/usr
# zfs create tank/usr/ports
# zfs set compression=gzip tank/usr/ports
# zfs create tank/usr/ports/distfiles
# zfs set compression=off tank/usr/ports/distfiles
# zfs create tank/tmp
# zfs create tank/var

Once everything has been copied to the right place, I set the mountpoints.

# zfs set mountpoint=/usr tank/usr
# zfs set mountpoint=/var tank/var
# zfs set mountpoint=/tmp tank/usr

To have everything set-up at boot time, I added the following to /etc/rc.conf:

gbde_autoattach_all="YES"
gbde_devices="ad4s1c"
gbde_lockdir="/etc/gbde"
zfs_enable="YES"

Furthermore, I made sure that ad4s1c is not mentioned anymore in the fstab (neither ad4s1c.bde). It was still there because I created the partition with the installer.

Note that gbde is handled before ZFS during start-up. Hence, there is no problem having ZFS in an encrypted container like this. The same holds when you use geli.

I wanted to copy some data from a Linux machine (the former installation) to a FreeBSD machine (the new installation) using an external USB disk. You can use ZFS with fuse on linux. So, in principal, that should have worked something like this:

--- On the source machine:
# zpool create ext sdb1
# cp -r * /ext/
# zpool export ext
--- On the target machine
# zpool import ext
# cp -r /ext/* .

Unfortunately, I got a message that the pool was created with a newer ZFS version. So I tried to attach the disk on my iBook where Linux is installed, but while tryin to install fuse ZFS I had to realize that only amd64, x86, and sparc64 are supported by ZFS on fuse.

So far this set-up works just fine. I will see how useful thing like snapshots are.