LinuxCommandLibrary

badblocks

Scan a storage device for bad sectors

TLDR

Search a disk for bad blocks by using a non-destructive read-only test

$ sudo badblocks [/dev/sdX]
copy

Search an unmounted disk for bad blocks with a [n]on-destructive read-write test
$ sudo badblocks -n [/dev/sdX]
copy

Search an unmounted disk for bad blocks with a destructive [w]rite test
$ sudo badblocks -w [/dev/sdX]
copy

Use the destructive [w]rite test and [s]how [v]erbose progress
$ sudo badblocks -svw [/dev/sdX]
copy

In destructive mode, [o]utput found blocks to a file
$ sudo badblocks -o [path/to/file] -w [/dev/sdX]
copy

Use the destructive mode with improved speed using 4K [b]lock size and 64K block [c]ount
$ sudo badblocks -w -b [4096] -c [65536] [/dev/sdX]
copy

SYNOPSIS

badblocks [-sSvwz] [-b blocksize] [-c count] [-i input] [-o output] [-t patterns] [-B] device [first-block [last-block]]

PARAMETERS

-b blocksize
    Specify block size in bytes (default 1024)

-c count
    Number of blocks to read per pass (default 64)

-i input
    File containing known bad blocks to skip

-o output
    Write bad block list to file instead of stdout

-s
    Show progress report with estimated completion time

-t patterns
    Specify test patterns (hex bytes, e.g., 'a0' or multiple '0xaa:0x55')

-v
    Verbose mode, print more details

-w
    Destructive read-write test mode (erases data!)

-z
    Zero-fill blocks after writing patterns (destructive)

-B
    Validate last-block arg against device size

-S
    Use device size from filesystem superblock

-V
    Print version information

DESCRIPTION

badblocks is a Linux utility from the e2fsprogs package used to test hard disks and other block devices for bad sectors or blocks. It performs read-only scans by default, reporting unreadable blocks, or destructive read-write-verify tests with the -w option, which writes test patterns, reads them back, and verifies integrity—but erases all data in the process.

In non-destructive mode, it sequentially reads blocks, marking bad ones in output. Progress can be shown with -s, and verbose details with -v. Output lists bad block numbers, suitable for input to tools like e2fsck -l badblocks.list to mark them bad on filesystems.

Specify block size with -b, test range with first/last block args, or patterns like 0xaa with -t. It's essential for disk diagnostics before formatting or when suspecting media failure, but requires unmounted devices. Tests can take hours or days on large drives.

CAVEATS

Destructive modes (-w, -z) permanently erase data; use only on empty, unmounted devices. Tests are extremely time-intensive on large drives. Not suitable for SSDs (use smartctl instead). May falsely report bad blocks on slow/removable media.

OUTPUT USAGE

Bad block list can pipe to e2fsck -l - or save as file for mke2fs -B to exclude during formatting.
Example: badblocks -v /dev/sda > badblocks.list

TEST PATTERNS

Default: sequential byte increments. Custom: -t 0xaa:0x55:0xff cycles through patterns. Use hex values for thorough testing.

HISTORY

Developed in 1992 by Remy Card for ext2 filesystem tools; maintained by Theodore Ts'o in e2fsprogs since 1994. Evolved for ext3/4 support, with options added for better progress reporting and patterns over decades.

SEE ALSO

e2fsck(8), mke2fs(8), dumpe2fs(8), fsck(8), hdparm(8)

Copied to clipboard