Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Recovering from partial hard drive failure
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Blue Lightning
Tux's lil' helper
Tux's lil' helper


Joined: 20 Jan 2003
Posts: 137
Location: Auckland, New Zealand

PostPosted: Tue Oct 14, 2003 7:17 am    Post subject: Recovering from partial hard drive failure Reply with quote

Last week my hard drive started to fail. I noticed the machine began to behave strangely (some applications stopped responding for a few seconds at random times), and fsck complained of errors. A scan using the drive manufacturer's test tool confirmed my worst fears.

The first thing I did, seeing as the system was still bootable, was to take a backup of /home onto another machine using tar and scp. Luckily, I had a spare hard drive of exactly the same size, so I then set about trying to copy the data from the dying drive to the good one. Outlined below is the what I did to bring my system back to a working state. Hopefully this will help anyone else who has a still booting but physically damaged hard drive containing a system they'd rather not have to reinstall. NOTE: I take no responsibility if you screw up your system even further with this information, this is all at your own risk.

Firstly, I needed a Linux bootable CD with the right tools. SystemRescueCD is just the thing - a Gentoo LiveCD with a number of useful tools for recovering, repartitioning or imaging a system.

The plan was to use sfdisk to transfer the partition table, and then dd to transfer each partition separately. As I discovered, however, you cannot use the dd command alone to copy a partition on a drive with hard errors, as it will not write anything in place of the errors and so will truncate the partition, as well as take a very long time. The best tool for the job is dd_rescue (included on the SystemRescueCD), which works just like dd except it always writes an image of the same length with the readable data in the same position, as well as adjusting the block size down when it detects an error, so that you lose the minimum amount of data. Also, as with dd, because it is copying at a low level it doesn't matter what file system the partition is (NTFS, ext3, etc.)

With this done, lastly I needed to "reinstall" grub in the boot sector of the new drive. To do this, I used the boot disk I made during my last Gentoo install (very useful in this situation, though you can probably just run GRUB from the Gentoo install CD) and performed the same steps as during the Gentoo installation to install GRUB.

Procedure

To recap here is the procedure with all relevant commands. Be extremely careful - double check before pressing enter or you may write over the original drive by mistake! If you have other unrelated hard drives in the machine, you would be well advised to disconnect them before attempting recovery to avoid disaster.

1. If you can still access it, back up your personal data in /home (and possibly /etc as well) using tar onto another known good drive or another machine. Then boot the SystemRescueCD if you haven't already.

2. Copy the partition table (here, /dev/brokenhd is the damaged drive, and /dev/goodhd is the new clean drive to copy onto, don't mix them up!)
Code:
sfdisk -d /dev/brokenhd | sfdisk /dev/goodhd

3. For each partition, copy the data (takes a while):
Code:
dd_rescue if=/dev/brokenhdX of=/dev/goodhdX

4. Turn off the machine, disconnect the damaged drive and make sure the good drive is primary master (assuming IDE). Boot PC into Gentoo LiveCD or use the GRUB boot disk you made during Gentoo installation.

5. Reinstall GRUB (assuming /boot is /dev/hda1 as in the Gentoo installation instructions - if not, you should know what you're doing):
Code:
grub
root (hd0,0)
setup (hd0)


Using this method I was able to recover my Gentoo partition as well as a couple of Windows 2000 partitions and a Red Hat partition too. Unfortunately I still don't know what files were damaged (there were about 280 errors during the dd_rescue copy of my / partition, so with 512 byte blocks that's about 140KB of zeroes spread over about 20GB). So far though the system works fine and I haven't discovered any corrupted files. The next step of course is to wipe the dying hard drive and return it under warranty.

It is interesting to note that both PartitionMagic 8.0 and Norton Ghost 2001 failed to help me in this situation. PartitionMagic had problems with ext3, and Ghost died with "out of memory". However, had they even been able to start I suspect they would still have failed as they are not designed to work with damaged partitions.
Back to top
View user's profile Send private message
Malakin
Veteran
Veteran


Joined: 14 Apr 2002
Posts: 1692
Location: Victoria BC Canada

PostPosted: Tue Oct 14, 2003 7:29 pm    Post subject: Reply with quote

Quote:
It is interesting to note that both PartitionMagic 8.0 and Norton Ghost 2001 failed to help me in this situation. PartitionMagic had problems with ext3, and Ghost died with "out of memory". However, had they even been able to start I suspect they would still have failed as they are not designed to work with damaged partitions.
This is a good point, both products are designed to work with undamaged filesystems. I use ghost sometimes (I sell/fix computer) and I always run a windows scandisk before using ghost especially on ntfs filesystems since any errors regardless of how minor they might be can stop the process halfway through potentially wasting a lot of time since ghosting even a smaller drive can take over an hour and a scandisk only takes a few minutes. One nice thing about ghost and the fact that it copies file by file is you end up with an unfragmented partition when copying any partitions where it understands the filesystem.

Depending on the defect if you have a drive that's failing you can try pointing a desk fan at the drive to keep it cool, this can help in extracting your data.
Back to top
View user's profile Send private message
keanu
n00b
n00b


Joined: 02 Mar 2003
Posts: 15

PostPosted: Fri Oct 17, 2003 6:03 pm    Post subject: Reply with quote

find files w/ bad sectors
http://article.gmane.org/gmane.linux.kernel/155536/
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum