Use ZFS The Architect Way

A major system upgrade.
A risky configuration change.
Testing a new application.

On traditional filesystems, recovery usually means restoring from backups.
Sometimes it requires reinstalling the system entirely.

OpenZFS provides tools for managing risk.
Snapshotsdataset propertiescompression, and encryption can be managed directly by the filesystem.

OpenZFS is more than a filesystem.
It is a filesystem and volume manager designed to simplify storage administration.

Storage pools

Storage pools provide the storage capacity used by ZFS datasets.
They consist of one or more disks.

Multi-device pools can be mirrored.
They can be part of a Raid-Z array.
The vdev type is a permanent decision.

To create a mirrored pool, use the zpool command’s create subcommand:

zpool create ghostpool mirror /dev/ada1 /dev/ada2

Check the status of all pools:

zpool status

Manage datasets

Datasets do not require dedicated partitions.
They share the available space of the storage pool.

You can create, destroy, snapshot and rollback datasets in the pools.
Datasets are like flexible, individual filesystems.

You can create them with the zfs create command:

zfs create zroot/backups

List the available datasets with the zfs list command:

zfs list

The output is similar:

NAME USED AVAIL REFER MOUNTPOINT
zroot 3.52G 18.3G 96K /zroot
zroot/ROOT 1.41G 18.3G 96K none
zroot/ROOT/default 1.41G 18.3G 1.41G /
zroot/backups 96K 18.3G 96K /zroot/backups
zroot/home 244K 18.3G 96K /home
zroot/home/ghost 148K 18.3G 148K /home/ghost
zroot/jails 1.06G 18.3G 104K /usr/local/jails
zroot/jails/containers 640M 18.3G 104K /usr/local/jails/containers
zroot/jails/containers/nginx 99.1M 18.3G 391M /usr/local/jails/containers/nginx
zroot/jails/templates 449M 18.3G 96K /usr/local/jails/templates
zroot/jails/templates/15.1-RELEASE 449M 18.3G 292M /usr/local/jails/templates/15.1-RELEASE
zroot/tmp 144K 18.3G 144K /tmp
zroot/usr 1.04G 18.3G 96K /usr
zroot/usr/ports 1.04G 18.3G 1.04G /usr/ports
zroot/usr/src 96K 18.3G 96K /usr/src
zroot/var 732K 18.3G 96K /var
zroot/var/audit 96K 18.3G 96K /var/audit
zroot/var/crash 96K 18.3G 96K /var/crash
zroot/var/log 240K 18.3G 240K /var/log
zroot/var/mail 108K 18.3G 108K /var/mail
zroot/var/tmp 96K 18.3G 96K /var/tmp

When a dataset is not in use anymore, destroy it:

zfs destroy zroot/backups

Later you learn how to mount a dataset and adjust its properties.

Dataset properties

Datasets can contain other datasets.
Properties can be inherited from parent datasets or set individually.
These properties determine how datasets behave.

Check all available properties with (on FreeBSD):

man zfsprops

You can check every property with the zfs get command:

zfs get all zroot/jails

Or the ones you are curious about:

zfs get compressratio,mountpoint zroot/jails

Then the output is shorter:

NAME PROPERTY VALUE SOURCE
zroot/jails compressratio 2.10x -
zroot/jails mountpoint /usr/local/jails local

Compression

Compression is one of the biggest strengths of ZFS.

zfs set compression=zstd-3 zroot/backups

Different types of data achieve different compression ratios.

# zfs get compressratio zroot/jails
NAME PROPERTY VALUE SOURCE
zroot/jails compressratio 2.10x -

Mountpoints

Datasets aren’t mounted like traditional filesystems.
No fstab edits.
No cryptic mount options.

You simply set the mountpoint option:

zfs set mountpoint=/backups zroot/backups

Snapshots

Dataset snapshots create restore points in the system.
They’re fast. They’re lightweight.

Create them with:

zfs snapshot zroot/backups@snapshot

List only the snapshots:

zfs list -t snapshot

Restore a snapshot simply with the rollback command:

zfs rollback zroot/backups@snapshot

If a snapshot is no longer in use, destroy it:

zfs destroy zroot/backups@snapshot

Snapshot clones

A clone is a copy of a snapshot treated like a regular dataset.
After creating a clone, the originating snapshot cannot be destroyed while the clone depends on it.

zfs clone zroot/data@snapshot zroot/newdata

Encrypted datasets

Encryption is part of ZFS.
You encrypt datasets individually.

To create an encrypted dataset there are three mandatory properties:

  • encryption
  • keyformat
  • keylocation

You can learn about them using the man zfsprops command.

To create an encrypted dataset:

zfs create -o mountpoint=/othertest -o encryption=on -o keyformat=passphrase -o keylocation=prompt zroot/othertest

The system prompts for the passphrase when the dataset is mounted.

Final Thoughts

ZFS is not a traditional filesystem.
It’s not better than the others. It’s different.

You don’t fight with fstab.
You don’t look for mystical mount options.
You don’t do a snapshot restoration wizardry.

It simply works.


Discover more from Tom's IT Cafe

Subscribe to get the latest posts sent to your email.

Leave a comment