[TriLUG] HDD may be failing

David Burton via TriLUG trilug at trilug.org
Mon Aug 31 17:44:21 EDT 2015


It is not correct to say that the HDD "may be failing."*  It's dead, Jim. *

I agree with Joseph (except that I wouldn't bother with badblocks on a new
drive).  Here it is in more detail:


*Step 1: *if your most important files are not backed up, then, before you
do anything else, manually copy them to something else (thumbdrive,
external HDD, network drive, or whatever) *NOW*.

Do that *before* your ddrescue attempt, if possible, because sometimes
drive rot progresses fast, and copying the whole drive will necessarily
give it a workout, which may worsen the file damage.


*THEN* copy your ("rescue") dying drive with ddrescue, using either "step
2a" or "step 2b."

2a. You can either use a different computer running Linux with the old/sick
and new drives attached as additional drives ("step 2a"),
*or*

2b. You can use the sick computer with Linux booted from a "live" distro CD
or thumbdrive ("step 2b").

In either case, you can attach the new drive via USB adapter during the
rescue attempt, if you wish, but be sure to attach the old/sick drive via
SATA cable, not USB adapter. (Error handling is poor over USB.)


*Step 2a:* attach the new and old drives to the rescue machine, and boot up
Linux. If you don't already have ddrescue installed, then install it.
Assume that /dev/sdb is the old/sick drive, and /dev/sdc is the new one.
Then:
# fdisk -lu /dev/sdb >fdisk_out.txt
# ddrescue --force /dev/sdb /dev/sdc drive.log
# ddrescue -d -r10 --force /dev/sdb /dev/sdc drive.log

--force (or -f) is necessary with recent ddrescue versions if the
destination is a drive, rather than a file.

-d (or --direct) says to bypass the Linux file system (open source drive
with the O_DIRECT flag), and copy sector-by-sector. It's slow, but usually
enables recovering some additional sectors.

-r10 says retry ten times. There's nothing magic about 10. If there are
only a few unrecovered sectors, you can use -r1000 and go to bed; sometimes
you'll find that some of the failed sectors will eventually be recovered.

"drive.log" is an ASCII logfile, which keeps track of what has and has not
been rescued. (Author Antonio Diaz designed it that way at my suggestion.)
That's what enables the 2nd pass to ignore the already recovered sectors.
ddrescue flushes its status to the logfile about once a minute, so even if
you crash during the recovery process you can reboot and resume where you
left off.


*Step 2b:* attach the new drive and a writeable USB flash thumbdrive, and
boot your favorite rescue distro (e.g., parted magic, comes with ddrescue
preinstalled) from CD or thumb drive. You'll need three drives attached
(not counting the CD):
1. the dying drive, /dev/sda in this example
2. the new target drive, /dev/sdb in this example
3. another drive, probably a thumb drive, for the ddrescue logfile,
/dev/sdc in this example.

# mount /dev/sdc1 /media/sdc1
# mkdir /media/sdc1/rescue
# cd /media/sdc1/rescue
# fdisk -lu /dev/sda >fdisk_out.txt
# ddrescue --force /dev/sda /dev/sdb drive.log
# ddrescue -d -r10 --force /dev/sda /dev/sdb drive.log


If you're lucky, then when ddrescue is done your new drive can be put into
your computer in place of the dying drive, and you're off and running.

In theory, you could use the information in drive.log + fdisk_out.txt to
identify the damaged files, but I only know how to do that for ntfs file
systems.


Here's the ddrescue project page:
http://freshmeat.net/projects/addrescue/
http://freecode.com/projects/addrescue

This is the ddrescue manual:
https://www.gnu.org/software/ddrescue/manual/ddrescue_manual.html


On some distros, it might be useful to disable buffering on the old/sick
drive before the 2nd ddrescue pass. E.g., for Step 2a:
# hdparm -a0 -A0 -k1 -K1 /dev/sdb
(That is not necessary with Parted Magic.)


Dave




On Mon, Aug 31, 2015 at 4:01 PM, Joseph Mack NA3T via TriLUG <
trilug at trilug.org> wrote:

> On Mon, 31 Aug 2015, Bill Farrow via TriLUG wrote:
>
> Stop !
>>
>
> :-)
>
> If you have bad sectors or a dying drive, use ddrescue to clone the
>> drive. You can clone directly to the new drive or to a image file on
>> the new drive for later access. Disk size differences can be fixed
>> later, most file systems can be resized offline if needed.
>>
>> http://www.gnu.org/software/ddrescue/
>>
>
> #hop over failed blocks on the first run
> ddrescue -n $ddrescue_source $ddrescue_target $ddrescue_logfile
>
> #do failed blocks only



> ddrescue -d -r3 $ddrescue_source $ddrescue_target $ddrescue_logfile
>
> make sure you have a logfile.
>
> you do have a disk ready that you've run badblocks on? If not get two
> disks. ddrescue to one and run badblocks on the other. Then when badblocks
> is done copy your files to it and use that disk. Then run badblocks on the
> othe disk.
>
> About 1:10 disks fails badblocks
>
> Joe
>


More information about the TriLUG mailing list