Published : 2013-07-25

ZFS hot replace

ZFS can replace disks on the fly. This is useful to grow a ZFS pool, replace a faulty disk, or switch disk technology (e.g. move to SSDs or a different virtual I/O backend). This article assumes your server has a free slot (on a VM it’s straightforward, just add the disk while running). We insert a blank data disk of equal or greater capacity in that slot. It is recognized by the system in hotplug mode (SATA, SCSI, VirtIO…). To replace the disk, simply run:

zfs replace mypool ada2 /dev/ada3

You can of course switch disk technology (here migrating from an ATA disk to a VirtIO disk):

zfs replace mypool ada2 /dev/vtbd0

You can then check the recovery state with:

zpool status

If there is enough data, you will see the pool enter resilvering mode. That means ZFS is copying data from the first disk to the second. You now know how to replace a disk in a ZFS pool. In my case this allowed me to move from SATA in write-through mode to VirtIO disks in direct-sync mode, noticeably improving write performance.