--- arch-wiki: https://wiki.archlinux.org/title/ZFS website: https://openzfs.org/wiki/Main_Page repo: https://github.com/openzfs/zfs obj: filesystem --- # ZFS [ZFS](https://en.wikipedia.org/wiki/ZFS "wikipedia:ZFS") is an advanced filesystem. ## ZPool **Create a pool*** ```shell zpool create -f -m [raidz(2|3)|mirror] ``` **Pool Status** ```shell zpool list zpool status -v ``` **Import Pool** ```shell zpool import -l -d /dev/disk/by-id # Import pool zpool import -a # Import all available pools zpool import -a -f # Import all available pools with force option ``` **Export Pool** ```shell zpool export ``` **Extend Pool** ```shell zpool add ``` **Destroy pool / dataset** ```shell zpool destroy zfs destroy / ``` **Rename a pool** ```shell zpool export oldname zpool import oldname newname ``` **Upgrade pool** ```shell zpool upgrade ``` ### Automount Specify this for `zfs-import-cache.service` to pick up the pool ```shell zpool set cachefile=/etc/zfs/zpool.cache ``` ## Datasets ### Dataset Managment **Create Dataset** ```shell zfs create / ``` **Create encrypted dataset:** ```shell openssl rand 32 > /path/to/key # Generate key zfs create -o encryption=on -o keyformat=raw -o keylocation=file://$KEYLOCATION "$DATASET" ``` **Change encryption keys:** ```shell zfs change-key -l [-o keylocation=value] [-o keyformat=value] [-o pbkdf2iters=value] filesystem ``` **Load all encryption keys** ```shell zfs load-key -a ``` **Load all keys at boot with systemd** __/etc/systemd/system/zfs-load-key.service__: ``` ini [Unit] Description=Load encryption keys DefaultDependencies=no After=zfs-import.target Before=zfs-mount.service [Service] Type=oneshot RemainAfterExit=yes ExecStart=/usr/bin/zfs load-key -a StandardInput=tty-force [Install] WantedBy=zfs-mount.service ``` **Destroy dataset:** ```shell # Destroy dataset zfs destroy / # Destroy Dataset recursively with all subdatasets zfs destroy -r / ``` **Mount dataset:** ```shell zfs mount / zfs unmount / ``` ### Snapshots **Create snapshot:** ```shell zfs snapshot /@ ``` **Rollback snapshot:** ```shell # Rollback to snapshot and destroy any newer snapshots zfs rollback -r /@ ``` **Show differences between snapshots:** ```shell zfs diff -F tank/test@before tank/test ``` The `-F` flag shows more information about the type of files that have changed: | Symbol | Meaning | | ------ | ---------------- | | `B` | Block device | | `C` | Character device | | `/` | Directory | | `>` | Door | | `|` | Named pipe | | `@` | Symbolic link | | `P` | Event port | | `=` | Socket | | `F` | Regular file | **Send and receive:** ```shell zfs send -v -w /@ | zfs recv / ``` ### Properties **Get properties:** ```shell zfs get / ``` **Set properties** ```shell zfs set = / ``` ### Available Properties | PROPERTY | EDIT | INHERIT | VALUES | | ---------------------- | ---- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `available` | NO | NO | `` | | `clones` | NO | NO | `[,...]` | | `compressratio` | NO | NO | `<1.00x or higher if compressed>` | | `createtxg` | NO | NO | `` | | `creation` | NO | NO | `` | | `encryptionroot` | NO | NO | `` | | `filesystem_count` | NO | NO | `` | | `guid` | NO | NO | `` | | `keystatus` | NO | NO | `none` / `unavailable` / `available` | | `logicalreferenced` | NO | NO | `` | | `logicalused` | NO | NO | `` | | `mounted` | NO | NO | `yes` / `no` | | `origin` | NO | NO | `` | | `redact_snaps` | NO | NO | `[,...]` | | `referenced` | NO | NO | `` | | `snapshot_count` | NO | NO | `` | | `type` | NO | NO | `filesystem` / `volume` / `snapshot` / `bookmark` | | `used` | NO | NO | `` | | `usedbychildren` | NO | NO | `` | | `usedbydataset` | NO | NO | `` | | `usedbyrefreservation` | NO | NO | `` | | `usedbysnapshots` | NO | NO | `` | | `written` | NO | NO | `` | | `atime` | YES | YES | `on` / `off` | | `casesensitivity` | NO | YES | `sensitive` / `insensitive` / `mixed` | | `checksum` | YES | YES | `on` / `off` / `fletcher2` / `fletcher4` / `sha256` / `sha512` / `skein` / `edonr` / `blake3` | | `compression` | YES | YES | `on` / `off` / `lzjb` / `gzip` / `gzip-[1-9]` / `zle` / `lz4` / `zstd` / `zstd-[1-19]` / `zstd-fast` / `zstd-fast-[1-10,20,30,40,50,60,70,80,90,100,500,1000]` | | `copies` | YES | YES | `1` / `2` / `3` | | `dedup` | YES | YES | `on` / `off` / `verify` / `sha256[,verify]` / `sha512[,verify]` / `skein[,verify]` / `edonr,verify` / `blake3[,verify]` | | `encryption` | NO | YES | `on` / `off` / `aes-128-ccm` / `aes-192-ccm` / `aes-256-ccm` / `aes-128-gcm` / `aes-192-gcm` / `aes-256-gcm` | | `keyformat` | NO | NO | `none` / `raw` / `hex` / `passphrase` | | `keylocation` | YES | NO | `prompt` / `` / `` / `` | | `mountpoint` | YES | YES | `` / `legacy` / `none` | | `pbkdf2iters` | NO | NO | `` | | `quota` | YES | NO | `` / `none` | | `readonly` | YES | YES | `on` / `off` | | `relatime` | YES | YES | `on` / `off` | | `reservation` | YES | NO | `` / `none` | | `snapdir` | YES | YES | `hidden` / `visible` | ### Scrub Like [Btrfs](Btrfs.md) ZFS can heal itself with scrubbing **Start a scrub:** ```shell zpool scrub ``` **Cancel a scrub:** ```shell zpool scrub -s ``` **Autoscrubbing with systemd:** __/etc/systemd/system/zfs-scrub@.timer__ ```ini [Unit] Description=Monthly zpool scrub on %i [Timer] OnCalendar=monthly AccuracySec=1h Persistent=true [Install] WantedBy=multi-user.target ``` __/etc/systemd/system/zfs-scrub@.service__ ```ini [Unit] Description=zpool scrub on %i [Service] Nice=19 IOSchedulingClass=idle KillSignal=SIGINT ExecStart=/usr/bin/zpool scrub %i [Install] WantedBy=multi-user.target ```