box.matto.nl
Enjoying Open Source Software

Scrubbing ZFS pools automation on FreeBSD

FreeBSD offers a wonderful ZFS integration. For quite some time is has been possible to boot from ZFS pools and even from encrypted ZFS pools.

FreeBSD comes with a toolbox with everything you need to use ZFS.

FreeBSD together with ZFS is a great combination for the systems in your home network, for workstations like your laptop or PC, as well as for servers.

Combined with the FreeBSD bhyve hypervisor and the FreeBSD jail container technology, using ZFS really shines. The ZFS snapshot and clone methods allow for very fast deployment of virtual machines and jails.

Snapshots can be copied with the zfs send and zfs receive command pair, this can be locally and also over the network, sending a snapshot from one machine and receiving it another. This gives great flexibility and also a very reliable way to create remote backups.

Scrubbing

When you scrub a ZFS pool, the process traverses all the data in the pool once and verifies that all blocks can be read. This is a good way to check the data integrity and discover any problems before it is too late.

The process runs in the background, and usually you won't notice any performance effects.

To manually start the scrubbing process, simply apply the command

zpool scrub <pool-name>

like zpool scrub zroot.

This will start the scrubbing in the background.

The command zpool status will show the estimated time for the process to finish. When done, it will report any errors the scrubbing process brought to light.

Automated scrubbing

On FreeBSD it is easy to automate the start of a scrubbing process. For this we use the periodic scripts.

Simply add the following lines to /etc/periodic.conf:

daily_scrub_zfs_enable="YES"
daily_scrub_zfs_default_threshold="28"

With this, on the 28-st day after the previous scrub, a new scrub process will be started automatically.

If you want to get some insight in your inbox, also add the following line to /etc/periodic.conf:

daily_status_zfs_enable="YES"

This will daily send an email with information related to your ZFS pools. This email will be send to the `root' user. In the file /etc/aliases you can set the appropriate email address for this user, like:

root: myname@mydomain.com

or

root: myname@mydomain.com, my-othername@some-domain.com

Don't forget to run newaliases after any change of the /etc/aliases file.

The email will contain messages like:

Scrubbing of zfs pools:
   skipping scrubbing of pool 'zroot':
      last scrubbing is 20 days ago, threshold is set to 28 days

and you know you don't have to worry about this.

Have a joyful time with your FreeBSD systems!

Tags:

⇽ Blog Question Challenge 2025


Made with ♥ by a human
Proud member of the 250kb.club, the no-JS.club, and the Blogroll.Club.