badblocks Command in Linux with Examples

This tutorial explains Linux “badblocks” command, options and its usage with examples.

badblocks – check bad blocks


badblocks is a Linux utility to check for bad sectors on a disk drive. It creates a list of these sectors that can be used with other programs, like mkfs, so that they are not used in the future and thus do not cause corruption of data.

In case of a HDD the whole sector should get retired. A sector is a subdivision of a track on a storage device and sectors that have become bad cannot be used because they have become permanently damaged (a bad sector can change a letter in a text file to causing a binary program to have a segmentation fault).

This can be done in a destructive write-mode that effectively wipes the device (do Backup!) or in non-destructive read-write (Backup advisable as well!) and read-only modes.



badblocks [options] [device]


show progress-bar
be “verbose” and output bad sectors detected to stdout
signifies a non-destructive read-write test
do a destructive write test
run through the extensive four pass test of sequent iterations
print bad sectors to instead of stdout
Specify a pattern.

Note : The may either be a numeric value between 0 and ULONG_MAX-1 inclusive
Note : Badblocks can be made to repeatedly write a single “random pattern” with the -t random option

1. Read-Write Test (non-destructive)

This test is designed for devices with data already on them. A non-destructive read-write test does transparently backup original content before testing sectors with a single random pattern and then restoring the content from the backup. This is a single pass test.

$ badblocks -nsv /dev/

2. Read-Write Test (destructive)


This test is primarily for testing new drives with no data on them. As the pattern is written to every accesible block the device effectively gets wiped. Default is an extensive test with four passes using four different patterns: 0xaa (10101010), 0x55 (01010101), 0xff (11111111) and 0x00 (00000000).

$ badblocks -wsv /dev/
Checking for bad blocks in read-write mode
From block 0 to 488386583
Testing with pattern 0xaa: done
Reading and comparing: done
Testing with pattern 0x55: done
Reading and comparing: done
Testing with pattern 0xff: 33.45% done, 4:09:55 elapsed. (0/0/0 errors)
Testing with pattern 0x00: done
Reading and comparing: done
Pass completed, 0 bad blocks found. (0/0/0 errors)

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

If you find any mistake above, kindly email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.