--- arch-wiki: https://wiki.archlinux.org/title/ZFS website: https://openzfs.org/wiki/Main_Page repo: https://github.com/openzfs/zfs obj: filesystem --- #refactor # 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 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 ### Creation **Create Dataset** ```shell zfs create / ``` **Create encrypted dataset:** ```shell dd if=/dev/random of=/path/to/key bs=1 count=32 # Generate key zfs create -o encryption=on -o keyformat=raw -o keylocation=file://$KEYLOCATION "$DATASET" ``` **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 ``` ### Snapshots **Create snapshot:** ```shell zfs snapshot /@ ``` **Send and receive:** ```shell zfs send -v -w /@ | zfs recv / ``` ### Properties **Get properties:** ```shell zfs get / ``` **Set properties** ```shell zfs set = / ``` ### Available Properties - `compressratio` : Shows information on compression - `creation` : Get creation date - `mounted` : Status on mount - `used` : Information on usage - `canmount` : Forbid or enable mounting - `casesensitivity` : Choose sensitivity - `compression` : Choose compression method - `encryption` : Encryption Information - `mountpoint` : Specify the mountpoint - `quota` : Filesystem Quota - `readonly` : Readonly or Readwrite - `reservation` : Reserved Space ### 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 ```