This tutorial explains Linux “badblocks” command, options and its usage with examples.
Description:
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.
Synopsis:
badblocks [options] [device]
OPTIONS:
-s
show progress-bar
-v
be “verbose” and output bad sectors detected to stdout
-n
signifies a non-destructive read-write test
-w
do a destructive write test
-p
run through the extensive four pass test of sequent iterations
-o
print bad sectors to instead of stdout
-t
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.
- Practice Programming MCQs
- Apply for Programming Internship
- Check Information Technology Books
- Check Linux Books