badblocks
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. It is part of the e2fsprogs project,[1] and a port is available for BSD operating systems.[2]
When run as a standalone program, badblocks gives a list of blocks with problems, if any. This makes it a good option for checking if the disk drive is ok independently from SMART data and file system checks. [3]
Contents |
[edit] 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 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.[4]
[edit] 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 and display progress by writing out the block numbers as they are checked. All data will be overwritten at the block level. If used on an entire disk as in the previous example, it destroys MBRs, partitions and data alike.
badblocks -wvsb 4096 /dev/sdb
This writes 4 different patterns on the whole drive /dev/sdb and verifies by reading back. Modern disk drives will probably not show any defective sectors because they silently remap bad sectors to spare tracks[citation needed], 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.
[edit] badblocks's "-c" option
badblocks has a "-c" option that lets users set the number of blocks it tests at a time. This option usually has little or no effect on scan speed.[5]
[edit] References
- ^ E2fsprogs: Ext2/3/4 Filesystem Utilities – Release notes
- ^ FreshPorts – sysutils/e2fsprogs
- ^ – Linux Administration and Privileged Commands Manual
- ^ – Linux Administration and Privileged Commands Manual
- ^ Ts'o, Theodore. "Re: Bug#232240: e2fsprogs: -c <number of blocks> should perhaps default to a higher number". Debian bug tracking system. http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=232240#20. Retrieved 11 December 2011.
[edit] External links
- Smartmontools – Bad block HOWTO for smartmontools. A complex how to for badblocks; might be confusing for the casual user.
| This Linux-related article is a stub. You can help Wikipedia by expanding it. |