ZFS – Good to know

## Links:https://ruvi-d.medium.com/zfs-on-ubuntu-20-04-lts-53728f3bc9e9
https://wiki.ubuntu.com/Kernel/Reference/ZFS
https://jrs-s.net/2016/09/15/zfs-snapshots-and-cold-storage/
https://didrocks.fr/2020/05/26/zfs-focus-on-ubuntu-20.04-lts-zsys-general-presentation/
https://wiki.archlinux.org/index.php/ZFS

## on Linux

install ZFS on Linux
> sudo apt install zfsutils-linux

## Commands:

### List the Pools
> zpool list

### Unmount Pool/Dataset
> zfs unmount <pool>/<dataset>

### Show parameters of pool
> zpool get all <pool>

### List the DataSets
> zfs list

### Create a Pool (easy/test)
> zpool create -f -o ashift=12 -O compression=lz4 <pool> /dev/xxx

Parameters:
– -f = forces use of vdevs, even if they appear in use….
– -n = dry run

### Create a Pool (advanced/production)
> zpool create -f -o ashift=12 -O compression=lz4 -O mountpoint=none \
-O normalization=formD <pool> /dev/xxx

Parameters (see https://wiki.alpinelinux.org/wiki/Root_on_ZFS_with_native_encryption):
– ashift=12 is recommended here because many drives today have 4KiB (or larger) physical sectors, even though they present 512B logical sectors
– mountpoint=none the unencrypted Root/Pool cannot be mounted.
– normalization=formD eliminates some corner cases relating to UTF-8 filename normalization. It also enables `utf8only=on`, meaning that only files with valid UTF-8 filenames will be accepted. (https://de.wikibooks.org/wiki/ZFS_auf_Linux/_ashift / https://de.wikibooks.org/wiki/ZFS_auf_Linux/_Initiale_Konfiguration)

Other Properties specified by -O (https://www.reddit.com/r/zfs/comments/cbn5qf/settings_for_new_zfs_pool/):
– relatime=on – see atime Options – Archlinux.org

### Create DataSet
> zfs create <pool>/<dataset>

### Create an encrypted DataSet
https://techgoat.net/index.php?id=174
https://wiki.archlinux.org/index.php/ZFS#Native_encryption

To create a encrypted dataset with a passphrase:
> zfs create -o encryption=on -o keyformat=passphrase <pool>/<dataset>

To create an encrypted dataset with keyfile:
> dd if=/dev/random of=/path/to/key bs=1 count=32
> zfs create -o encryption=on -o keyformat=raw -o keylocation=file:///path/to/key <pool>/<dataset>
Verify Key Location:
> zfs get keylocation <pool>/<dataset>
Change Key Location
> zfs get keylocation <pool>/<dataset>

Unmount and forget Key:
> zfs umount <pool>/<dataset>
> zfs unload-key <pool>/<dataset>

Mount and enter Password:
> zpool import <pool>/<dataset>
> zfs load-key <pool>/<dataset>
> zfs mount <pool>/<dataset>

### Create a test-file (10 MB)
> dd if=/dev/zero of=testfile.txt bs=1024 count=10240

### Create a snapshot
– There is a hidden folder -zfs in each DataSet, where these snapshots are stored.
> zfs snapshot <pool>/<dataset>@<snapshot>

### Show list of snapshots
> zfs list -rt snapshot
> zfs list -rt snapshot -o name,creation <pool>/<dataset>

### Rollback to Snapshot
> zfs rollback <pool>/<dataset>@<snapshot>

### Compare Snapshots
> zfs diff <pool>/<dataset>@<snap1> <pool>/<dataset>@<snap2>

### Delete Dataset (BE CAREFUL!!)
docs.oracle
> zfs destroy <pool>/<dataset>

### Monitor ZFS
> zpool status
> zpool iostat
> zpool list –o name,size,capacity

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.