Learn all the essential commands to manage ZFS filesystems.

Table of Contents

Install ZFS utilities

You can find out how to install required packages in these links:

Ubuntu: you can install them by typing apt install zfsutils-linux as root or with sudo. Arch Linux: check https://wiki.archlinux.org/title/ZFS#Automatic_Start about enabling services to mount ZFS at boot. You may need to manually enable zfs kernel module (/sbin/modprobe zfs) and enable the module at boot by creating a .conf file inside /etc/modules.load.d/ and adding zfs inside.

Create a pool

zpool create [<options>] <pool name> [mirror|raidz|raidz2|raidz3] <device name> [<device name> ...]
# zpool create p1 virtio-pci-0000:08:00.0
# zpool create p1 mirror virtio-pci-0000:08:00.0 virtio-pci-0000:09:00.0
  • mirror is similar to RAID1 (1:1 redundancy), raidz gives 1 disk of parity (with a minimum of 3 disks), raidz2 2 disks of parity (with a minimum of 4 disks), and so on.
  • <device-name> can be device IDs (check ls -l /dev/disk/by-id/), device paths (check ls -l /dev/disk/by-path/) or device names like sda, sdb1, etc. (not recommended because the naming could change on every start). You can use GPT partition labels as well.
  • You can add the option -m <mount-point> to specify a mount point (by default creates a mount point inside /). You can find more <options> in man zpool-create.

Add disks to an existing pool

zpool add <pool name> <device-name>
# zpool add p1 virtio-pci-0000:09:00.0

Create a dataset

Datasets are like partitions. You can create filesystems inside them.

zfs create <pool name>/<dataset name>
# zfs create p1/main

Set a quota for a dataset

You can define disk quotas (it’s like defining the partition size) on a dataset.

zfs set quota=<size> <pool name>/<dataset name>
# zfs set quota=20G p1/main

Create a snapshot of a dataset or pool

zfs snapshot <pool name>/<dataset name>@<tag>
# zfs snapshot p1/main@2021-11-01
  • You can use any name for the <tag>.

List snapshots

zfs list -t snapshot

Roll a dataset or pool back to snapshot

zfs rollback <pool name>/<dataset name>@<tag>
# zfs rollback p1/main@2021-11-01

Restore a file from snapshot

Snapshots are located under <pool mount point>/<dataset>/.zfs/snapshot/ (or <pool mount point>/.zfs/snapshot/). First, check if that folder is visible, if not, type:

zfs set snapdir=visible <pool>/<dataset name>
# or
zfs set snapdir=visible <pool>

You can copy a file from the snapshot to restore it.

cp /p1/main/.zfs/snapshot/2021-11-01/debian.iso /p1/main/

Export a snapshot

zfs send <pool name>/<dataset name>@<tag> #writes to standard output
# zfs send p1/main@2021-11-01 > backupfile
# zfs send p1/main@2021-11-01 | zfs recv -F backups/main

Remove a snapshot

zfs destroy <pool name>/<dataset name>@<tag>

Destroy a dataset

zfs destroy <pool name>/<dataset name>
# zfs destroy p1/main

Destroy a pool

zpool destroy <pool name>
# zpool destroy p1
  • You will need to add -r if there are snapshots.

If you have any suggestion, feel free to contact me via social media or email.