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.
Snapshots, dataset properties, compression, 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 MOUNTPOINTzroot 3.52G 18.3G 96K /zrootzroot/ROOT 1.41G 18.3G 96K nonezroot/ROOT/default 1.41G 18.3G 1.41G /zroot/backups 96K 18.3G 96K /zroot/backupszroot/home 244K 18.3G 96K /homezroot/home/ghost 148K 18.3G 148K /home/ghostzroot/jails 1.06G 18.3G 104K /usr/local/jailszroot/jails/containers 640M 18.3G 104K /usr/local/jails/containerszroot/jails/containers/nginx 99.1M 18.3G 391M /usr/local/jails/containers/nginxzroot/jails/templates 449M 18.3G 96K /usr/local/jails/templateszroot/jails/templates/15.1-RELEASE 449M 18.3G 292M /usr/local/jails/templates/15.1-RELEASEzroot/tmp 144K 18.3G 144K /tmpzroot/usr 1.04G 18.3G 96K /usrzroot/usr/ports 1.04G 18.3G 1.04G /usr/portszroot/usr/src 96K 18.3G 96K /usr/srczroot/var 732K 18.3G 96K /varzroot/var/audit 96K 18.3G 96K /var/auditzroot/var/crash 96K 18.3G 96K /var/crashzroot/var/log 240K 18.3G 240K /var/logzroot/var/mail 108K 18.3G 108K /var/mailzroot/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 SOURCEzroot/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/jailsNAME PROPERTY VALUE SOURCEzroot/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.