Some useful ZFS commands on Ubuntu

Table of Contents
About ZFS #
ZFS (Zettabyte File System) is an advanced file system and logical volume manager initially developed by Sun Microsystems, now part of Oracle. Known for its robust data integrity, ZFS combines the functions of a file system with a volume manager, making it highly scalable and reliable. Key features include support for high storage capacities, data integrity verification through checksums, native RAID configurations, snapshots, and copy-on-write cloning. It is much easier to use than e.g. Linux LVM with ext4.
ZFS Commands #
Create ZFS Mirror #
To create a mirrored ZFS pool, follow these steps:
- Identify Drives: Check which drives you want to mirror by listing available drives with lsblk or fdisk -l.
- Create Pool: Use the zpool create command with the mirror option. For example:
$ zpool create mypool mirror /dev/disk/by-id/ata-WDC_WD100EDGZ-11B2DA0_12345678 \
/dev/disk/by-id/ata-WDC_WD100EDGZ-11B2DA0_87654321
Verify Pool: Check the pool status with:
$ zpool status mypool
Replace failed hard disk #
To replace a disk that failed within a ZFS mirror, just find the ID of the failed/removed/missing device.
$ zdb
Replace failed/removed/missing device with ID with the NEW device name. For example:
# zpool replace -f <zpool> <old id> <new device>
$ zpool replace -f mypool 15xxxxxxxxxxxxx7313 /dev/disk/by-id/ata-WDC_WD100EMAZ-11BLFA0_12345678
Check with the zpool status command that resilvering starts:
$ zpool status mypool
pool: mypool
state: DEGRADED
status: One or more devices is currently being resilvered. The pool will
continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
scan: resilver in progress since Tue Oct 29 12:38:51 2019
32.4G scanned at 510M/s, 0B issued at 0B/s, 6.71T total
0B resilvered, 0.00% done, no estimated completion time
config:
NAME STATE READ WRITE CKSUM
mypool DEGRADED 0 0 0
mirror-0 DEGRADED 0 0 0
ata-WDC_WD120EMAZ-11BLFA0_12345678 ONLINE 0 0 0
replacing-1 DEGRADED 0 0 0
176xxxxxxxxxxxxx176 UNAVAIL 0 0 0 was /dev/disk/by-id/ata-ST8000VN0022-2EL112_12345678-part1
ata-WDC_WD120EMAZ-11BLFA0_87654321 ONLINE 0 0 0
Auto expand ZFS mirror #
If you have replaced your ZFS mirror with bigger disks, you need to adjust the pool size to it. Just set the parameter “autoexpand=on” for you zfs pool.
$ zpool set autoexpand=on mypool
Example:
$ zpool list
NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT
mypool0 7.25T 6.71T 552G - 3.62T 8% 92% 1.00x DEGRADED -