Eric Radman : a Journal

ZFS Quickstart

ZFS is not only a full-featured file system, it is also handles volume discovery, RAID, and network access.

Some tutorials on using PostgreSQL with ZFS claim that consistency guarantees allow full_page_writes to be disabled since need to guard against torn pages. This technique is not tested or supported by PostgreSQL developers, and this parameter will lead to corruption if database is replicated to a non-ZFS volume.

Rocky/Alma Linux Install

dnf install https://zfsonlinux.org/epel/zfs-release-2-2.el9.noarch.rpm
dnf config-manager --disable zfs
dnf config-manager --enable zfs-kmod
dnf install zfs
echo zfs > /etc/modules-load.d/zfs.conf

See also OpenZFS RHEL install.

Limit ARC memory use if the system is running a memory intensive application such as a database

FreeBSD

# /etc/rc.conf
zfs_enable="YES"

Limit ARC memory use

# /etc/sysctl.conf
vfs.zfs.arc.max=1073741824

ZFS does not require a partition table, but initializing a disk with GUID partition map will avoid spurious warnings and make it clear what kind of file system is on a device

gpart destroy -F nvd1          # Delete partition data
gpart create -s gpt nvd1       # New GUID partition table
gpart add -t freebsd-zfs nvd1  # Create and label partition

Create zpool and new volume on first partition

zpool create -O compression=lz4 zpool2 /dev/nvd1p1
zfs create -o mountpoint=/ci zpool2/ci

Automated Snapshot Managment

To automate snapshot retention make a new periodic snapshot and prune anything that is more than N days old

#!/bin/sh -e

today=$(date +"%Y-%m-%d")

for fs in zpool2/ci; do
   zfs snapshot $fs@$today

   for snap in $(zfs list -t snapshot -H -o name $fs | sort -r | tail +30); do
      zfs destroy $snap
   done
done

Run daily

15  20  *  *  * /usr/local/bin/zfs-snap.sh

NFS Export

While any local mount can be added to /etc/exports ZFS sharing allows mount points to be automatically by setting the shrenfs property on each volume

$ zfs sharenfs='-ro,-network 192.168.2.0/24' zpool1
$ zfs get sharenfs
NAME       PROPERTY  VALUE                        SOURCE
zpool1     sharenfs  -ro,-network 192.168.2.0/24  local
zpool1/ci  sharenfs  -ro,-network 192.168.2.0/24  inherited from zpool1

Virtual Machines

When running KVM or Bhyave, ZFS can provide a device that can be attached to a virtual machine directly. This is referred to as a zvol

zfs create -sV 100G -o volmode=dev zpool2/vm/mykube2

Import all Pools After Reinstall

zpool import -a