What does zfs scrub do

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 4, 2026

Quick Answer: A ZFS scrub is a process that reads all data on a ZFS storage pool and verifies its integrity against its checksums. If any data corruption is detected, ZFS automatically attempts to repair it using redundant data from other copies or parity information.

Key Facts

What is ZFS Scrub?

ZFS (Zettabyte File System) is an advanced file system and logical volume manager known for its data integrity features. One of the most critical features for maintaining data integrity is the 'scrub' operation. A ZFS scrub is a background process that systematically reads every block of data and metadata stored within a ZFS pool. During this read operation, ZFS recalculates the checksum for each block and compares it to the checksum that was previously stored with the data. This comparison is the core of how ZFS detects silent data corruption, which can occur due to various reasons like hardware failures (e.g., bad sectors on a drive), cosmic rays, or firmware bugs.

Why is Scrubbing Important?

The primary purpose of a ZFS scrub is to ensure the integrity and reliability of your stored data. Unlike traditional file systems that might not detect data corruption until the corrupted file is accessed, ZFS actively checks for errors. This proactive approach means that potential issues can be identified and, in many cases, resolved before they lead to data loss or system instability. Without regular scrubbing, silent corruption could go unnoticed, gradually degrading the data over time. When ZFS detects a checksum mismatch during a scrub, it indicates that the data block has been corrupted. If the pool is configured with redundancy (e.g., mirroring or RAID-Z), ZFS will then attempt to retrieve a good copy of the data from another drive or reconstruct it using parity information. This self-healing capability is a cornerstone of ZFS's robustness.

How Does ZFS Scrub Work?

The scrub process involves several key steps. First, ZFS traverses the entire file system tree, accessing every file and directory. For each data block encountered, it reads the block from the storage device. It then recalculates the checksum for this block using a specified hashing algorithm (e.g., SHA-256, Fletcher4). This newly calculated checksum is compared against the checksum that ZFS stored alongside the data when it was originally written or last verified. If the checksums match, the data block is considered intact. If they do not match, ZFS flags the block as corrupted. At this point, ZFS consults its metadata to determine if there are other copies of the data block available (in a mirrored configuration) or if it can be reconstructed from parity data (in a RAID-Z configuration). If a valid copy or reconstruction is possible, ZFS writes the corrected data back to the disk and updates the checksum. If the pool lacks redundancy and corruption is detected, ZFS cannot automatically repair the data, and the corrupted block will remain flagged. The scrub process provides a report upon completion, detailing the number of blocks read, the time taken, and importantly, the number of corrupted blocks detected and, if applicable, repaired.

When Should You Scrub?

The frequency of ZFS scrubs is a crucial factor in maintaining data integrity. While ZFS is designed to detect errors, these checks are only performed when a scrub is initiated. It is generally recommended to perform a scrub at least once a month. For critical systems or environments with a high volume of data changes, more frequent scrubs (e.g., weekly) might be advisable. Many ZFS administrators schedule scrubs to run automatically during off-peak hours to minimize any potential impact on system performance. The duration of a scrub depends on several factors, including the total amount of data in the pool, the speed of the storage devices, the system's I/O capabilities, and the complexity of the ZFS configuration (e.g., RAID-Z levels). A full scrub of a large pool can take many hours, or even days, to complete.

Initiating and Monitoring a Scrub

You can initiate a scrub manually from the command line using the command `zpool scrub `. To check the status of an ongoing scrub or the last scrub's results, you can use the command `zpool status `. This command provides detailed information about the pool's health, including any ongoing operations, detected errors, and the results of the last scrub. It's good practice to review the output of `zpool status` regularly to stay informed about your pool's condition.

In summary, ZFS scrub is an essential maintenance task that actively verifies and repairs data, safeguarding against silent corruption and ensuring the long-term reliability of your storage pool. Regular scrubs are a fundamental part of leveraging ZFS's powerful data integrity features.

Sources

  1. ZFS - WikipediaCC-BY-SA-4.0
  2. Scrub in ZFS - OpenZFS Documentationfair-use

Missing an answer?

Suggest a question and we'll generate an answer for it.