💾 Archived View for gmi.noulin.net › 2021-06-27-zfs-commands.gmi captured on 2022-04-29 at 12:20:10. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-03-01)

➡️ Next capture (2023-03-20)

-=-=-=-=-=-=-

ZFS commands

Feed

date: 2021-06-27 12:21:41

categories: linux

firstPublishDate: 2021-06-27 12:21:41

The commands on this page are my notes reading

FreeBSD handbook ZFS chapter

,

OpenZFS - Root on ZFS

and

ZFS Debian wiki

.

Read my other post for reasons to use ZFS

ZFS in Debian Bullseye

and

Setting up root on ZFS

for installing Debian 11 (bullseye) with ZFS.

Another resource is

the Arch Wiki about zfs

.

Concepts

pool - vdevs - disks
  `- datasets

Usage

Options:

man zfs
man zpool

zpool create poolName /dev/da0

zpool create poolName mirror /dev/ada1 /dev/ada2

zpool create poolName raidz /dev/da0 /dev/da1 /dev/da2

zfs create poolName/datasetName
zfs set compression=lz4 snapdir=visible poolName/datasetName
zfs set copies=2 compression=lz4 snapdir=visible poolName/datasetName

zfs create -p poolName/dataset1/dataset2/childName

zfs mount poolName/datasetName
zfs unmount poolName/datasetName

(all files have to be closed)

zfs mountpoint=/path poolName/datasetName

zfs destroy poolName/datasetName
delete snapshot
zfs destroy poolName/datasetName@snapshotName

zpool destory poolName

zfs snapshot poolName/datasetName@snapshotName

The snapshots are available in `dataset mount point`/.zfs/snapshot/

zfs snapshot -r poolName@snapshotName

zfs rollback poolName/datasetName@snapshotName

zpool status poolName
# show error details (file paths, errors in snapshots,...):
zpool status poolName -v
zpool status -x
all pools are healthy

zpool offline storage da1
zpool replace storage da1
zpool status storage

zpool scrub poolName

zpool attach >> adds disks to a vdev
zpool add    >> adds vdevs to a pool

zpool replace poolName /dev/ada1p3 /dev/ada2p3

zpool history
zpool history poolName

show more info, like snapshot events:

zpool history -i

long history:

zpool history -l

zpool iostat
zpool iostat -v

zfs list

zfs list -t snapshot

zfs list -t all

zfs list -rt all poolName/datasetName

zfs list -rt snapshot poolName/datasetName

zfs get used,compressratio,compression,logicalused poolName/datasetName

zfs get all poolName/datasetName

zfs rename poolName/datasetName poolName/newDatasetName

zfs rename poolName/datasetName@snapshotName newSnapshotName

diff snapshot to current

zfs diff poolName/datasetName@snapshotName

diff 2 snapshots

zfs diff poolName/datasetName@snapshotName poolName/datasetName@snapshotName2

get state:

zfs get snapdir poolName/datasetName
zfs set snapdir=visible poolName/datasetName

zfs clone poolName/datasetName@snapshotName poolName/newDatasetName

show original snapshot name:

zfs get origin poolName/newDatasetName

remove link with snapshot

zfs promote poolName/newDatasetName

Setup:
+ host:
zfs allow -u user send,snapshot zroot
+ remote:
sysctl vfs.usermount=1
echo vfs.usermount=1 >> /etc/sysctl.conf
zfs create zroot/backup
zfs allow -u user create,mount,receive zroot/backup
# or zfs allow -u receiver compression,mountpoint,mount,create,receive rxpool
chown user /zroot/backup
zfs create zroot/backup/compressed
zfs set compression=lz4 snapdir=visible zroot/backup/compressed

+ command:
zfs send -vp zroot/compressed@e | ssh user@172.16.43.235 zfs recv -Fdv zroot/backup
-v verbose
-p send dataset properties

receive:
-F Force a rollback of the file system to the most recent snapshot
-d Use the full sent snapshot path without the pool name to determine the name of the new snapshot
-v verbose

zfs send -vi zroot/compressed@oldSnapshot zroot/compressed@newSnapshot | ssh user@172.16.43.235 zfs recv -dvu zroot/backup
# zfs recv -Fdv also works

- send with ssh example
zfs snapshot zroot/compressed@initial
+ remote:
+ zfs create zroot/tank
+ zfs set compression=lz4 snapdir=visible zroot/tank
+ zfs allow -u user compression,mountpoint,mount,create,receive zroot/tank
+ chown user /zroot/tank
zfs send -v zroot/compressed@initial | ssh user@172.16.43.235 zfs recv -Fd zroot/tank
zfs snapshot zroot/compressed@evening
zfs send -vi initial zroot/compressed@evening | ssh user@172.16.43.235 zfs recv -Fd zroot/tank

zpool create \
    -o cachefile=/etc/zfs/zpool.cache \
    -o ashift=12 \
    -O acltype=posixacl -O snapdir=visible -O compression=lz4 \
    -O dnodesize=auto -O normalization=formD -O relatime=on \
    -O xattr=sa -O mountpoint=/home/data \
    sandisk /dev/disk/by-id/DISK-part1

hashtags: #zfs

Feed