30.3. Managing Datasets and Properties

A pool is infrastructure; datasets are where the application data lives. The dataset hierarchy should express differences in policy: compression, record size, access-time updates, quotas, encryption, and snapshot schedules. Setting a property on a parent is a convenient default, but every child that needs a different value should override it explicitly.

30.3.1. Dataset Layout, Property Inheritance, and Mountpoints

Create a parent and a child dataset:

# zfs create tank/data

The command is silent. Create the child:

# zfs create tank/data/docs

This command is also silent. Change the ownership of the leaf dataset so that john can write test files without root:

# chown john:john /tank/data/docs

List the datasets and their accounting:

# zfs list -o name,used,avail,refer,mountpoint
NAME             USED  AVAIL  REFER  MOUNTPOINT
raidpool         540K  1.31G    96K  /raidpool
tank             624K   831M    96K  /tank
tank/data        192K   831M    96K  /tank/data
tank/data/docs    96K   831M    96K  /tank/data/docs

USED includes the dataset's own data, its snapshots, and its children; REFER is the space referenced by the dataset itself; AVAIL is the space available to that dataset after quotas and reservations. The parent and child show the same AVAIL because neither has a quota. AVAIL is also deliberately more conservative than the FREE column of zpool list: it is reduced by the pool's reserved slop space, and on RAIDZ vdevs it additionally allows for the parity overhead of a worst-case write pattern. That is why raidpool reports 1.31G available although its pool summary in Section 30.2.3 showed 2.87G free, and why the difference grows when more parity columns are added. The default mountpoint is derived from the dataset name under the pool's mountpoint.

Properties and their source show what is local and what is inherited:

# zfs get -o property,value,source mountpoint,compression,recordsize,atime tank/data tank/data/docs
PROPERTY     VALUE            SOURCE
mountpoint   /tank/data       default
compression  on               default
recordsize   128K             default
atime        on               default
mountpoint   /tank/data/docs  default
compression  on               default
recordsize   128K             default
atime        on               default

SOURCE is default when no local value or inherited value applies. After a parent is changed, a child reports inherited from tank/data. A local value overrides inheritance for that dataset and its children until another child overrides it again.

The query options used here are:

Option Description
zfs get -o property,value,source Selects the property name, current value, and source
zfs get -r dataset Repeats the query for the dataset and its descendants
zfs get -H Suppresses the header, which is useful in scripts
zfs list -o field,... Selects and orders dataset columns
zfs list -t snapshot Lists snapshots instead of filesystems

A dataset can use an independent mountpoint outside the pool root:

# zfs create tank/mounts

The create command is silent. Set the independent mountpoint:

# zfs set mountpoint=/srv/zfs-mounts tank/mounts

The set command is silent; changing mountpoint unmounts and remounts the dataset at the new location. Verify the property and the actual mount:

# zfs get -o property,value,source mountpoint,mounted tank/mounts
PROPERTY    VALUE            SOURCE
mountpoint  /srv/zfs-mounts  local
mounted     yes              -
# findmnt -no TARGET,SOURCE,FSTYPE /srv/zfs-mounts
/srv/zfs-mounts tank/mounts zfs

findmnt reads the kernel mount table, so it confirms that ZFS performed the mount rather than merely recording the property. The SOURCE column is the dataset name, not a device path. A ZFS mount is not a traditional block-device mount even though it appears in the same table.

The dataset properties most often set at creation are:

Property Description
mountpoint Directory where the dataset is mounted; none leaves it unmounted, legacy leaves mounting to another tool
canmount Whether the dataset may be mounted; off is useful for a parent that only holds children
compression Compression algorithm or off/on; on selects LZ4 when the feature is enabled
recordsize Suggested maximum block size for filesystem data
atime Whether reads update access times
quota Hard limit on the dataset and its descendants, including snapshots
reservation Guaranteed minimum space for the dataset and its descendants
readonly Prevents writes to the dataset
exec Allows or denies execution of files on the dataset
setuid Allows or denies setuid programs on the dataset
acltype Selects POSIX ACL or NFSv4 ACL behavior
xattr Selects extended-attribute storage behavior

A parent dataset such as tank/data is usually a policy holder. Set canmount=off on it if it should not have its own mountpoint, and create one child per workload. Avoid making the pool root dataset (tank) the home of application data; keeping it minimal makes import and recovery easier to reason about.

30.3.2. Compression, Record Size, Access Times, and Workload Choices

ZFS compresses each block independently, so compression is transparent to applications and can be enabled on an existing dataset. Set LZ4 on the parent and disable access-time updates; set a larger record size on the child that stores large sequential files:

# zfs set compression=lz4 tank/data
# zfs set atime=off tank/data
# zfs set recordsize=1M tank/data/docs

Each command is silent. The child inherits the parent's compression and atime settings but keeps its own record size:

# zfs get -o property,value,source compression,recordsize,atime tank/data tank/data/docs
PROPERTY     VALUE           SOURCE
compression  lz4             local
recordsize   128K            default
atime        off             local
compression  lz4             inherited from tank/data
recordsize   1M              local
atime        off             inherited from tank/data

The source column is the useful part: lz4 on tank/data/docs is inherited, not a separate local setting. If the parent later changes to zstd, the child follows unless it has a local override. This is convenient for policy, but it also means that an administrator can change many datasets by editing a parent.

Write 8 MiB of random data to the child and inspect the compression result:

$ dd if=/dev/urandom of=/tank/data/docs/random.bin bs=1M count=8 status=none

The command is silent because status=none suppresses the transfer summary. Random data is incompressible, so the ratio stays near 1:

# zfs get -o property,value,source compressratio,used,logicalused tank/data/docs
PROPERTY       VALUE  SOURCE
compressratio  1.00x  -
used           8.10M  -
logicalused    8.04M  -

Now write a highly repetitive 8 MiB text file as john:

$ yes "Debian ZFS compression sample" | head -c 8388608 > /tank/data/docs/text.log

The pipeline generates repeated text and stops at 8 MiB; it produces no terminal output because the data goes to the file. The file size is:

$ ls -l /tank/data/docs/text.log
-rw-rw-r-- 1 john john 8388608 Nov 24 14:54 /tank/data/docs/text.log

The dataset's compression ratio rises because the text compresses well:

# zfs get -o property,value,source compressratio,used,logicalused tank/data/docs
PROPERTY       VALUE  SOURCE
compressratio  1.97x  -
used           8.17M  -
logicalused    16.0M  -

logicalused counts the uncompressed bytes written by the files; used is the physical space after compression and metadata. The ratio is historical: it reflects all blocks currently in the dataset, not only the most recent write. Deleting the text file lowers used only after snapshots that reference it are destroyed.

The common compression choices are:

Value Trade-off Suitable workloads
off No CPU cost, no space saving Pre-compressed media, encrypted or already-compressed data where CPU is scarce
lz4 Very fast, modest ratio; the default behind compression=on General-purpose filesystems, virtual machines, logs
zstd Better ratio than LZ4 at higher CPU cost; level can be selected Archival data, text, source trees, systems with CPU headroom
gzip / gzip-N Higher ratio, slower; levels 1–9 Cold data where space matters more than latency
zle Fast but weak; mainly historical Rarely worth selecting on current systems

recordsize is a hint, not a fixed block size. The default 128 KiB suits general filesystems. A database or virtual-machine image that performs many small random writes may benefit from a smaller record size, while a dataset of large sequential files may benefit from 1 MiB. Changing recordsize affects new writes only; existing blocks keep their original size until rewritten. Do not set a huge record size for a dataset full of small files: it wastes space and can increase read amplification for random access.

Access-time updates are a write-amplification source. atime=off prevents a read from generating a metadata write on the dataset. On a desktop, access times can be useful for mail clients and file browsers; on a server, they are usually noise. If you need them, consider relatime semantics at the application level or accept the extra writes.

Other workload properties worth knowing are:

Property Effect When to change it
sync=standard Honors synchronous write requests; the default Keep for databases and mail spools
sync=always Treats every write as synchronous; slower but safer for some workloads Only when the application cannot request sync itself
sync=disabled Ignores synchronous requests; risks data loss on power failure Never for important data
logbias=latency Uses the ZIL to reduce latency for synchronous writes Default for most workloads
logbias=throughput Does not use configured log devices; optimizes synchronous writes for overall pool throughput Bulk sequential writes
primarycache=all Caches data and metadata in the ARC Default
primarycache=metadata Caches metadata only Large streaming reads that would evict useful data
secondarycache=all Uses L2ARC if present Systems with an L2ARC device

The checksum property is on by default and is separate from compression:

# zfs get -o property,value,source checksum tank/data
PROPERTY  VALUE      SOURCE
checksum  on         default

checksum=on selects the default algorithm, currently Fletcher-4 on this OpenZFS build. Stronger algorithms are available for datasets where undetected corruption is unacceptable, at some CPU cost. Section 30.5.1 covers the trade-offs and scrub behavior.

30.3.3. Quotas, Reservations, and Space Accounting

A quota is a hard limit on the space a dataset and its descendants may consume, including snapshots. A reservation guarantees that space remains available to the dataset even when the pool is otherwise full. Set both on the docs dataset:

# zfs set quota=50M tank/data/docs
# zfs set reservation=10M tank/data/docs

Both commands are silent. The properties and current usage are:

# zfs list -o name,quota,reservation,used,avail,refer tank/data/docs
NAME            QUOTA  RESERV   USED  AVAIL  REFER
tank/data/docs    50M     10M  8.17M  41.8M  8.17M

AVAIL is the quota remaining, not the pool's free space. A 60 MiB write exceeds the quota and fails:

$ dd if=/dev/urandom of=/tank/data/docs/quota-test.bin bs=1M count=60 status=none
dd: error writing '/tank/data/docs/quota-test.bin': Disk quota exceeded

The partial file remains until it is removed, so the dataset is now at its limit:

# zfs list -o name,quota,used,avail tank/data/docs
NAME            QUOTA   USED  AVAIL
tank/data/docs    50M  50.2M     0B

USED can exceed the quota slightly because metadata and block accounting are not byte-for-byte identical to the file size. The parent's space view shows where the usage is charged:

# zfs list -o space tank/data tank/data/docs
NAME            AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
tank/data        781M  50.3M        0B     96K             0B      50.2M
tank/data/docs     0B  50.2M        0B   50.2M             0B         0B

USEDCHILD on the parent is the child's usage; USEDDS on the child is its own data. USEDSNAP would show blocks retained by snapshots, and USEDREFRESERV would show space reserved for a zvol's refreservation. This breakdown is the quickest way to answer "what is using the space?" before destroying snapshots or raising quotas.

Remove the failed file and clear the limits:

$ rm -f /tank/data/docs/quota-test.bin

The removal is silent. In the root shell, clear both limits:

# zfs set quota=none tank/data/docs
# zfs set reservation=none tank/data/docs

Both zfs set commands are silent. Setting a property to none removes the local value and restores inheritance or the default. The related properties differ in scope:

Property Applies to Counts snapshots? Effect
quota Dataset and descendants Yes Hard limit on total used space
refquota Dataset itself No Hard limit on referenced data, excluding snapshots and children
reservation Dataset and descendants Yes Guaranteed minimum space
refreservation Dataset itself No Guaranteed space for the dataset's own data; commonly used for zvols
userquota@user Named user's objects Yes, within the dataset Limits one user's space
groupquota@group Named group's objects Yes, within the dataset Limits one group's space

User and group quotas require the userquota/groupquota feature and are managed with zfs userspace and zfs groupspace. They are useful on shared file servers but do not replace per-dataset quotas for application isolation. A reservation is not a quota: it guarantees space but does not cap usage, so a dataset with a reservation can still fill the rest of the pool.

30.3.4. Zvols and Block Storage Consumers

A zvol is a dataset that presents a block device. Create a 128 MiB zvol with compression disabled, because the consumer may already compress or encrypt its data:

# zfs create -V 128M -o compression=off tank/vol1

The command is silent. The block device appears under /dev/zvol and in the block-device list:

# lsblk -o NAME,SIZE,TYPE
NAME    SIZE TYPE
zd0     128M disk
vda     100G disk
└─vda1  100G part
vdb       1G disk
├─vdb1 1014M part
└─vdb9    8M part
vdc       1G disk
├─vdc1 1014M part
└─vdc9    8M part
vdd       1G disk
├─vdd1 1014M part
└─vdd9    8M part
vde       1G disk
├─vde1 1014M part
└─vde9    8M part
vdf       1G disk
vdg       1G disk
├─vdg1 1014M part
└─vdg9    8M part

zd0 is the zvol; the zfs_member partitions on vdb through vdg belong to the pools. The zvol's size and space usage are dataset properties:

# zfs list -o name,volsize,used,volmode tank/vol1
NAME       VOLSIZE   USED  VOLMODE
tank/vol1     128M   132M  default

USED includes the zvol's reserved space and metadata, so it can be slightly larger than VOLSIZE. volmode=default exposes the device according to the platform; other values include dev (create /dev/zvol links), full (also create partition devices), and none (do not expose a block device). A zvol with volmode=none is useful as a snapshot-only container but cannot be mounted as a block device.

Create a filesystem on the zvol and mount it:

# mkfs.ext4 -q /dev/zvol/tank/vol1

mkfs.ext4 -q is quiet. Create the mountpoint:

# mkdir -p /mnt/vol1

The mkdir is silent. Mount the filesystem:

# mount /dev/zvol/tank/vol1 /mnt/vol1

The mount is silent on success. The ext4 filesystem on the zvol is owned by root, so the write goes through sudo tee from john's shell:

$ echo zvol-data | sudo tee /mnt/vol1/probe.txt
zvol-data

tee writes to the file and copies the data to standard output, which is why the line appears. Reading it back confirms the mount:

$ cat /mnt/vol1/probe.txt
zvol-data

Unmount the filesystem before destroying the zvol:

# umount /mnt/vol1

The unmount is silent. Destroy the zvol:

# zfs destroy tank/vol1

The destroy is silent. Destroying a zvol destroys its data; unmount any filesystem or stop any virtual machine using the device first. ZFS refuses to destroy a dataset with dependent clones or snapshots unless -r or -R is used, so a successful destroy is a strong signal that nothing else depends on it.

The zvol properties most often changed are:

Property Description
volsize Logical size of the block device; can be increased, but shrinking requires care
volblocksize Block size for the zvol; set at creation and difficult to change
volmode How the device is exposed (default, dev, full, none)
refreservation Space reserved for the zvol; a thick-provisioned zvol reserves its full size
compression Compression for zvol blocks; usually off for VM images or encrypted consumers
sync Synchronous-write behavior; a VM guest may issue its own flushes

A zvol is not automatically thin or thick in the way a storage array uses those terms. By default ZFS reserves enough space to guarantee that the zvol can be fully written, which is a form of thick provisioning. refreservation=none allows overcommit, but a full pool can then make the zvol fail writes. For virtual machines, decide deliberately whether the pool guarantees the zvol's size or whether overcommit is acceptable.

30.3.5. Native Encryption, Key Loading, and Key Backup

ZFS native encryption is per dataset. It protects data at rest, including snapshots and send streams when the stream is created with -w, but it does not protect a mounted filesystem from a user who has access to it. Create a raw key as john:

$ cd ~/debian-handbook/zfs
$ dd if=/dev/urandom of=secure.key bs=32 count=1 status=none
$ chmod 600 secure.key

The commands are silent. keyformat=raw requires exactly 32 random bytes; do not use a text password or a truncated file. The key file is readable only by john, but root can read it because root can read everything. Store a backup of the key separately from the pool; without it, the encrypted dataset is unrecoverable even if the disks are healthy.

Create the encrypted dataset as root, pointing at john's key file:

# zfs create -o encryption=on -o keyformat=raw -o keylocation=file:///home/john/debian-handbook/zfs/secure.key tank/secure

The command is silent. Inspect the encryption properties:

# zfs get -o property,value,source encryption,keyformat,keylocation,keystatus,mounted tank/secure
PROPERTY     VALUE                                             SOURCE
encryption   aes-256-gcm                                       -
keyformat    raw                                               -
keylocation  file:///home/john/debian-handbook/zfs/secure.key  local
keystatus    available                                         -
mounted      yes                                               -

encryption and keyformat have no settable source after creation; they are immutable properties of the dataset. keystatus=available means the key is loaded in memory. mounted=yes means the dataset is mounted and usable. A child dataset created under tank/secure inherits encryption and uses the same key unless it specifies a different keylocation.

Give john ownership and write a file:

# chown john:john /tank/secure

The chown is silent. Back in john's shell, write a file:

$ echo classified > /tank/secure/secret.txt

echo writes to the file and prints nothing. Unmount the dataset and unload its key:

# zfs unmount tank/secure
# zfs unload-key tank/secure

The commands are silent. The key status changes and the dataset is no longer mounted:

# zfs get -o property,value keystatus,mounted tank/secure
PROPERTY   VALUE
keystatus  unavailable
mounted    no

Trying to mount without the key fails:

# zfs mount tank/secure
cannot mount 'tank/secure': encryption key not loaded

Load the key and mount again:

# zfs load-key tank/secure
# zfs mount tank/secure

Both commands are silent on success. The data is readable by john:

$ cat /tank/secure/secret.txt
classified

Back up the key and verify the copy:

$ cp secure.key secure.key.backup
$ cmp secure.key secure.key.backup

cp is silent; cmp is also silent when the files are identical. A silent cmp is the success signal here; if the files differed, cmp would print the first differing byte and offset and exit nonzero. Store the backup on a different system or medium, not only in the same pool. A key stored next to the encrypted data protects against disk theft only until the thief finds the key.

Change the dataset's key location to the backup file:

# zfs change-key -o keylocation=file:///home/john/debian-handbook/zfs/secure.key.backup tank/secure

The command is silent. The property now points at the backup:

# zfs get -o property,value keylocation tank/secure
PROPERTY     VALUE
keylocation  file:///home/john/debian-handbook/zfs/secure.key.backup

Changing keylocation does not re-encrypt the data; it changes where the key is loaded from on the next load. To change the key itself, use zfs change-key -o keyformat=... -o keylocation=... with a new key; OpenZFS rewraps the dataset key, which is much cheaper than rewriting all data. Keep the old key until the new key is verified and backed up.

A wrong key fails cleanly, without exposing any data. Create a second raw key file that is well-formed but does not hold the dataset's key, in john's shell:

$ dd if=/dev/urandom of=wrong.key bs=32 count=1 status=none

The command is silent; it writes 32 fresh random bytes into the workspace. In the root shell, attempt to load it:

# zfs load-key -L file:///home/john/debian-handbook/zfs/wrong.key tank/secure
Key load error: Incorrect key provided for 'tank/secure'.

The dataset remains unavailable; no data is exposed. Load the correct key again:

# zfs load-key tank/secure
# zfs mount tank/secure

Both commands are silent. The data is readable again:

$ cat /tank/secure/secret.txt
classified

The load-key and mount commands are silent; cat prints the file. This sequence is the normal boot-time recovery for an encrypted dataset: import the pool, load the key, then mount. The pool import does not automatically load file-based keys unless zpool import -l is used, and even then the key file must be available at the path recorded in keylocation.

The encryption options and operational commands are:

Option or command Description
encryption=on Enables encryption with the default aes-256-gcm
encryption=aes-256-gcm Selects AES-256-GCM explicitly
keyformat=raw Key is exactly 32 raw bytes from keylocation
keyformat=passphrase Key is derived from a passphrase with -o pbkdf2iters=...
keylocation=file:///path Loads the key from a file
keylocation=prompt Prompts for the key at load time
zfs load-key -a Loads all available keys
zfs unload-key -r dataset Unloads keys for a dataset hierarchy
zfs change-key dataset Rewraps the dataset key; used to change key material or location
zfs send -w ... Sends encrypted data without decrypting it

Native encryption protects data at rest and in -w send streams. It does not protect against a compromised running system, a key file left readable on the host, or an administrator who can load the key. Treat the key file as a credential: restrict its permissions, back it up separately, and rotate it if it may have been exposed.