Monday, September 14, 2009

Rescuing a dying hard disk

Linux provides a wealth of tools for various purposes. Often these tools are simple yet powerful individual commands that can also be recombined in a multitude of ways to perform every conceivable administrative task.

One such powerful tool is ddrescue, or gddrescue if you install from Ubuntu's repository. With this tool, you are almost guaranteed a successful rescue of a dying hard disk. I say 'almost' because there's always situations where a rescue is impossible or impractical to perform, but for most cases you'll fare much better than equivalent Windows-based tools.

Simply enable Ubuntu's universe repository to gain access to this wonderful tool for installation.

~$ sudo apt-get install gddrescue

Once installed, it's a simple matter of running the following line to perform a 'backup' of the dying hard disk onto a new healthy disk:

~$ sudo ddrescue -r3 /dev/sda /dev/sdb rescue.log

The option -r3 means retry up to 3 times, /dev/sda & /dev/sdb are source and destination drives respectively, and rescue.log specifies the log file to use for recording purposes. The log file comes in handy in case you need to stop & resume the backup operation for whatever reason, or if your backup task is somehow interrupted halfway. This process can take a long time depending on how large your hard disk is and how bad the damage.

After completing the backup, be sure to replace the defective drive with the new drive which now contains a mirror copy of your original defective drive. Windows users should run chkdsk /f on all partitions (or, chkdsk /r if you use Windows Recovery  Console) to repair any existing filesystem damage followed by sfc /scannow inside Windows to verify Windows system files.

As it happens, there's a distro that comes with the necessary tools built-in: Trinity Rescue Kit. It even has a script to run virus scan using various antivirus software.

Reference:

Rescuing files of dying discs.