# low level format partially toasted 2.5" USB HD? [wrecked]

## JeroenV

Hi,

I have a 2.5" laptop HD that is partially bad (G-shock?), but I'm hoping to still use it for transport of unimportant large files, so I got a USB case for it.

Now I want to low-level format it to mark all bad sectors, so that I can more or less safely use the remaining "good" part of the drive.

The thing I first tried, was make a small vfat partition (sdg1) to possibly contain windows ext2 driver or the like, and the rest ext3. The bad sectors must be somewhere around the last 70-90% of the disk. So I tried

```

#mke2fs -v -O dir_index -cc -j -T largefile4 /dev/sdg2

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

13792 inodes, 14110740 blocks

705537 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=4294967296

431 block groups

32768 blocks per group, 32768 fragments per group

32 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

        4096000, 7962624, 11239424

Running command: badblocks -b 4096 -X -s -w /dev/sdg2 14110740

Testing with pattern 0xaa: done

badblocks: Input/output error during ext2fs_sync_device

Reading and comparing:           30051/       14110740

....

```

Subsequent test took more and more time, all in all several days(!). End then it ended with ..."aborted" (due to I/O error or something)

errors shown in the syslog (repeated gigabytes long!!!):

```

Mar 21 18:22:04 ahorn 7:0:0:0: rejecting I/O to dead device

```

Does this mean that I definitively have to trash the drive, or is there something more low-level that can actually mark out the bad blocks or sectors or whatever?

TIA  :Exclamation: 

----------

## DirtyHairy

Well, I don't know about low level formating (I know this from times long ago, but I'm not sure if such a thing is possible/necessary with todays drives), but I know that error --- it occurs when the USB device disconnects while the system is accessing it; you could try to grep your logs for something like this. If this is indeed the case, I would suspect that the drive is indeed damaged beyond help - I would suppose that the drives firmware gets messed up while trying to read some physically damaged block, which in turn messes up the USB-ATA interface. You might still try to directly connect it to an ATA controller and see if it is more tolerant though...

----------

## JeroenV

thanks, I might open a laptop, put the bad drive in and boot from live-cd to check it. In the mean time I tried the following:

```

# dd if=/dev/zero of=/dev/sdg

```

which started giving the "dead device"  errors after a while...

After giving Ctrl-C it said

```

58022902+0 records in

58022902+0 records out

29707725824 bytes (30 GB) copied, 699.96 s, 42.4 MB/s

```

so I figured the bad sectors start after 30GB.

I'm double checking with

```

# dd if=/dev/zero of=/dev/sdg bs=1k count=30000000

```

If I don't get any dead device errors, I'll just partition up to 30 GB and try to find if there's any good space near the end of the drive in the same way....(using dd's seek option)

This way I may end up with 2 usable partitions on this HD.

Come to think of it, I still may want to try the direct ATA connect option (laptop), since this is what mke2fs will do automatically if the driver doesn't freak out...

UPDATE

Ok, ata also has trouble with it, while doing a new format with badblocks option, I actually hear some funny noises too from the drive...

```

...

Mar 21 19:48:25 livecd end_request: I/O error, dev sda, sector 20569458

Mar 21 19:49:01 livecd ata1: command 0xca timeout, stat 0xd0 host_stat 0x20

Mar 21 19:49:01 livecd ata1: translated ATA stat/err 0xd0/00 to SCSI SK/ASC/ASCQ 0xb/47/00

Mar 21 19:49:01 livecd ata1: status=0xd0 { Busy }

Mar 21 19:49:01 livecd sd 0:0:0:0: SCSI error: return code = 0x8000002

Mar 21 19:49:01 livecd sda: Current: sense key=0xb

Mar 21 19:49:01 livecd ASC=0x47 ASCQ=0x0

Mar 21 19:49:01 livecd Info fld=0x139e322

Mar 21 19:49:01 livecd end_request: I/O error, dev sda, sector 20570914

Mar 21 19:49:31 livecd ata1: command 0xca timeout, stat 0xd0 host_stat 0x21

Mar 21 19:49:31 livecd ata1: translated ATA stat/err 0xd0/00 to SCSI SK/ASC/ASCQ 0xb/47/00

Mar 21 19:49:31 livecd ata1: status=0xd0 { Busy }

Mar 21 19:49:31 livecd sd 0:0:0:0: SCSI error: return code = 0x8000002

Mar 21 19:49:31 livecd sda: Current: sense key=0xb

Mar 21 19:49:31 livecd ASC=0x47 ASCQ=0x0

Mar 21 19:49:31 livecd Info fld=0x139e322

Mar 21 19:49:31 livecd end_request: I/O error, dev sda, sector 20570922

Mar 21 19:50:01 livecd ata1: command 0xca timeout, stat 0xd0 host_stat 0x21

Mar 21 19:50:01 livecd ata1: translated ATA stat/err 0xd0/00 to SCSI SK/ASC/ASCQ 0xb/47/00

Mar 21 19:50:01 livecd ata1: status=0xd0 { Busy }

Mar 21 19:50:01 livecd sd 0:0:0:0: SCSI error: return code = 0x8000002

Mar 21 19:50:01 livecd sda: Current: sense key=0xb

Mar 21 19:50:01 livecd ASC=0x47 ASCQ=0x0

Mar 21 19:50:01 livecd Info fld=0x139e322

Mar 21 19:50:01 livecd end_request: I/O error, dev sda, sector 20570930

```

.... seems this is the end for this drive   :Crying or Very sad: 

----------

## JeroenV

ok, I still haven't given up, let's see how far it can   go.

The idea: make a small partition, try to format it, if it doesn't succeed, mark that area as bad in a logfile, and make a new partition in the next area.

This way I will end up with a logfile that shows which area's can actually be successfully formatted, and I will then make a few partitions covering those area's.

The following code is the automated implementation of this concept, the only TODO seems to be to make sure that the USB HD is always recognised on the same device node (probably hack an udev rule), but I'm out of time for today...

```

#! /bin/bash

# still one  problem: the usb device has to be mounted undeer the SAME device (e.g. /dev/sdg)

# after every usb-storage reload!!! otherwise it will not work.

# you may have to (temporarily) hack udev rules

if [ -z "$1" ]; then

   echo "Give full device as argument"

   echo "This WILL destroy ALL DATA on the given device!!!"

   exit 1

fi

DEV=$1

echo "DEVICE $DEV IS GOING TO BE TOTALLY WIPED!!!"

echo "Press enter to continue..."

read

# set to "" to actually get active

# PRETEND="-n"

PRETEND=""

LOG="bpcheck.log"

MLOG="bpcheck.mlog"

PLOG="bpcheck.plog"

rm -f $LOG

MKFS="mke2fs $PRETEND -v -c -j -T largefile ${DEV}1"

PTYP=83

BOOT="*"

START=0

# increment (2G), we don't use blocks, because partition boundaries 

# seem to get mis-aligned (sfdisk complains)

INC=2000

END=$(expr $START \+ $INC)

# very sloppy determination of disk size in Mb

# assuming block size is 1024 (can probably be done nicer)

TSIZE=$(expr $(sfdisk -s $DEV) \/ 1000)

##################### functions

watchdog() {

   while [ 1 ]; do 

      D=$(date +'%h %d %H:%M')

      # echo "watchdog: $D"

      ERR=$(tail /var/log/messages | grep "$D" | grep "reset high speed USB device")

      if [ -n "$ERR" ]; then

         echo "Watchdog killing hung mke2fs process and resetting usbstorage"

         killall mke2fs

         rmmod -f usb-storage

         sleep 2s

         modprobe usb-storage

         sleep 10s

      fi

      sleep 1s

   done

}

######################### main prog

watchdog &

while [ $END -lt $TSIZE ]; do

   echo "TSIZE==$TSIZE START==$START END==$END"

   echo "Feeding to sfdisk: \"$START $INC $PTYP $BOOT\""

   echo "$START $INC $PTYP $BOOT" | sfdisk $PRETEND -uM $DEV > $PLOG

   $MKFS > $MLOG

   RET=$?

   echo "$MKFS returned $RET"

   if [ $RET -gt 0 ]; then

      echo "Partition between $START and $END (blocks) seems to contain bad blocks!" >> $LOG

      echo "detailed data:" >> $LOG

      cat $PLOG >> $LOG

      cat $MLOG >> $LOG

      echo "#######################################################################" >> $LOG

      # if killed or error, give time to settle new usbstorage

      sleep 1m

   fi

   START=$END

   END=$(expr $END \+ $INC)

done

# kill watchdog process

killall $0

```

Don't try this at home, it will for sure wipe all data on attached USB storage devices, for the rest YMMV.

----------

## thebigslide

If you want to low level format the drive, you might have to plug it into the IDE interface directly.  Download the utility from the manufacturer's website.  You will probably have to boot into a DOS or pseudoDOS environment to do so.

It will take a long time (20 minutes/gig maybe)

DO NOT INTERRUPT IT.

----------

## JeroenV

Thanks   :Wink:   (a bit late)

I have tried to do it this way because I don't own a 2.5"->3.5" IDE adapter:

 put freedos on a bootable USB stick with the HD util

 put the bad HD where it came from (my wife's laptop)

 boot it from the stick

It failed, freedos hangs at "InitDisk", alledgedly it's a memdisk/BIOS issue that apparently also affects Thinkpads.

I'll try next to install a bootable dos and the HD util on the bad harddisk itself, and see whether it's possible to run it.

I'll have to do that later since the laptop is being heavily used lately.

Thanks for your hints...

----------

## thebigslide

Can you net-boot the laptop?  What about burning a boot CD?  You won't be able to boot from the HD and then low level it.  You will need to boot from another device.  It may stop responding when it formats the part of the disc containing files which are in use and interrupt the low level format.  Or it may just simply refuse to work.

I would low level that baby 2 or 3 times over if it's been dropped as there's probably physical damage.  Low levelling multiple times will likely cause failures in regions of the disc adjacent to the damage now rather than later.

----------

## JeroenV

ok, it's official: the disk is toasted   :Crying or Very sad: 

I downloaded a freedos boot CD and hacked the fujitsu diagnostic tool on it. It failed the comprehensive test and advise me to contact fujitsu. SeaTools (wich  allegedly can cope with most brands of HD's also failed the long test. Before completing the test none of the tools offered low-level format capability, I suppose that would be step 2. But apparently the tools found that the disk was too far gone....

Anyway, it was very interesting to take the disk apart, the platters seem usable to make some jewelry of (earrings anyone?)  and I might find a purpose for the high-speed motor? (although I fear the torque is quite limited). 

Thanks for the hints anyway, my new freedos cd expertise may invite me to go flash some BIOSes   :Very Happy: 

----------

## thebigslide

too bad.  If you want the platters to stay shiney, make sure you laquer the metal.  They oxidize rapidly in humid air.

----------

## boatman9

One should not run badblocks on a drive that has a large number of bad blocks because the drive's firmware will repeatedly try each bad sector many times, it could take days!  A better way is to use dd_rescue to read the drive from beginning to the bad section, and again backwards from the end to the bad section.  When you have found the start and end of the group(s) of bad cylinders then you can place your partitions in a way that avoids these bad areas.

I know this topic is rather old, but it comes up in some search engine searches and some people will be referencing it so I thought I'd post my results.

I have a 20gb Toshiba drive that has a large number of bad blocks in two areas.  I used dd_rescue to find these areas, then I created my partitions.  I am pleased to report the success of my attempts to use this partly damaged hard drive.

Initially I tried to make the whole disk one partition and avoid the bad blocks by marking them bad.  This did not work because inodes and such are are distributed throughout the ext3 partition (similar problem was encountered when using reiserfs), some of these inodes landed in the bad sections.  The inodes can be relocated, but apparently only to blocks nearby the original site, there were no nearby good blocks in which to put the inodes.

Success came after I partitioned the drive into 3 parts, thereby completely avoiding the bad cylinders.  See partition table below.

```
Disk /dev/sda: 20.0 GB, 20003880960 bytes

16 heads, 63 sectors/track, 38760 cylinders

Units = cylinders of 1008 * 512 = 516096 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1               1       18873     9511991+  83  Linux

/dev/sda2           19548       22054     1263528   83  Linux

/dev/sda3           22856       38760     8016120   83  Linux
```

----------

