ZFS
- zpool — configure ZFS storage pools
- zpool-status — Display detailed health status for the given ZFS storage pools
- zpool-list — Lists ZFS storage pools along with a health status and space usage
- zpool-create — Creates a new ZFS storage poolzpool-destroy — Destroys the given ZFS storage pool, freeing up any devices for other use
- zpool-import — Lists ZFS storage pools available to import or import the specified pools
- zpool-export — Exports the given ZFS storage pools from the system
- zpool-get — Retrieves properties for the specified ZFS storage pool(s)
- zpool-set— Sets the given property on the specified pool
- zfs — configures ZFS file systems
- zdb — display zpool debugging and consistency information
- zfs-auto-snapshot – take regular ZFS snapshots
- Documentation
- Installation
- Misc
- Random
zpool — configure ZFS storage pools
The zpool command configures ZFS storage pools. A storage pool is a collection of devices that provides physical storage and data replication for ZFS datasets. All datasets within a storage pool share the same space.
Virtual Devices (vdevs): A “virtual device” describes a single device or a collection of devices organized according to certain performance and fault characteristics.
zpool-status
— Display detailed health status for the given ZFS storage pools
zpool status
(also shows if a scrub is in progress)
zpool-list
— Lists ZFS storage pools along with a health status and space usage
zpool list
zpool list -v
zpool-create
— Creates a new ZFS storage pool
zpool-destroy
— Destroys the given ZFS storage pool, freeing up any devices for other use
zpool create SAN200 /dev/mapper/mpathl /dev/mapper/mpathk /dev/mapper/mpathm /dev/mapper/mpathn
zpool create -o ashift=12 storage raidz1 /dev/sda /dev/sdb
zpool destroy SAN200
zpool-import
— Lists ZFS storage pools available to import or import the specified pools
zpool-export
— Exports the given ZFS storage pools from the system
Rename a zpool:
zpool export [poolname]
zpool import [poolname] [newpoolname]
zpool-get
— Retrieves properties for the specified ZFS storage pool(s)
zpool-set
— Sets the given property on the specified pool
https://openzfs.github.io/openzfs-docs/man/5/zpool-features.5.html
zpool get all tank
zpool get size tank
zpool get feature@large_dnode tank
zfs — configures ZFS file systems
zfs list
-H | Used for scripting mode. Do not print headers and separate fields by a single tab instead of arbitrary white space. |
-o property | A comma-separated list of properties to display. |
-r | Recursively display any children of the dataset on the command line. |
-s property | A property for sorting the output by column in ascending order based on the value of the property. |
-t type | A comma-separated list of types to display, where type is one of filesystem, snapshot, volume, bookmark, or all. |
zfs list
zfs list -t volume
zfs list -t snapshot
zfs list -t snapshot tank/dataset
zfs list -r -t snapshot tank/dataset
zfs list -H -r -t snapshot -o name
zfs clone
zfs clone [-p] [-o property=value]… snapshot filesystem|volume
Creates a clone of the given snapshot. See the Clones section for details. The target dataset can be located anywhere in the ZFS hierarchy, and is created as the same type as the original.
zfs clone tank/dataset@morning tank/dataset_morning
zfs create/destroy
zfs create -p tank/backup/test
-p Creates all the non-existing parent datasets.
zfs destroy -r SAN200/backup
-r Destroy (or mark for deferred deletion) all snapshots with this name in descendent file systems.
zfs get/set
https://openzfs.github.io/openzfs-docs/man/7/zfsprops.7.html
acltype=off|nfsv4|posix | Controls whether ACLs are enabled and if so what type of ACL to use. |
atime=on|off | Controls whether the access time for files is updated when they are read. |
compression=on|off|gzip|gzip-N|lz4|lzjb|zle|zstd|zstd-N|zstd-fast|zstd-fast-N | Controls the compression algorithm used for this dataset. When set to on (the default), indicates that the current default compression algorithm should be used. |
dnodesize=legacy|auto|1k|2k|4k|8k|16k | Specifies a compatibility mode or literal value for the size of dnodes in the file system. The default value is legacy. Setting this property to a value other than legacy requires the large_dnode pool feature to be enabled. |
recordsize=size | Specifies a suggested block size for files in the file system. This property is designed solely for use with database workloads that access files in fixed-size records. ZFS automatically tunes block sizes according to internal algorithms optimized for typical access patterns. |
relatime=on|off | Controls the manner in which the access time is updated when atime=on is set. |
sharesmb=on|off|opts | Controls whether the file system is shared by using Samba USERSHARES and what options are to be used. |
sharenfs=on|off|opts | Controls whether the file system is shared via NFS, and what options are to be used. A file system with a sharenfs property of off is managed with the exportfs(8) command and entries in the /etc/exports file. |
xattr=on|off|sa | Controls whether extended attributes are enabled for this file system. |
zfs get compression
zfs set compression=lz4 SAN200
zfs set compression=on pool/home/anne
zfs set compression=lz4 pool/home/anne
zfs get all pool/home/bob
zfs get xattr,compression,atime,recordsize,acltype,dnodesize, localZFS
zfs get compression,xattr,acltype,dnodesize,atime tank/smbtest
zfs set compression=lz4 xattr=sa acltype=posixacl dnodesize=auto atime=on tank/smbtest
zfs get xattr,compression,atime,relatime,recordsize,acltype,dnodesize, localZFS
zfs set xattr=sa compression=lz4 atime=off relatime=on recordsize=1M acltype=posixacl dnodesize=auto localZFS
zfs get mountpoint storage/music
zfs set mountpoint=/home/bob/Music storage/music
sharenfs
zfs set sharenfs="rw=@192.168.0.0/24,rw=@10.0.0.0/24" pool-name/dataset-name
https://blog.programster.org/sharing-zfs-datasets-via-nfs
zfs rename
-f | Force unmount any filesystems that need to be unmounted in the process. |
-p | Creates all the nonexistent parent datasets. |
-r (snapshots) | Recursively rename the snapshots of all descendant datasets. |
zfs rename -p tank/projects tank/data/projects
zfs snapshot
Create snapshot
(must be filesystem@snapname
or volume@snapname
)
zfs snapshot tank/backup/projects@version1
zfs destroy tank/backup@zfs-auto-snap_frequent-2021-04-23-1900
zfs list -t snapshot -o name | grep ^BACKUP/projects@zfs-auto-snap_frequent | xargs -n 1 zfs destroy
zfs list -r -t snapshot tank
Remove all modifications since snapshot
zfs rollback tank/backup/test@zfs-auto-snap_removeme-2021-04-30-1637
Look into the snapshots
The info is available at the root of the dataset in .zfs/snapshots
zfs send/receive
zfs send [-DLPRbcehnpvw] [[-I|-i] snapshot] snapshot
zfs send [-LPcenvw] [-i snapshot|bookmark] filesystem|volume|snapshot
-I snapshot | Generate a stream package that sends all intermediary snapshots from the first snapshot to the second snapshot. |
-R, –replicate | Generate a replication stream package, which will replicate the specified file system, and all descendent file systems, up to the named snapshot. |
zfs receive [-Fhnsuv] [-o origin=snapshot] [-o property=value] [-x property] filesystem|volume|snapshot
zfs receive [-Fhnsuv] [-d|-e] [-o origin=snapshot] [-o property=value] [-x property] filesystem
-F | Force a rollback of the file system to the most recent snapshot before performing the receive operation. |
first time:
zfs send tank/backup/projects@zfs-auto-snap_daily-2021-04-24-0425 | zfs recv SAN200/backup/projects
after that:
zfs send -R -I @zfs-auto-snap_daily-2021-04-24-0425 tank/backup/projects@zfs-auto-snap_daily-2021-04-25-0425 | zfs receive -F SAN200/backup/projects
zfs share/unshare
zfs get sharesmb tank/smbtest
zfs hold/holds
cannot destroy snapshot [snapshot] : dataset is busy
z$ zfs holds [snapshot]
NAME TAG TIMESTAMP
[snapshot] .send-2964719-1 Mon Mar 14 15:17 2022
zfs share -a | filesystem
zfs unshare -a | filesystem|mountpoint
zdb — display zpool debugging and consistency information
-l device : Read the vdev labels from the specified device (obtained with zpool list -v
)
# zdb -l mpathp
-C : Display information about the configuration
# zdb -C tank
-d : Display information about datasets
# zdb -d tank/backup
zfs-auto-snapshot – take regular ZFS snapshots
/sbin/zfs-auto-snapshot -q -g --label=hourly --keep=24 tank/backup/projects
Helper script to run after zfs-auto-snapshot (note that the –keep switch takes affect after the –post-snapshot):
#!/bin/sh
#echo "dataset = $1"
#echo "snapname = $2"
latest_synced_snapname=`zfs list -H -o name -S creation -t snapshot SAN200/test | head -1 | sed 's/.*\(@.*\)/\1/'`
zfs send -R -I "$latest_synced_snapname" "$1@$2" | zfs receive -F SAN200/test
Documentation
https://openzfs.github.io/openzfs-docs/Performance%20and%20Tuning/index.html
https://openzfs.github.io/openzfs-docs/man/8/index.html
https://wiki.archlinux.org/title/ZFS
Installation
sudo apt install zfsutils-linux
Misc
zfs tuning: https://jrs-s.net/2018/08/17/zfs-tuning-cheat-sheet/
advanced format drives: https://wiki.lustre.org/Optimizing_Performance_of_SSDs_and_Advanced_Format_Drives
official FAQ: https://openzfs.github.io/openzfs-docs/Project%20and%20Community/FAQ.html
Record size: https://blog.programster.org/zfs-record-size
Root on ZFS: https://openzfs.github.io/openzfs-docs/Getting%20Started/Ubuntu/Ubuntu%2020.04%20Root%20on%20ZFS.html
Cheat sheet: https://www.thegeekdiary.com/solaris-zfs-command-line-reference-cheat-sheet/
System administration: https://openzfs.org/wiki/System_Administration
Random
$ more /etc/cron.hourly/zfs-auto-snapshot
#!/bin/sh
# Only call zfs-auto-snapshot if it's available
which zfs-auto-snapshot > /dev/null || exit 0
exec zfs-auto-snapshot --quiet --syslog --label=hourly --keep=24 --recursive --post-snapshot=/home/technician/zfs/myscript SAN300/projects
#exec zfs-auto-snapshot --quiet --syslog --label=hourly --keep=24 --recursive SAN300/projects
$ more /home/technician/zfs/myscript
#!/bin/sh
#echo "dataset = $1"
#echo "snapname = $2"
zfs create -p BACKUP/$1
latest_synced_snapname=`zfs list -H -o name -S creation -t snapshot BACKUP/$1 | head -1 | sed 's/.*\(@.*\)/\1/'`
if [ -z "$latest_synced_snapname" ]
then
zfs send -R "$1@$2" | zfs receive -F BACKUP/$1
else
zfs send -R -I "$latest_synced_snapname" "$1@$2" | zfs receive -F BACKUP/$1
fi
#zfs list -t snapshot -o name | grep ^BACKUP/$1@zfs-auto-snap_frequent | xargs -n 1 zfs destroy
return 0