Zfs usage

From wikinotes

Monitoring

zpool status           # lists devices, READ/WRITE/CHECKSUM errors, general health
zpool get all ${pool}  # list version (or feature flags, if version is 5000), attributes of pool
zfs list               # lists mountpoints by pool
zfs list -t snapshot   # lists snapshots

An additional set of resource management tools is provided by zfs-stats.

zfs-stats -M  # summary of memory usage

Create/Configure

# simulate zpool using file
dd if=/dev/zero of=/tmp/mypool bs=1M count=128
zpool create mypool /tmp/mypool
zpool destroy mypool

# create pool from mirrored disks
zpool create mypool mirror /dev/ada1 /dev/ada2  # create pool from mirrored disks

zfs create   -o compression=lz4  -o setuid=off   zroot/var/db/pkg        ## Create zfs filesystem and mountpoint
zfs destroy       /zroot/myfs                                            ## delete filesystem
zfs set quota=2G  /zroot/myfs                                            ## set a maximum size for a dataset

Mount

zfs mounts do not utilize fstab

Importing makes zpool a part of the current system (started at boot).
Importing is also the interface used to mount zpools and their contained filesystems
.

# list importable pools
zpool import

# import pool 'zroot' at it's configured mountpoint
# also, it will automatically be started at boot
zpool import zroot

# import pool with different root mountpoint
zpool import -o altroot=/mnt mypool

# some other useful params
zpool import \
  -N               `# import pool without mounting anything` \
  -o altroot=/mnt  `# change altroot (root-mountpoint)` \
  -R /mnt          `# temporarily use altroot (root-mountpoint)`

Snapshots

mount -t zfs zroot/media@2018-06-20__07:20  /mnt/snapshots

Snapshots

# =========
# snapshots
# =========
zfs snapshot zroot/home@friday                       # Create zfs snapshot of zroot/home called 'friday'
zfs list -t snapshots                                # list snapshots only
zfs destroy zroot/home@friday                        # delete snapshot 'friday'
zfs diff zroot/home@friday zroot/home@monday | less  # diff snapshot changes

# ==============
# mount snapshot
# ==============
mount -t zfs zroot/media@2018-06-20__07:20  /mnt/snapshots

zdb

zdb is the zfs debugger.

See zfs zdb.