Badblocks
   HOME

TheInfoList



OR:

badblocks is a Linux utility to check for bad sectors on a disk drive. It can create a text file with 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. It is part of the e2fsprogs project, and a port is available for
BSD The Berkeley Software Distribution or Berkeley Standard Distribution (BSD) is a discontinued operating system based on Research Unix, developed and distributed by the Computer Systems Research Group (CSRG) at the University of California, Berk ...
operating systems. When run as a standalone program, badblocks gives a list of blocks with problems, if any. This makes it a good option for checking whether the disk drive is healthy, independent of SMART data and file system checks.


e2fsck's "-c" option

A more common use case is the invocation of badblocks as part of
e2fsck The system utility fsck (''file system consistency check'') is a tool for checking the consistency of a file system in Unix and Unix-like operating systems, such as Linux, macOS, and FreeBSD. A similar command, CHKDSK, exists in Microsoft Windows ...
when passing the option "-c" to scan for bad blocks and prevent data from being stored on these blocks. This is done by adding the list of found bad blocks to the bad block
inode The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attribute ...
to prevent the affected sectors from being allocated to a file or directory. The test can be done using a read-only ("-c") or non-destructive read–write ("-cc") test method.


dumpe2fs

Running dumpe2fs -b will display the list of bad blocks recorded by e2fsck or tune2fs.


Examples

badblocks -nvs /dev/sdb This would check the drive "sdb" in non-destructive read–write mode and display progress by writing out the block numbers as they are checked. badblocks -wvs /dev/sdb6 This would check the sixth partition of the drive "sdb", in destructive read–write mode (-w = write-mode), which writes 4 different patterns on the whole partition and verifies each by reading back. It displays progress by writing out the block numbers as they are checked (-s = show, -v = verbose). All data on the partition will be overwritten at the block level. badblocks -wvsb 4096 /dev/sdb This does the same as above, but to the entire drive, with a block size (-b) of 4096. This destroys
MBR MBR may refer to: Computing * Master boot record, the first sector of a partitioned data storage device, used for booting * Memory buffer register * Minimum bounding rectangle * Minimum bit rate Publications * ''The Malaysia Book of Records'' * ...
s, partitions and data alike. Modern disk drives will probably not show any defective sectors because they silently remap bad sectors to spare tracks, but running the program with a new drive for several days will test the whole surface, and when reading it afterwards S.M.A.R.T. data will eventually show reallocated sectors. Using the -w
option Option or Options may refer to: Computing *Option key, a key on Apple computer keyboards *Option type, a polymorphic data type in programming languages *Command-line option, an optional parameter to a command *OPTIONS, an HTTP request method ...
on a device containing an existing file system erases the data on that device.


References

{{Reflist


External links

* Smartmontools â€
Bad block HOWTO for smartmontools.
A complex how to for badblocks; might be confusing for the casual user.
Badblocks - ArchWIKI
Unix file system-related software