Page 1 of 1

How to get rid of bad blocks on a drive

Posted: Thu 12 Feb 2009, 16:59
by PaulBx1
I had a drive from some old computer that was reporting bad blocks. I was about to toss it when I had the bright idea of finding where the bad blocks were, and then just making a partition around them with a single file named "Don't use this partition! Bad blocks here!"

So, I had this drive in a USB box, and started fiddling around with gparted and e2fsck, and chkdsk on a windows box too. I found out the reporting doesn't tell you the location, so I was trying to localize it by moving partition boundaries. Perhaps with some research I could have found a tool with more detailed reporting, or maybe it was a switch I missed, I don't know. But after a while, I noticed bad blocks were not being reported any more!

Turns out most modern drives have enough intelligence to remap bad blocks to some spare sectors they have in reserve, and according to one article I read, the way to trigger this behavior is to attempt to write the bad sector. Not sure how that would do it, but SOMETHING worked.

I finally ran this command on the disk:

Code: Select all

badblocks -svw /dev/sdc
This code writes the entire disk, from start to finish, with some alternating bit patterns, all ones and all zeros, and verifies after each write. Needless to say, there is no data left after this is done, no partitions, not even an mbr. You might want to back up any data on the drive before doing this. :wink:

It took half a day for this 150GB USB drive, but now I am confident the bad blocks are mapped out and the drive is good.

(Edit: I added the "s" flag to the above command because it gives progress information, something useful to have for a command that might take many hours to finish.)

Posted: Thu 12 Feb 2009, 19:46
by Flash
Puppy has this command? If so, it would be a simple and easy way to erase a hard disk drive.

Posted: Thu 12 Feb 2009, 22:21
by r__hughes
I get this with a frugal pup411

~#
~# which badblocks
/sbin/badblocks
~#
~#
~# badblocks --h
badblocks: invalid option -- -
Usage: badblocks [-b block_size] [-i input_file] [-o output_file] [-svwnf]
[-c blocks_at_once] [-p num_passes] [-t test_pattern [-t test_pattern [...]]]
device [last_block [start_block]]
~#

I will bravely leave it to others to verify if this can be used to completely erase a disk :)

Re: How to get rid of bad blocks on a drive

Posted: Wed 18 Feb 2009, 15:17
by DMcCunney
PaulBx1 wrote:I had a drive from some old computer that was reporting bad blocks. I was about to toss it when I had the bright idea of finding where the bad blocks were, and then just making a partition around them with a single file named "Don't use this partition! Bad blocks here!"
Nice thought, but unfortunately, the bad blocks may not all be localized in a single area.
So, I had this drive in a USB box, and started fiddling around with gparted and e2fsck, and chkdsk on a windows box too. I found out the reporting doesn't tell you the location, so I was trying to localize it by moving partition boundaries.
If you can access the drive from a Windows box, and it was previously formatted as FAT or NTFS, CHKDSK /F /R /X in a command window will do a surface scan of the drive and map bad blocks. /F is fix file system errors, /R is the surface scan, and /X dismounts the drive so CHKDSK gets exclusive access.

You can then reformat it with whatever file system you like.

Your solution is a good one if you only have Linux available.
______
Dennis

Posted: Wed 18 Feb 2009, 19:08
by Flash
DMcCunney, um, thanks, I guess. For what it's worth, this is a forum for Linux users. :)

Posted: Thu 19 Feb 2009, 12:18
by Billwho?
Ahh but some of us have to maintain window$ boxes for less enlightened family members. So why not kill two canaries with one rock and run the scan on the D drive while you are downloading all the windows and virus scanner updates.

Posted: Sun 13 Mar 2011, 17:50
by Sylvander
1. The HDD on my sons Dell Inspiron 6400 had [has?] a "bad block" somewhere on his Windows XP NTFS partition holding Windows XP [and 4 varied Puppy pupsaves+SFS] on his internal HDD [ATA Hitachi HTS54106].
I found this because Lupu-520 was [very suspiciously] showing about 50% CPUusage...
SO...

2. I rebooted with the...
puppy pfix=ram
Command.
And used GParted to "check" the partition.
But it reported it couldn't complete the check/fix.
SO...

3. I booted "FalconFour's UBCD v2.0"...
And ran a diagnostic [HDtune?]...
Which reported a single faulty "block"...
ERROR at 3190MB (LBA 6534312)
Then...

4. Ran...
chkdsk /r c:
I believe /r includes /f
So no need to use...
chkdsk /f /r c:

5. HDtune still shows the faulty block [how come?] but both Lupu and Windows seem to be working well.

6. I'd like to be sure the faulty block has been taken out of use.
And if it hasn't, to find a program that will do it.
Hopefully it will then no longer be displayed as faulty by HDtune.

Posted: Mon 14 Mar 2011, 21:26
by pemasu
Well, you can feed the badblocks info to fsck so that bad blocks are not used:
http://linuxpoison.blogspot.com/2008/01 ... s-and.html

Posted: Mon 14 Mar 2011, 22:10
by Sylvander
1. Could you explain the various parts of those 2 command lines, so I may gain some level of knowledge and understanding of what is being done? :)

Posted: Tue 15 Mar 2011, 06:17
by pemasu
Sylvander. I just found that possibility when someone else asked the same question in irc.
The mechanism is simple. You execute the badblocks and create textfile to have the findings. Then you feed that information to fsck so that those found badblocks are not used.
However I havent used it myself. I think you should search the net for right options for both commands. I wanted to inform you of one way I found when researching the same question.
I am sure the net offers a lot references.

Oh, and the partition you check needs to be unmounted. You probably knew that, but as safety measure, I remind it.

Posted: Tue 15 Mar 2011, 07:29
by Sylvander
OK, thanks. :D