Thursday, August 16, 2012

How to check disk drive for errors and badblocks in Ubuntu / Debian Linux


badblocks is a Free software  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.

It will help you to check your drive periodically for bad blocks. It will list out all bad blocks. This list can be fed to fsck to be recorded in the filesystem data structures so that the operating system won’t try to use the bad blocks for storing data. The following example will show how this could be done.

Open a  terminal, type following command:

    $ sudo badblocks -v /dev/hda1 > bad-blocks

The above command will generate the file bad-blocks in the current directory from where you are running this command.

Now, you can pass this file to the fsck command to record these bad blocks

    $ sudo fsck -t ext4 -l bad-blocks /dev/hda1
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Check reference counts.
    Pass 5: Checking group summary information.

    /dev/hda1: ***** FILE SYSTEM WAS MODIFIED *****

    /dev/hda1: 25/360 files, 44/1440 blocks

If you have already  used  badblocks , e2fsck will try to move the block to another place. If the block was really bad, not just marginal, the contents of the file may be corrupted.

Looks at badblocks man pages for more command line options.

1 comment:

Mystik al said...

Cheers
for that very useful indeed.
I have never heard of the badblocks utility its a nice simple tool.