A failed or failing drive is never a good sign. Knowing when or if you have a failing drive is incredibly important. In an enterprise networking environment data is money…so uptime.

Badblocks is a tool used in Linux to check for bad sectors in a system.  A sector is a subdivision of a track on a storage device. Bad sectors cannot be used because they have become permanently damaged. This is why constantly backing up data is a good practice. Bad sectors and bad blocks can appear at any time. Which is why a lot of companies use RAID arrays like 1, 5 and 10. That way they have backups and copies of information. If you do not have an array, try to schedule a weekly backup of information.

Use fdisk with root superuser privileges. fdisk displays information about the drives on the workstation. It will even display information about their partitions. Since badblocks is used to search for bad blocks, mostly in partitions, checking to see how many partitions you have is a smart idea.

Please note that you will need to specify the block size with -c.

$ sudo fdisk -l

Once you have picked a drive to check, run this.  Just for your information, -v will run the application is verbose mode.

# badblocks -v /dev/<device>

If you are looking to store the results within a text file, direct the output to a text file.

# badblocks -v /dev/sda > failedsectors.txt

Should you come across a bad sector, use e2fsck (ext2/ext3/ext4) and fdisk with the file you stored the output to. Using the -l option will tell the command line to add the block number listed in the file specified by the filename, failedsectores.txt.

Fair warning, the -w option on a device containing data will erase all information on the device.  If you are looking to do a write mode test, use the -n option instead. The option -n will preserve your data but.

More options for badblocks can be found here.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s