$linuxjunkies
>

badblocks(8)

Search a device for bad blocks and optionally mark them as unusable.

UbuntuDebianFedoraArch

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

FlagWhat it does
-b block_sizeBlock size in bytes (default 1024); use 4096 for modern disks
-c blocks_at_onceNumber of blocks to test at once (default 16); affects speed
-wDestructive write test; writes patterns and reads them back (slower, thorough)
-nNon-destructive read-write test; does not destroy existing data
-rNon-destructive read-only test (default); fastest method
-t test_typeSpecify test pattern: random, 0, 1, or combination (e.g., '0,1,2,random')
-o output_fileWrite bad block numbers to file for use with e2fsck -l
-p num_passesNumber of passes for write test (default 0 means continuous)
-s start_blockStart testing from this block number instead of the beginning
-vVerbose output; show progress and statistics
-d read_delay_factorDelay in milliseconds between reads; helps with timing-sensitive drives
-fForce 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/sda1

Destructive write test on entire /dev/sdb disk; tests write/read patterns

sudo badblocks -w -v /dev/sdb

Non-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/sda1

Test with alternating 0 and 1 patterns, write results to badblocks.list

sudo badblocks -t 0,1 -o badblocks.list /dev/sdc

After running badblocks, use e2fsck to mark the discovered bad blocks as unusable

sudo e2fsck -l bad_blocks.txt /dev/sda1

Read-only test from block 1000000 to 5000000 (partial device test)

sudo badblocks -r -s 1000000 /dev/sdb 5000000

Destructive write test with 2 passes, verbose mode; thorough hardware verification

sudo badblocks -w -p 2 -v /dev/sdc

Related commands