stm / [WIP] ZFS commands

Last active 1 month ago

Like 0

Commands to create new ZFS pool and datasets on Linux

Revision 97878a74ae8776d060d94a6a45eb14a9c7e844c7

zfs.txt Raw
1# Notes
2#
3# ashift=12: 2^12 = 4KiB sectors, for certain NVMe drives use 13 (8KiB)
4# autotrim=on: TRIM for SSDs
5# encryption=on: Defaults to aes-256-gcm (since 0.8.4)
6# pbkdf2iters=1400000: PBKDF2-SHA1 iterations recommendation by OWASP, default is only 350000
7# dnodesize=auto: Is supposed to be used on systems running SAMBA with xattr=sa
8# compression=on: Defaults to lz4
9# normalization=formD: Decomposed Unicode normalization, implies utf8only=on, so UTF-8 filenames only
10# longname=on: Allows filenames up to 1023 bytes, default is off meaning 255 bytes (supported since 2.3.0)
11# primarycache: Defines what is cached in ARC, defaults to all (alternative settings: none, metadata)
12# secondarycache: Defines what is cached in L2ARC, defaults to all (alternative settings: none, metadata)
13# direct: Unset, defaulting to standard (since 2.3.0)
14# !!! recordsize: Unset, defaulting to 128KiB (important performance related setting!)
15#
16# Sources:
17# https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2
18# https://openzfs.github.io/openzfs-docs/Getting%20Started/Debian/Debian%20Trixie%20Root%20on%20ZFS.html#step-2-disk-formatting
19# https://openzfs.github.io/openzfs-docs/man/master/7/zfsprops.7.html#compression
20# https://openzfs.github.io/openzfs-docs/man/master/7/zfsprops.7.html#direct
21# https://openzfs.github.io/openzfs-docs/man/master/7/zfsprops.7.html#dnodesize
22# https://openzfs.github.io/openzfs-docs/man/master/7/zfsprops.7.html#longname
23# https://openzfs.github.io/openzfs-docs/man/master/7/zfsprops.7.html#pbkdf2iters
24#
25
26
27# RAIDZ2 pool creation
28#
29# -o (lowercase) is a _pool_ setting, -O (uppercase) is a _root dataset_ setting
30#
31zpool create \
32 -o ashift=12 \
33 -o autotrim=on \
34 -O encryption=on -O keylocation=prompt -O keyformat=passphrase \
35 -O pbkdf2iters=1400000 \
36 -O acltype=posixacl -O xattr=sa -O dnodesize=auto \
37 -O compression=on \
38 -O normalization=formD \
39 -O relatime=on \
40 -O longname=on \
41 -O canmount=off \
42 -O mountpoint=/mnt/$${POOL_NAME} ${POOL_NAME} \
43 raidz2 \
44 ${DISK1..N}
45
46
47# Dataset creation (benchmarking)
48#
49# To evaluate which recordsize is most suitable for a certain task we want to hit the raw disk as much as possible.
50# Modern OpenZFS versions already allow for direct IO (direct=standard by default), which mostly bypasses ARC/L2ARC.
51# In addition we tell ZFS to not hold actual file data in cache, only metadata.
52#
53zfs create \
54 -o canmount=off \
55 -o casesensitivity=insensitive \
56 -o primarycache=metadata \
57 -o secondarycache=metadata \
58 ${POOL_NAME}/recordsize-test
59zfs create -o recordsize=4K ${POOL_NAME}/recordsize-test/4K
60zfs create -o recordsize=8K ${POOL_NAME}/recordsize-test/8K
61zfs create -o recordsize=16K ${POOL_NAME}/recordsize-test/16K
62zfs create -o recordsize=32K ${POOL_NAME}/recordsize-test/32K
63zfs create -o recordsize=64K ${POOL_NAME}/recordsize-test/64K
64zfs create -o recordsize=128K ${POOL_NAME}/recordsize-test/128K
65zfs create -o recordsize=256K ${POOL_NAME}/recordsize-test/256K
66zfs create -o recordsize=512K ${POOL_NAME}/recordsize-test/512K
67zfs create -o recordsize=1M ${POOL_NAME}/recordsize-test/1M
68zfs create -o recordsize=2M ${POOL_NAME}/recordsize-test/2M
69zfs create -o recordsize=4M ${POOL_NAME}/recordsize-test/4M
70
71
72# Dataset creation (media, file server)
73#
74# casesensitivity=insensitive: Can speed up SAMBA sorting due to SAMBA being case-insensitive as well
75# recordsize=XXX Bigger recordsize can yield higher compression rations (if data is suitable; video files aren't)
76#
77TODO
78
79
80# Dataset creation (databases)
81#
82# Common database solutions use 4K (SQLite), 8K (PostgreSQL) or 16KB (MariaDB InnoDB) page sizes.
83# Adjusting recordsize to these workloads reduces write amplification and improves random IO.
84# Databases usually implement some form of caching themselves, so consider disabling ARC/L2ARC file caching.
85#
86TODO
87