Creating zpools
OpenZFS zpool properties docs
OpenZFS zpool features docs
Useful options to pay attention to during storage creation: ashift, autotrim, autoexpand, autoreplace, async_destroy, device_rebuild (only on mirrors), embedded_data (need both sending & receiving pools to support it), encryption, longname, lz4_compress, physical_rewrite, raidz_expansion, resilver_defer, zilsaxattr, zpool_checkpoint, zstd_compress
vdev_type values: mirror, raidz1, raidz2, draid
Examples:
Generic: zpool create -o zpoolprop1 -o zpoolfeature1 -O datasetfeature1 poolname1 vdev_type /dev/device1 /dev/device2 /dev/device3 /dev/device4
Simple filesystem storage pool (mirror of HDDs): zpool create -o ashift=12 stor1
Simple filesystem storage pool (mirror of SSDs): zpool create -o ashift=12 -O autotrim=on stor1
Simple filesystem storage pool (raidz2 of HDDs): zpool create -o ashift=12 stor1
Postgres pool (HDD mirror): zpool create postgres1_pool mirror /dev/sda /dev/sdb
Ideally, add a SLOG device on NMVe/SSD to a HDD pool by doing this after pool creation: zpool add postgres1_pool log /dev/nvme1
Postgres pool (SSD mirror): zpool create postgres1_pool -o autotrim=on mirror /dev/nvme1 /dev/nvme2
zpool create
Creating ZFS datasets
OpenZFS zfs properties docs
Feature flag OS support matrix
Oracle ZFS dataset properties docs
Examples:
zfs create pg_main
Replacing drives
Finding drives: gpart list and smartctl to get the disk's serial number and manufacturer (and then search the hard drives to find the right one)
Replacing drives (when you can leave the old drive connected & working, even if in a degraded/faulted state): zpool replace poolname old_drive_identifer new_drive_identifier (obv, replace poolname, old and new drive IDs with proper values) That command will remove old_drive_identifier from the pool, and add new_drive_identifier to it, and start the resilvering process (which writes all the data on the old drive onto the new one)
Replacing drives (when you have a mirror or raidzX redundancy, and the old drive is dead):
zpool offline poolname old_drive_identifier (to remove the drive from the pool poolname)
zpool replace poolname new_drive_identifer (to add the new drive)
Approach 2:
zpool replace poolname old_drive_guid new_drive_identifier (when old drive is no longer connected, zpool status will show the old drive GUID, which can then be used in the zpool replace command)
ZIL (ZFS Intent Log)
Often an SSD, used as a write cache for a zpool.
L2ARC
Also often an SSD, used as a read cache for a zpool.
Recovering a destroyed pool
Try running zpool import -D - if no changes have been made, but you just accidentally ran a zpool destroy on your pool, this might allow it to be recreated.
To import a pool that is missing a log device, try zpool import -m poolname.
Space usage
Try using the basics:
zpool list to see how much pool space there is (note that this reports raw disk space, but in case of raidz pools, it overstates truly available storage since its calculations are in raw bytes, not pre-parity bytes (for real/pre-parity space available, use zfs list).
zfs list to see how much space each of the datasets is taking. Note that the space usage includes child datasets by default.
zfs list -o space to see more detailed breakdowns of what is taking up space (snapshots, etc.)
Sharing
Suggestion: set casesensitivity=mixed for datasets that will be shared over Samba
Fun
Every ZFS dataset has a .zfs folder in its root (that is not shown in ls -a) that contains snapshot and share directories
zfs diff dataset@snapshotname will tell you all the files that have changed since snapshot.
zfs allow -u username permissiontype,permissiontype2 dataset will grant permissions (of permissiontype and permissiontype2) to username
zfs allow -s @permissionset permissiontype1,permissiontype2 dataset will create a permission set (a group of permissions that can be easily applied) for a dataset
zfs allow -u username @permissionset dataset will then grant permissions to that permission set.
zfs history poolname will show important historical events for the pool (scrubs, imports/exports, ...?)
zfs get creation will show the creation timestamps of all datasets + snapshots