How to get rid of bad blocks on a drive

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
PaulBx1
Posts: 2312
Joined: Sat 17 Jun 2006, 03:11
Location: Wyoming, USA

How to get rid of bad blocks on a drive

#1 Post 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.)
Last edited by PaulBx1 on Sat 12 Dec 2009, 00:57, edited 1 time in total.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#2 Post by Flash »

Puppy has this command? If so, it would be a simple and easy way to erase a hard disk drive.

r__hughes
Posts: 359
Joined: Thu 13 Apr 2006, 04:14
Location: Montreal, Canada

#3 Post 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 :)
--- quad booting Slacko57NPAE, Slacko56NPAE, Slacko55PAE (with OO4, devx, Gimp) & WXP on DELL Dimension 2400 PC & DELL Latitude 630 Laptop using grub.
---USB-Flash booting same on Samsung N110 WXP Netbook and Lenovo q100 WXP netPC.

DMcCunney
Posts: 889
Joined: Tue 03 Feb 2009, 00:45

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

#4 Post 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

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#5 Post by Flash »

DMcCunney, um, thanks, I guess. For what it's worth, this is a forum for Linux users. :)

User avatar
Billwho?
Posts: 559
Joined: Tue 06 Dec 2005, 09:28
Location: still "In The Dog House" East Coast Oz
Trialing 4.20

#6 Post 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.
Linux = Learning through doing :shock: :? :D
The learning curve may be steep but there is a light at the end of the tunnel.
You just have to pass the occasional oncoming train to get there.

Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#7 Post 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.

User avatar
pemasu
Posts: 5474
Joined: Wed 08 Jul 2009, 12:26
Location: Finland

#8 Post 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

Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#9 Post 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? :)

User avatar
pemasu
Posts: 5474
Joined: Wed 08 Jul 2009, 12:26
Location: Finland

#10 Post 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.

Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#11 Post by Sylvander »

OK, thanks. :D

Post Reply