--- title: Maintaining a system build on ZFS slug: maintaining-a-system-build-on-zfs date: 2025-08-02 draft: false authors: - luc tags: - Alpine Linux - Gentoo Linux categories: - Maintenance --- 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: === "Alpine Linux" ``` shell-session sh# zfs snapshot rpool/root/alpine@previous ``` === "Gentoo Linux" ``` shell-session 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: === "Alpine Linux" ``` shell-session sh# apk upgrade sh# reboot ``` === "Gentoo Linux" ``` shell-session sh# emerge -auDU @world sh# reboot ``` If the system does not behave accordingly after reboot, one may `rollback` to the previous snapshot: === "Alpine Linux" ``` shell-session sh# zfs rollback -r rpool/root/alpine@previous ``` === "Gentoo Linux" ``` shell-session 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: ``` shell-session 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`: ``` shell-session sh# zpool scrub rpool ``` A `scrub` may take a while, its progress can be checked with: ``` shell-session sh# zpool status rpool ``` > A ZFS scrub only repairs if `mirror` or a `zraid` mode is set in the pool.