agentleFS
ryanmacleanryanmaclean/skills/zfs/SKILL.md

zfs

Skill1 starsChanged 2 months agoMITView on GitHub

ZFS (OpenZFS) space efficiency and snapshotting for FreeBSD and Linux developers. Use when cloning datasets, creating build sandboxes, replicating storage, or writing Rust/C code that works with ZFS pools on macOS, FreeBSD, or Linux. Trigger phrases: "zfs snapshot", "zfs clone", "COW dataset", "zpool", "send/receive", "zfs dedup", "OpenZFS", "FreeBSD storage", "build rollback on ZFS". Covers: clone, snapshot, send/receive, dedup, Rust patterns, FreeBSD vs Linux differences.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Only worth enabling when data has high block-level duplication (VM images, backups).

    line 124
  2. Distinctive:

    NOT recommended for source code or build artifacts — too much RAM, little gain.

    line 125
  3. Very specific:

    Use the zfs-sys crate if it exists for your OpenZFS version, otherwise shell out.

    line 159
  4. Distinctive:

    Always enable compression on the pool or root dataset after creation:

    line 205

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

ZFS — OpenZFS Reference

ZFS is the COW filesystem for FreeBSD (first-class, ships by default since FreeBSD 13) and available on Linux via OpenZFS (Ubuntu, Debian, Arch). Commands are identical across platforms — pool naming and device paths differ.


The core rule

On ZFS, the unit of COW cloning is a dataset (filesystem or volume), not a file. To clone a directory tree: snapshot the dataset, then clone the snapshot.

zfs snapshot pool/dataset@tag
zfs clone pool/dataset@tag pool/dataset-clone

Clone is instant, zero space until divergence. This is the ZFS equivalent of cp -c on APFS.


Quick reference

OperationCommandNotes
Create snapshotzfs snapshot pool/ds@nameInstant, space = changed blocks only
List snapshotszfs list -t snapshot
Clone snapshotzfs clone pool/ds@snap pool/ds-cloneCOW — zero space at creation
Rollbackzfs rollback pool/ds@snapDestroys data after snapshot
Destroy clone/snapzfs destroy pool/ds@snapClone must be destroyed first
Send (backup)zfs send pool/ds@snap | zfs receive backup/dsStream to remote or file
Incremental sendzfs send -i pool/ds@prev pool/ds@now | zfs receive backup/dsDelta only
Space usagezfs list -o name,used,avail,refer
Enable dedupzfs set dedup=on pool/dsBlock-level; RAM-intensive
Enable compressionzfs set compression=lz4 pool/dsAlmost always worth enabling

Snapshots for build isolation

# Before a risky migration
zfs snapshot pool/src@pre-migration-2026-03-07

# Something went wrong — roll back
zfs rollback pool/src@pre-migration-2026-03-07

# Done — clean up
zfs destroy pool/src@pre-migration-2026-03-07

Snapshots consume space proportional to blocks changed after the snapshot, not the full dataset.


Dataset clones for test environments

# Snapshot the production dataset
zfs snapshot pool/prod@test-base

# Create a clone — writable, COW, instant
zfs clone pool/prod@test-base pool/test

# Use pool/test — all writes go to clone, prod is untouched

# Destroy when done (must destroy clone before its origin snapshot)
zfs destroy pool/test
zfs destroy pool/prod@test-base

Send/receive — replication

# Full send to remote
zfs send pool/ds@snap | ssh user@remote zfs receive backup/ds

# Incremental (only changed blocks since @prev)
zfs send -i pool/ds@prev pool/ds@now | ssh user@remote zfs receive -F backup/ds

# Send to a file
zfs send pool/ds@snap | gzip > ds-backup.gz
zfs send pool/ds@snap > ds-backup.zfs  # raw, faster to restore

# Restore
zfs receive pool/ds < ds-backup.zfs

Compression — always enable

zfs set compression=lz4 pool/dataset   # fast, good ratio — default choice
zfs set compression=zstd pool/dataset  # better ratio, slower — good for cold data

LZ4 compression typically saves 30–50% on source code and logs with near-zero CPU cost. Enable at dataset creation; only new writes are compressed.


Dedup — use carefully

zfs set dedup=on pool/dataset

Block-level deduplication. Requires ~5GB RAM per TB of data for the dedup table. Only worth enabling when data has high block-level duplication (VM images, backups). NOT recommended for source code or build artifacts — too much RAM, little gain.


Rust patterns

ZFS has no stable clonefile()-style syscall for userspace. Options:

1. Shell out (simplest, recommended for most cases):

use std::process::Command;

fn zfs_snapshot(dataset: &str, tag: &str) -> std::io::Result<()> {
    let status = Command::new("zfs")
        .args(["snapshot", &format!("{dataset}@{tag}")])
        .status()?;
    if status.success() { Ok(()) } else {
        Err(std::io::Error::other("zfs snapshot failed"))
    }
}

fn zfs_clone(origin: &str, tag: &str, clone: &str) -> std::io::Result<()> {
    let snap = format!("{origin}@{tag}");
    let status = Command::new("zfs")
        .args(["clone", &snap, clone])
        .status()?;
    if status.success() { Ok(()) } else {
        Err(std::io::Error::other("zfs clone failed"))
    }
}

2. libzfs FFI (advanced, avoids process overhead): libzfs is available on FreeBSD and Linux but has no stable API — version-specific. Use the zfs-sys crate if it exists for your OpenZFS version, otherwise shell out.


FreeBSD vs Linux differences

AspectFreeBSDLinux (OpenZFS)
Pool device naming/dev/ada0, /dev/da0, /dev/gpt/label/dev/sda, /dev/nvme0n1
Import on bootAutomatic via /etc/rc.conf: zfs_enable="YES"zpool import -a in initrd or systemd unit
Default pool namezroot (installer default)rpool (Ubuntu default)
ARC (cache) tuningvfs.zfs.arc_max in /boot/loader.confzfs_arc_max in /etc/modprobe.d/zfs.conf
Encrypted rootNative ZFS encryption or GELI (FreeBSD)Native ZFS encryption or LUKS
zpool statusIdenticalIdentical
zfs commandsIdenticalIdentical

Space audit commands

zpool list                          # pool-level free/used
zfs list -o name,used,avail,refer   # dataset breakdown
zfs list -t snapshot                # all snapshots and their sizes
zpool iostat -v                     # I/O per vdev
zdb -b pool/dataset                 # block-level stats (verbose)

Pools — bare minimum setup

# Single disk pool (development only — no redundancy)
zpool create mypool /dev/ada1

# Mirror (RAID-1 equivalent)
zpool create mypool mirror /dev/ada1 /dev/ada2

# Status
zpool status mypool

# Destroy (irreversible)
zpool destroy mypool

Always enable compression on the pool or root dataset after creation:

zfs set compression=lz4 mypool

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.