badblocks(8)
Search a device for bad blocks and optionally mark them as unusable.
Synopsis
badblocks [-b block_size] [-c blocks_at_once] [-d read_delay_factor] [-e max_bad_blocks] [-f] [-i input_file] [-o output_file] [-p num_passes] [-s start_block] [-t test_type] [-v] [-w] [-X] [-z] device [last_block] [first_block]Description
badblocks is used to search a device (typically a hard disk or USB drive) for bad blocks. It can perform non-destructive read-only tests or destructive write tests to identify sectors that cannot reliably store data. The results can be saved to a file for use with e2fsck or other filesystem tools to mark bad blocks as unusable.
This command is essential for diagnosing hardware failures, testing new drives before use, or identifying problematic sectors on aging storage devices. Root privileges are typically required.
Common options
| Flag | What it does |
|---|---|
-b block_size | Block size in bytes (default 1024); use 4096 for modern disks |
-c blocks_at_once | Number of blocks to test at once (default 16); affects speed |
-w | Destructive write test; writes patterns and reads them back (slower, thorough) |
-n | Non-destructive read-write test; does not destroy existing data |
-r | Non-destructive read-only test (default); fastest method |
-t test_type | Specify test pattern: random, 0, 1, or combination (e.g., '0,1,2,random') |
-o output_file | Write bad block numbers to file for use with e2fsck -l |
-p num_passes | Number of passes for write test (default 0 means continuous) |
-s start_block | Start testing from this block number instead of the beginning |
-v | Verbose output; show progress and statistics |
-d read_delay_factor | Delay in milliseconds between reads; helps with timing-sensitive drives |
-f | Force test even if device appears to be in use |
Examples
Non-destructive read-only test on /dev/sda1 with verbose output showing progress
sudo badblocks -v /dev/sda1Destructive write test on entire /dev/sdb disk; tests write/read patterns
sudo badblocks -w -v /dev/sdbNon-destructive read-write test, save bad blocks to bad_blocks.txt, test 64 blocks at once
sudo badblocks -n -c 64 -o bad_blocks.txt /dev/sda1Test with alternating 0 and 1 patterns, write results to badblocks.list
sudo badblocks -t 0,1 -o badblocks.list /dev/sdcAfter running badblocks, use e2fsck to mark the discovered bad blocks as unusable
sudo e2fsck -l bad_blocks.txt /dev/sda1Read-only test from block 1000000 to 5000000 (partial device test)
sudo badblocks -r -s 1000000 /dev/sdb 5000000Destructive write test with 2 passes, verbose mode; thorough hardware verification
sudo badblocks -w -p 2 -v /dev/sdc