When ZFS scrub reports permanent errors in files, you can use several approaches to find the exact offset of the corruption. Here's how to do it:
Using zdb to find error offsets
First, get the object ID of the affected file. If the scrub output shows a file path, you can find its object ID:
# Get the object number from the file path
zdb -O poolname/dataset /path/to/affected/file
Once you have the object ID, you can examine the file's block pointers:
# Examine the object's details including block pointers
zdb -ddddd poolname/dataset objectID
This will show you the DVAs (Data Virtual Addresses) and block pointers for the file. Look for blocks marked with errors or cksum failures.
Using zpool status -v for detailed error information
For more detailed error information:
zpool status -v poolname
This will show errors with their transaction group (txg) numbers and sometimes block information.
Finding the exact byte offset
To correlate block errors to byte offsets in the file:
- Use
zdb to examine the indirect blocks:
zdb -R poolname:vdev:offset:size:flags
- Calculate the file offset based on the block pointer level and block size. For a file using 128K blocks:
- Level 0 blocks: offset = block_number × 128K
- Level 1 blocks: each points to multiple Level 0 blocks
- And so on for higher levels
Alternative approach using zinject
If you want to verify the exact location, you can use zinject to list injection records which sometimes contain offset information:
zinject -l
Practical example to find corruption offset
Here's a practical workflow:
# 1. Get detailed object information
zdb -O poolname/dataset /corrupted/file
# 2. Note the object number (e.g., 12345)
# 3. Examine object with verbosity
zdb -ddddd poolname/dataset 12345
# 4. Look for blocks with cksum errors in the output
# You'll see something like:
# L0 DVA[0]=<0:1a2b3c4d:20000> [L0 ZFS plain file] cksum=XXX (error)
# 5. The offset in the file would be:
# block_number × recordsize (usually 128K)
For files with errors, the output will indicate which blocks failed checksum verification, and you can calculate the byte offset based on the block number and the file's recordsize property.
If you need to examine the raw data at a specific offset, you can also use zdb -R to read raw blocks from the pool and examine them directly.