PitchHut logo
Scan drives for bad/slow sectors, while skipping known ones.
Pitch

heavybad is a Linux tool designed for detecting bad sectors on raw block devices. With its multi-pass detection, users can scan drives at the LBA level and skip known bad sections, enhancing efficiency. It offers features like real-time logging, temperature monitoring, and supports both read-only and destructive modes to ensure comprehensive results.

Description

heavybad is a robust tool designed specifically for Linux that facilitates the detection of bad sectors on raw block devices. This multi-pass bad-sector detector operates at the Logical Block Addressing (LBA) level, employing O_DIRECT reads and write/verify methods to efficiently identify and map out slow or damaged sectors. Notably, heavybad supports skip lists to bypass known bad regions, thereby speeding up subsequent scans, and is primarily intended for use on unallocated or expendable storage areas, necessitating root access for operational effectiveness.

Key Features

  • Read-only Mode: Safe scanning on live or mounted data, utilizing O_DIRECT probes.
  • Destructive Mode: Offers multiple write patterns (0xAA, 0x55, 0xFF, 0x00, and RAND) with customizable verification reads to robustly assess remaining sectors.
  • Efficient Sector Detection: Last resort using a random pattern to catch marginal sectors that might be overlooked by uniform testing patterns.
  • Sub-range Splitting: Enables targeted skipping of confirmed bad LBAs in a chunk rather than discarding the whole chunk, optimizing the scanning process.
  • Skip List Support: Users can provide a list of confirmed bad LBAs/ranges to avoid rescanning, saving valuable time in repeat operations.
  • Real-time Output: As sectors are identified, bad and slow segments are logged in a designated file in concise, clear formats suitable for both NTFS and ext filesystems.
  • --merge-skip Flag: Seamlessly appends newly discovered bad sectors to the existing skip list, maintaining an updated record.
  • Queue Mode: Facilitates multiple back-to-back scans using a configurable JSON file, including features for infinite looping and automatic skip list updates.
  • Resume Functionality: Maintains progress in a resume file, allowing users to pick up where they left off in the event of interruptions.
  • Enhanced Logging: Logs every bad and slow LBA event and summarizes findings in append mode.
  • Temperature Monitoring: Monitors the drive’s temperature at regular intervals, utilizing the smartctl tool for effective assessment.
  • Response Time Histogram: Categorizes response times into ranges, providing valuable insights upon completion of scans.
  • Filesystem-Aware Output: Generates logs formatted appropriately for NTFS and ext filesystems, assisting in the integration with tools like ntfsmarkbad and e2fsck.

Recommended Workflow

For both NTFS and ext filesystems, users are guided through a systematic scanning workflow that includes both read-only and destructive passes to reliably map and verify bad sectors.

Example Usage

The command line offers flexibility in executing scans:

# Read-only precision scan (NTFS)
sudo python3 heavybad.py \
  --device /dev/sda \
  --start-lba 2048 --end-lba 346791935 \
  --chunk-size 1 --slow-ms 150 --fs ntfs \
  --skip-list known_bad.txt \
  --output found_bad.txt \
  --merge-skip --resume --histogram --verbose

# Destructive stress test (NTFS)
sudo python3 heavybad.py \
  --device /dev/sda --destructive \
  --start-lba 2048 --end-lba 346791935 \
  --chunk-size 4096 --passes 5 --verify-reads 3 --fs ntfs \
  --skip-list known_bad.txt \
  --output found_bad.txt \
  --merge-skip --resume --histogram --verbose

# Dry run — validate your command without touching the drive
sudo python3 heavybad.py \
  --device /dev/sda \
  --start-lba 2048 --end-lba 346791935 \
  --chunk-size 1 --dry-run

heavybad is built to assist users in efficiently managing storage health while providing detailed control over scanning methodologies, making it a valuable resource for system maintainers and enthusiasts alike.

0 comments

No comments yet.

Sign in to be the first to comment.