Simple ZFS Usage

For years all I heard from various people I know was “ZFS“. It was the answer to almost every question and given how few OS’s supported it always appeared to be the promised land over the rainbow. That was then, but in recent years the availability of ZFS has grown quickly and I can now fully appreciate what they were saying was true. I’ve used ZFS on Ubuntu and now am using it on FreeBSD without too many problems.
I’m far from an expert but this may help others make the switch.

Keeping it Simple

My main concern is preserving data rather than speed, so I’ve chosen to go with a simple “mirror” setup for my pools. I’ve also not enabled compression at present, though I may in the future.

Root

On both Ubuntu and FreeBSD the ZFS commands root privilege, hence the use of sudo below.

Pools?

ZFS file systems live within a ZFS pool. Before you can create a mountpoint and it’s associated file system you need a pool. For a pool you need at least one physical drive available.
zpool operates on pools and zfs operates on file systems.

On my system I added 2 4Tb drives which after looking at dmesg and fdisk I confirmed were /dev/sdd and /dev/sde. Given these were new disks I didn’t do anything to create partitions as I was about to use them for the pool.

$ sudo zpool create tank mirror /dev/sdd /dev/sde

Once created it was time to check their status.

$ sudo zpool status
pool: tank
 state: ONLINE
  scan: none requested
config:
 
        NAME        STATE     READ WRITE CKSUM
        tank        ONLINE       0     0     0
            sdd     ONLINE       0     0     0
            sde     ONLINE       0     0     0
 
errors: No known data errors

File Systems

One aspect I didn’t fully appreciate was that file systems will automatically be mounted under the pool name. This can be easily changed but can make things much easier.

To create a file system with a mountpoint of /tank/media all you need is this command.

$ sudo zfs create tank/media

However, if you want the file system to be mounted as /media you can specify it at creation.

$ sudo zfs create -o mountpoint=/media tank/media

Once created, changing your mind is simple enough as well. To change the mountpoint from /tank/media to /media is just

$ sudo zfs set mountpoint=/media tank/media

Once created, the newly created file systems appear as any other mounted filesystem.

$ mount
/dev/ada4p2 on / (ufs, local, journaled soft-updates)
devfs on /dev (devfs, local, multilabel)
tank/media on /media (zfs, local, nfsv4acls)
tank on /tank (zfs, local, nfsv4acls)

I’m far from an expert on this, but it’s all quite logical and if I can figure it out… 🙂