Skip to content

ZFS ​

Import ZFS pool ​

Import encrypted ZFS pool ​

  1. sudo zfs set keylocation=file:///directory/pool-key pool-name

  2. sudo zpool import pool-name -l

Create ZFS pool ​

Create new ZFS pool using by-id ​

Example 1:

zpool create -f -m /mnt/data bigdata \
            raidz \
                ata-ST3000DM001-9YN166_S1F0KDGY \
                ata-ST3000DM001-9YN166_S1F0JKRR \
                ata-ST3000DM001-9YN166_S1F0KBP8 \
                ata-ST3000DM001-9YN166_S1F0JTM1

Example 2:

zpool create -f -o ashift=12 sp-storage \
            raidz2 \
                ata-ST8000NM0055-1RM112_ZA1DZ7LK \
                ata-ST8000NM0055-1RM112_ZA1DZXGC \
                ata-ST8000NM0055-1RM112_ZA1DZ7FJ \
                ata-ST8000NM0055-1RM112_ZA1DZLR9

Create ZFS dataset ​

Create encrypted ZFS dataset using raw key and ZSTD compression

zfs create -o compression=zstd -o encryption=on -o keyformat=raw -o keylocation=file:///directory/dataset-key dataset-name

Auto backup ZFS encrypted datasets ​

Script that automatically backs up encrypted datasets using incremental snapshots can be found in server-resources repository. You can create a cron job to run this task. Refer to Linux help topic.

ZFS Replication ​

Flags ​

Recursive, include child datasets

-R

Raw send, use this for encrypted dataset

-w

Incremental

pool/dataset@existingsnapshot pool/dataset@newsnapshot

Examples ​

zfs send -Rwi originpool@existingsnapshot originpool@newsnapshot | pv | ssh root@targetserver zfs recv targetpool/targetdataset

In this example, we are using the above flags to send an incremental stream to the target server. We are piping through pv to measure data transfer.

ZFS Snapshots ​

Create recursive snapshot

zfs snapshot -r pool/dataset@snapshot-name

Get full name of last snapshot

zfs list -t snapshot -H -o name pool/dataset | tail -n1

If the snapshot names always begin with a year, you can use egrep to shorten the snapshot names

zfs list -t snapshot -H -o name pool/dataset | egrep -o '20.+' | tail -n1

Workarounds ​

Mounting ZFS volumes automatically ​

In case ZFS volumes are not mounting after reboot, these commands should be run.

sudo zpool set cachefile=/etc/zfs/zpool.cache pool-name
sudo systemctl enable zfs.target
sudo systemctl start zfs.target
sudo systemctl enable zfs-import-cache
sudo systemctl start zfs-import-cache
sudo systemctl enable zfs-mount
sudo systemctl start zfs-mount
sudo systemctl enable zfs-import.target
sudo systemctl start zfs-import.target
sudo zfs set mountpoint=/mnt/pool-name pool-name