Wednesday, January 23, 2008

Howto check disk drive for errors and badblocks

It can be a good idea to periodically check for bad blocks. This is done with the badblocks command. It outputs a list of the numbers of all bad blocks it can find. 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.

$ badblocks /dev/hda1 > bad-blocks

$ fsck -t ext3 -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: 11/360 files, 63/1440 blocks

If badblocks reports a block that was already used, 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.

2 comments:

abubin said...

can I run this command without unmounting the partition? Cause I have problems unmounting /var. Lots of services running that is using this partition.

Anonymous said...

Moreover, the badblocks man page states that it must know the correct block size, otherwise it will go bad; and it is recommended to rather use fsck -c [mount point] then the fsck will pass correct block size to badblocks.

Post a Comment

Linuxpoison Archive

Add to Technorati Favorites http://www.wikio.com Software Computers blogs TopOfBlogs Unix-Linux Blogs Computers (Software) - TOP.ORG Computer Software Blog Directory Computer Blogs - Blog Catalog Blog Directory Blog Flux Directory Technology Blogs - Blog Rankings

Copying and distribution of the articles is permitted in any medium as long as the author and source are quoted.
E-mail contact: njauhari@cybage.com
All trademarks are the property of their respective owners.