blkrawverify - Linux


Overview

blkrawverify is a utility used to verify raw block devices (e.g., hard drives, SSDs) by comparing their data against a reference image. It’s particularly useful for detecting data corruption or verifying the integrity of cloned or migrated storage devices.

Syntax

blkrawverify [options] <reference> <device>

Options/Flags

  • -c, –chunk-size: Set the chunk size (in bytes) for data transfer and verification. Default: 64 KiB
  • -m, –md5: Generate an MD5 hash of the device’s data and compare it against the MD5 hash of the reference image.
  • –hexdump: Dump the first 1 KiB of mismatched data in hex format.
  • –ignore-blocks: Ignore specified range of blocks when verifying. Format: ":" (e.g., "100:200").
  • –offset: Start verifying from the specified byte offset on both the reference image and device.
  • –quiet: Suppress progress and only print error messages.
  • -h, –help: Display help and usage information.

Examples

Simple Verification:

blkrawverify ref.img /dev/sda

Verification with MD5 Check:

blkrawverify -m ref.img /dev/sdb

Verifying from a Specific Offset:

blkrawverify --offset 1000000000 ref.img /dev/sdc

Ignoring Blocks from Verification:

blkrawverify --ignore-blocks 1000:2000 ref.img /dev/sdd

Common Issues

  • Missing Reference Image: Ensure the specified reference image exists and is accessible.
  • Permission Errors: Verify that you have read access to the reference image and write access to the device being verified.
  • Data Mismatch: If data corruption is detected, compare the reference image and the device at a byte level to identify the corrupted sectors.

Integration

With dd: Use blkrawverify to verify the integrity of data cloned using dd:

dd if=src.img of=dst.img bs=64K conv=sync
blkrawverify src.img dst.img

With rsync: Verify the integrity of files copied using rsync:

# Create a reference image of the source directory
rsync -av --files-from=/dev/null /src /ref/
# Copy the files to the destination directory
rsync -av --files-from=/dev/null /src /dst
# Verify the integrity of the copied files
blkrawverify /ref/ /dst

Related Commands

  • bmaptool: Manipulate block mappings
  • dd: Copy and convert data
  • md5sum: Calculate MD5 checksums
  • rsync: Remote file copying and synchronization