ZFS command line examples

ZFS is a combined file system and logical volume manager designed by Sun Microsystems. The features of ZFS include protection against data corruption, support for high storage capacities, efficient data compression, integration of the concepts of filesystem and volume management, snapshots and copy-on-write clones, continuous integrity checking and automatic repair, RAID-Z and native NFSv4 ACLs.

Below is a quick reference for ZFS command line examples

CREATE / DESTROY POOL

  • Remove a disk from a pool
    # zpool detach prod c0t0d0
  • Delete a pool and all associated file systems
    # zpool destroy prod
  • Create a pool named prod
    # zpool create prod c0t0d0
  • Create a pool with a different default mount point
    # zpool create -m /app/db prod c0t0d0

CREATE RAID-Z / MIRROR

  • Create RAID-Z vdev / pool
    # zpool create raid-pool-1 raidz c3t0d0 c3t1d0 c3t2d0
  • Add RAID-Z vdev to pool raid-pool-1
    # zpool add raid-pool-1 raidz c4t0d0 c4t1d0 c4t2d0
  • Create a RAID-Z1 Storage Pool
    # zpool create raid-pool-1 raidz1 c0t0d0 c0t1d0 c0t2d0 c0t3d0 c0t4d0 c0t5d0
  • Create a RAID-Z2 Storage Pool
    # zpool create raid-pool-1 raidz2 c0t0d0 c0t1d0 c0t2d0 c0t3d0 c0t4d0 c0t5d0
  • Add a new mirrored vdev to a pool
    # zpool add prod mirror c3t0d0 c3t1d0
  • Force the creation of a mirror and concat
    # zpool create -f prod c3t0d0 mirror c4t1d0 c5t2d0
  • Force the creation of a mirror between two different sized disks
    # zpool create -f mypool mirror c2t0d0 c4t0d0
  • diska is mirrored to diskb
    # zpool create mypool mirror diska diskb
  • diska is mirrored to diskb AND diskc is mirrored to diskd
    # zpool create mypool mirror diska diskb mirror diskc diskd

CREATE / DESTROY A FILESYSTEM AND/OR A BLOCKDEVICE

  • Create a filesystem named db in pool prod
    # zfs create prod/db
  • Create a 5gb block device volume named db in pool prod
    # zfs create -V 5gb prod/db
  • Destroy the filesystem or block device db and associated snapshot(s)
    # zfs destroy -fr prod/db
  • Destroy all datasets in pool prod
    # zfs destroy -r prod

MOUNT / UMOUNT ZFS

  • Set the FS mount point to /app/db
    # zfs set mountpoint=/app/db prod/db
  • Mount zfs oracle in pool prod
    # zfs mount prod/db
  • Mount all zfs file systems
    # zfs mount -a
  • Unmounting all zfs file systems
    # zfs umount a
  • Unmount zfs filesystem prod/db
    # zfs umount prod/db

LIST ZFS FILESYSTEM INFORMATION

  • List all zfs file systems
    # zfs list
  • Listing all properties and settings for a FS
    # zfs list -o all
    # zfs get all mypool

LIST ZFS POOL INFORMATION

  • List pool status
    # zpool status -x
  • List individual pool status mypool in detail
    # zpool status -v mypool
  • Listing storage pools brief
    # zpool list
  • Listing name and size
    # zpool list -o name,size
  • Listing without headers / columns
    # zpool list -Ho name

SET ZFS FILESYSTEM PROPERTIES

  • Set a quota on the disk space available to user guest22
    # zfs set quota=10G mypool/home/guest22
  • How to set aside a specific amount of space for a file system
    # zfs set reservation=10G mypool/prod/test
  • Enable mounting of a file system only through /etc/vfstab
    # zfs set mountpoint=legacy mypool/db
    and then add appropriate entries to /etc/vfstab
  • NFS share /prod/export/share
    # zfs set sharenfs=on prod/export/share
  • Disable execution of files on /prod/export
    # zfs set exec=off prod/export
  • Set the recordsize to 8k
    # zfs set recordsize=8k prod/db
  • Do not update the file access time record
    # zfs set atime=off prod/db/datafiles
  • Enable data compression
    # zfs set compression=on prod/db
  • Enable fletcher4 type checksum
    # zfs set checksum=fletcher4 prod/data
  • Remove the .snapshot directory visibility from the file system
    # zfs set snapdir=hidden prod/data

ANALYSE ZFS PERFORMANCE

  • Display zfs IO statistics every 2 seconds
    # zpool iostat 2
  • Display #zfs IO statistics in detail every 2 seconds
    # zpool iostat -v 2

ZFS FILESYSTEM MAINTENANCE

  • Scrub all file systems in pool mypool
    # zpool scrub mypool
  • Temporarily offline a disk (until the next reboot)
    # zpool offline -t mypool c0t0d0
  • Clear error count by onlining a disk
    # zpool online
  • Clear error count (without the need to online a disk)
    # zpool clear

IMPORT / EXPORT POOLS AND FILESYSTEMS

  • List pools available for import
    # zpool import
  • Imports all pools found in the search directories
    # zpool import -access
  • To search for pools with block devices not located in /dev/dsk
    # zpool import -d
  • Search for a pool with block devices created in /zfs
    # zpool import -d /zfs prod/data
  • Import a pool originally named mypool under new name temp
    # zpool import mypool temp
  • Import pool using pool ID
    # zpool import 6789123456
  • Deport a ZFS pool named mypool
    # zpool export mypool
  • Force the unmount and deport of a ZFS pool mypool
    # zpool export -f mypool

CREATE / DESTROY SNAPSHOTS

  • Create a snapshot named test of the db file system
    # zfs snapshot mypool/db@test
  • List snapshots
    # zfs list -t snapshot
  • Roll back to Tues (recursively destroy intermediate snaps)
    # zfs rollback -r prod/prod@tuesday
  • Roll back must and force unmount and remount
    # zfs rollback -rf prod/prod@tuesday
  • Destroy snapshot created earlier
    # zfs destroy mypool/db@test

CREATE / DESTROY CLONES

  • Create a snapshot and then clone that snap
    # zfs snapshot prod/prod@12-11-06
    # zfs clone prod/prod@12-11-06 prod/prod/clone
  • Destroy clone
    # zfs destroy prod/prod/clone