Understanding the Relationship Between SMART Self-Tests and badblocks: A Technical Deep Dive


2 views

While both smartctl -t long and badblocks perform disk surface scans, they operate at different levels:

  • SMART self-tests are firmware-level diagnostics executed by the drive's controller
  • badblocks is a filesystem-level tool that performs raw block testing

When badblocks detects a bad sector:

# Example badblocks command
badblocks -sv /dev/sda

The drive firmware may automatically reallocate the sector if it's still within the spare sector pool. This would increment the SMART Reallocated_Sector_Ct value. However, this behavior depends on:

  • Drive manufacturer implementation
  • Current health status of the drive
  • Available spare sectors remaining

For comprehensive testing, I recommend this sequence:

# First run SMART long test
smartctl -t long /dev/sda

# Then perform destructive badblocks test (warning: erases data!)
badblocks -wsv /dev/sda

The key differences in output interpretation:

Tool What It Reports Impact on SMART
smartctl Firmware-detected errors Directly updates SMART
badblocks OS-level read failures May trigger SMART updates

Use SMART self-tests when:

  • Monitoring drive health over time
  • Needing non-destructive testing
  • Checking warranty status

Use badblocks when:

  • Preparing a new drive for service
  • Suspecting undetected media errors
  • Needing absolute certainty about block integrity

Here's a simple bash script to combine both approaches:

#!/bin/bash
DEVICE="/dev/sda"

# Run SMART long test
smartctl -t long $DEVICE
sleep 7200 # Wait 2 hours for test completion

# Check results
smartctl -a $DEVICE | grep -i "test result"

# Run badblocks in non-destructive mode
badblocks -sv $DEVICE -o badblocks.txt

# Compare with SMART data
echo "SMART Reallocated Sectors:"
smartctl -A $DEVICE | grep Reallocated_Sector_Ct

While both tools examine drive health, their approaches differ fundamentally. SMART self-tests operate through the drive's internal diagnostics firmware, while badblocks performs external surface scanning at the filesystem level.

When you execute smartctl -t long /dev/sda, the drive controller:

1. Performs complete surface scan using internal algorithms
2. Verifies all data sectors (including spare areas)
3. Updates SMART attributes like:
   - Reallocated_Sector_Ct
   - Current_Pending_Sector
   - Offline_Uncorrectable

The badblocks utility works differently:

# Typical destructive test pattern
badblocks -wsv /dev/sdX

# Non-destructive verification
badblocks -nsv /dev/sdX

Unlike SMART tests, badblocks doesn't automatically update drive firmware statistics. However, modern drives may still reallocate sectors detected during these scans.

When combined strategically:

# Sequence for comprehensive testing
smartctl -t long /dev/sdX && \
badblocks -nsv /dev/sdX && \
smartctl -a /dev/sdX

Critical factors to weigh:

  • SMART tests preserve existing data
  • badblocks -w will DESTROY data (use with caution)
  • Enterprise environments often combine both methods

Here's a sample monitoring script:

#!/bin/bash
DRIVE="/dev/sda"

# Initiate long test
smartctl -t long $DRIVE

# Wait for completion
while [[ $(smartctl -c $DRIVE | grep -c "Self-test in progress") -gt 0 ]]; do
    sleep 300
done

# Cross-verify results
BADBLOCKS=$(badblocks -ns $DRIVE | wc -l)
SMART_RELOC=$(smartctl -A $DRIVE | grep Reallocated_Sector_Ct | awk '{print $10}')

# Alert logic
if [[ $BADBLOCKS -gt 0 || $SMART_RELOC -gt 0 ]]; then
    echo "WARNING: Drive issues detected" | mail -s "Drive Alert" admin@example.com
fi