1748234 Members
3196 Online
108759 Solutions
New Discussion юеВ

bad blocks

 
admin1979
Super Advisor

bad blocks


Hello,

A question : How do we detect & correct a bad blocks in a hard disk.
We have a test Linux system in which we need to test this out.

I googled a bit and found that e2fsck -cy /dev/partition would search for the badblocks.
Is it correct?

And if it does , how do we correct it ?
Or else how do we make sure to skip it so that they will not be used (Mark as unused maybe??) anymore.

Please suggest.

Thanks,
admin
9 REPLIES 9
Michal Kapalka (mikap)
Honored Contributor

Re: bad blocks

hi,

check this link :

http://smartmontools.sourceforge.net/badblockhowto.html

hope i will help you

mikap
Goran┬аKoruga
Honored Contributor

Re: bad blocks

Hello.

You can also run badblocks command by hand. Or tell mkfs to use its status to ignore detected bad blocks (mkfs -c).

I hope you're aware that using disks with known bad sectors is not a good idea.

Regards,
Goran
Steven E. Protter
Exalted Contributor

Re: bad blocks

Shalom,

the problem is e2fsck -cy is for use on a file system that is unmounted. To use it on a mounted file system would do damage.

I would check for bad blocks like this:

dd if=/disk_device of=/dev/null bs=10024 count=10000

Make the count bigger and change the block size(bs) to test the entire disk. This will not damage the file systems on the disk.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
admin1979
Super Advisor

Re: bad blocks


Hello,

Thanx for the replies. The disk in question is 36.4 in size. So dd command should be changed to something like ,

bs=1024 & count=36000000 to test the 36.4 GB hard disk.

Is it right?

Secondly,

If dd does detect the bad blocks then what o/p should we expect from this command.

Thanx
admin
Matti_Kurkela
Honored Contributor

Re: bad blocks

Running e2fsck with the '-c' option causes e2fsck to run the "badblocks" command to detect the bad blocks, and to automatically mark them as unusable.

All modern disk drives (=manufactured in 1990s or later) have built-in bad block detection in the hardware, at the disk mechanism/firmware level. The disk has a number of spare blocks: it transparently redirects any I/O that would access the bad blocks to these replacement blocks.

If e2fsck/badblocks can detect any bad blocks on the disk, that means the disk's built-in bad block mechanism has already detected and corrected as many bad blocks as it can, and is unable to fix any more. So it's an indication that there is already fairly severe damage on the disk.

Running e2fsck -cy might be acceptable as a *short-term workaround only* to allow backing up the latest data, or if the server is in a distant location where the disk cannot be replaced without a significant delay.

But you should definitely treat the disk as *unreliable* from now on: make extra sure all important software, data and configuration information is backed up and that the backups are usable.

The only real fix for the problem is to replace the disk.

(NOTE: in some special cases a diagnostic program published by the disk manufacturer can fix some types of errors. These fixes are usually disk model specific and suggest that the disk may have known hardware/firmware bugs: check if the manufacturer has published disk firmware upgrades in this case.)

For the "dd" command: if you don't specify the "count=" parameter at all, the command will automatically process the entire source disk. If the dd command can be run into completion without any new disk errors appearing into the system logs (see the "dmesg" command and the log files in /var/log), the disk has no bad blocks that would be visible to the filesystem level.

The bs= parameter should be set to a value that is a multiple of the actual block size of the disk. A larger value will allow dd to request blocks from the disk in larger chunks, which may speed the process.

If the actual size of the disk is not an exact multiple of the bs= value, the dd command will report one incomplete block at the end. This is not a problem.

The output of the dd command should look like:

12345678+0 records in
12345678+0 records out

if the disk size was an exact multiple of the bs= value, and

12345678+1 records in
12345679+0 records out

if it wasn't. (12345678+1 means "12345678 complete blocks of size bs= and one incomplete block", and dd will automatically pad it with zeroes when outputting, creating one extra full block.)

MK
MK
admin1979
Super Advisor

Re: bad blocks


Thanx for detailed reply. If the disk has such built in mechanism , then is there any way we can see if it really did detect any such bad blocks and used the spare blocks at the end of the disk??

PS : The latest e2fsck -cy on partitions of the disks , did not detect any badblocks.

Thanx
admin
Steven E. Protter
Exalted Contributor

Re: bad blocks

Shalom again admin,

bs=1024 & count=36000000 to test the 36.4 GB hard disk.

That is correct for dd.
e2fsck is a file system check tool.

It is not going to find bad disk blocks.

It is going to find corrupted file systems.

If you umount your file system and run e2fsck on it and find no problems, it is very likely however that the section of the disk the file system is sitting on is okay.

Other Linux Block checking tools:

http://linux.die.net/man/8/badblocks

http://www.felipecruz.com/linux-disk-utilies.php

http://linux.about.com/od/lsa_guide/a/gdelsa35t09.htm

http://www.mepis.org/node/5649

Each method has its merits, pluses and minues.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
admin1979
Super Advisor

Re: bad blocks


Hello,

The question was if dd is used , what sort of output should we expect in case it does find any badblocks?
And do we need to bring the machine to single user mode for dd to execute?

Secondly I went thru the links u suggested, the very first link says ,

For this reason, it is strongly recommended that users not run badblocks directly, but rather use the -c option of the e2fsck and mke2fs programs.

So thats what we used e2fsck. Isnt it?
Steven E. Protter
Exalted Contributor

Re: bad blocks

Shalom again admin,

The question was if dd is used , what sort of output should we expect in case it does find any badblocks?

You will see at the end of the dd command read errors indicated. The records read will not balance out.

[root@bersheva hpux.depots]# dd if=/dev/hda1 of=/dev/null bs=1024 count=10
10+0 records in
10+0 records out
10240 bytes (10 kB) copied, 0.00882 seconds, 1.2 MB/s

Records in will not match records out if there are bad blocks.


And do we need to bring the machine to single user mode for dd to execute?

No: You can run dd on any disk, even if the system is in heavy use.

Secondly I went thru the links u suggested, the very first link says ,

For this reason, it is strongly recommended that users not run badblocks directly, but rather use the -c option of the e2fsck and mke2fs programs.

This is a root only activity. Users should not have access to these utilities.

So thats what we used e2fsck. Isnt it?
Yes.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com