Skip to content

Maintaining a system build on ZFS

ZFS opens up novel methods to safely maintain a system. In this blog entry we will outline these methods in the form of an update protocol. To keep your system healthy this protocol should be executed on a weekly/monthly basis.

Pre-update

To be able to rollback the system after a system update, one may create a snapshot of the root filesystem:

sh# zfs snapshot rpool/root/alpine@previous
sh# zfs snapshot rpool/root/gentoo@previous

Furthermore, zfs list -t snapshot can be used to list snapshots and zfs destroy can be used to remove snapshots.

Update

We may perform a system update:

sh# apk upgrade
sh# reboot
sh# emerge -auDU @world
sh# reboot

If the system does not behave accordingly after reboot, one may rollback to the previous snapshot:

sh# zfs rollback -r rpool/root/alpine@previous
sh# zfs rollback -r rpool/root/gentoo@previous

Post-update

To maintain the performance of the SSDs in the system, perform a trim on the ZFS-pool:

sh# zpool trim --secure --wait rpool #(1)!
  1. Some devices may not support the option --secure.

A scrub on the ZFS-pool checks and repairs the data in the pool and is usually performed after a trim:

sh# zpool scrub rpool

A scrub may take a while, its progress can be checked with:

sh# zpool status rpool

A ZFS scrub only repairs if mirror or a zraid mode is set in the pool.