Badblocks
   HOME

TheInfoList



OR:

badblocks is a
Linux Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
utility to check for
bad sector Bad Sector is an ambient/noise project formed in 1992 in Tuscany, Italy by Massimo Magrini. While working at the Computer Art Lab of ISTI in Pisa (one of the CNR institutes), he developed original gesture interfaces that he uses in live pe ...
s on a
disk drive Disc or disk may refer to: * Disk (mathematics), a two dimensional shape, the interior of a circle * Disk storage * Optical disc * Floppy disk Music * Disc (band), an American experimental music band * ''Disk'' (album), a 1995 EP by Moby Other ...
. It can create a text file with a list of these sectors that can be used with other programs, like
mkfs In computer operating systems, mkfs is a command used to format a block storage device with a specific file system. The command is part of Unix and Unix-like operating systems. In Unix, a block storage device must be formatted with a file syst ...
, so that they are not used in the future and thus do not cause data corruption. It is part of the
e2fsprogs e2fsprogs (sometimes called the e2fs programs) is a set of utilities for maintaining the ext2, ext3 and ext4 file systems. Since those file systems are often the default for Linux distributions, it is commonly considered to be essential softwar ...
project, and a port is available for
BSD The Berkeley Software Distribution (BSD), also known as Berkeley Unix or BSD Unix, is a discontinued Unix operating system developed and distributed by the Computer Systems Research Group (CSRG) at the University of California, Berkeley, beginni ...
operating system An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ...
s. 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 ''SMart'' was a British CBBC television programme based on art, which began in 1994 and ended in 2009. The programme was recorded at BBC Television Centre in London. Previously it had been recorded in Studio A at Pebble Mill Studios in Birmingha ...
data and file system checks.


e2fsck's "-c" option

A more common use case is the invocation of badblocks as part of e2fsck 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 An 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 attribu ...
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 MBRs, 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 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