HxHippy

ZFS Datasets and Properties

Creating and managing ZFS datasets with properties for quotas, compression, and more.

Last updated: 2025-01-15

Understanding Datasets

ZFS datasets are the primary way to organize data. They're similar to directories but with their own properties that can be inherited by children.

Dataset Types

  • Filesystem: Regular mountable dataset
  • Volume (zvol): Block device (for VMs, iSCSI)
  • Snapshot: Read-only point-in-time copy
  • Bookmark: Lightweight snapshot reference

Creating Datasets

# Create basic dataset
zfs create tank/data

# Create with specific mountpoint
zfs create -o mountpoint=/srv/files tank/files

# Create nested datasets
zfs create tank/data/projects
zfs create tank/data/backups

# Create unmounted dataset
zfs create -o mountpoint=none tank/templates

Dataset Properties

View Properties

# All properties
zfs get all tank/data

# Specific property
zfs get compression tank/data

# Multiple properties
zfs get compression,compressratio,used,available tank/data

# All datasets, one property
zfs get compression -r tank

Set Properties

# Enable compression (lz4 recommended)
zfs set compression=lz4 tank/data

# Set quota (hard limit)
zfs set quota=100G tank/data/user1

# Set reservation (guaranteed space)
zfs set reservation=50G tank/data/important

# Set record size (for specific workloads)
zfs set recordsize=1M tank/data/media  # Large files
zfs set recordsize=16K tank/data/database  # Databases

# Disable access time updates (performance)
zfs set atime=off tank/data

Common Properties

Property Description Values
compression Data compression off, lz4, gzip, zstd
quota Maximum space size or none
reservation Guaranteed space size or none
recordsize Block size 512 to 1M
atime Access time updates on, off
exec Allow execution on, off
setuid Allow setuid on, off
readonly Read-only mode on, off
mountpoint Where to mount path or none
canmount Can be mounted on, off, noauto

Inheritance

# Properties inherit from parent
zfs set compression=lz4 tank
# All children of tank now use lz4

# Override for specific dataset
zfs set compression=gzip tank/logs

# Check inheritance source
zfs get compression -o name,value,source tank/data
# Output shows: local, inherited from, default

Managing Datasets

# List all datasets
zfs list

# List with specific columns
zfs list -o name,used,avail,refer,mountpoint

# Recursive list
zfs list -r tank

# Rename dataset
zfs rename tank/old tank/new

# Move dataset
zfs rename tank/data/project tank/archive/project

Destroying Datasets

# Destroy dataset
zfs destroy tank/data/temp

# Recursive destroy (children too)
zfs destroy -r tank/old

# Destroy with snapshots
zfs destroy -R tank/data@snap1

# Dry run (show what would be destroyed)
zfs destroy -n -v tank/data/temp

ZVOLs (Block Devices)

# Create 50GB zvol
zfs create -V 50G tank/vm/disk1

# Create sparse zvol (thin provisioned)
zfs create -s -V 100G tank/vm/disk2

# Access as block device
ls -la /dev/zvol/tank/vm/disk1

# Use with bhyve VM or iSCSI

Best Practices

  1. Use meaningful names - Organize by purpose
  2. Set compression early - Before adding data
  3. Use quotas - Prevent runaway usage
  4. Disable atime - Unless needed for specific apps
  5. Inherit sensible defaults - Set at pool level
intermediate ZFS Updated 2025-01-15
  • zfs
  • datasets
  • properties
  • quota
  • compression
  • freebsd