In this tip, we will see how to use badblocks to scan/test your hard disk partitions (including USB hard drivers) for bad blocks (or bad sectors). Bad sectors are sectors that are damaged and cannot be used to store data on a hard drive. Badblocks will detect all bad blocks on your hard disk and store them in a text file so that you can use it with e2fsck to configure your OS to not store your data in these damaged sectors.

This tip can be run in the following Ubuntu/Linux Mint distributions:

  • Ubuntu 12.10/12.04/11.10 or older
  • Linux Mint 14/13/12 or older

WARNING: We are not liable for any mis-use of the commands given below. Use them at your own risk!

Getting Started

To know the names of mounted hard drives and USB devices on your system, run this command:

sudo fdisk -l

To scan your hard disk for damaged sectors, run this command:

sudo badblocks -v /dev/sda1 > bad-sectors.txt

Repalce /dev/sda1 with your own device name. The text file containing all bad blocks to be generated will be named bad-sectors.txt; it will be created in the current terminal location. When the scan is complete and if bad sectors are reported, you can use the generated text file with the e2fsck command line utility using this command (hard disk must be unmounted):

sudo e2fsck -l bad-sectors.txt  /dev/sda1

You system will now ignore all bad sectors detected by badblocks. For more help about badblocks and e2fsck, run one of these commands from the terminal:

man badblocks

or

man e2fsck

 
Top