Recovering hard drive data
Anyone who has worked on computers has inevitably heard the sound of a hard drive “clunking”. Those who have heard it know that it is the undeniable sound of the hard drive getting ready to die. More often then not this sound comes just after the point in the hard drives lifetime where Windows stops letting you read and write data to the drive. At this point your heart starts to pound and you rack your brain for the answer to the only question that matters at this point.. When did I last backup my data? Not to worry though, there is most likely a way to recover at least some of your data from the hard drive using Linux’s dd command.
Most windows users don’t realize it but Linux has a wide variety of tools that can help windows users out of a jam. In the case of a dying hard drive this tool is called dd. dd is a common unix program that is included in almost every unix/linux distribution. dd’s sole purpose in *nix is to provide basic low level copy of conversion of raw data. In basic terms that means it copies your hard drive sectors instead of copying files like you would in windows. A hard drive sector holds only a bit of information on the hard drive where as a file can be spread across many sectors.
By now your probably saying “thats fine and all but I don’t run linux. I run windows” and thats perfectly fine. The Linux gods have created a helpful thing called a Live CD. Live CD’s allow you to run a operating system completely from a cdrom without needing to install it. So to recover the dying hard drive you will need to get yourself a copy of DSL, Damn Small Linux. DSL is a small enough Linux distribution that can be loaded from almost any type of media including CD’s and flash drives. If you don’t have a computer to download DSL and burn it to CD then have a friend do it for you or ask your local computer store.
Once a copy of DSL is obtained you will need to find another hard drive to copy the data too. The new hard drive should be the same size or larger then the drive that needs to be recovered. Once the new drive is obtained, connect both drives to the computer placing the dying hard drive as the primary drive. Connect the new drive as a slave if using IDE or install it on to the 2nd controller if using sata. This helps ensure the dd commands below are correct.
Now that the new drive is installed in the machine and the DSL CD is in the drive, start the computer and boot from the cdrom. If DSL boots properly then you will be looking at a nice Linux desktop. An icon should be on the desktop or in the menu called “Terminal”. Double click the icon to get a terminal window to open. It will look similar to a dos command prompt window in Microsoft Windows.
We want to start dd and get the drive copy going. To do this you will need to know what type of hard drives you have in the system. Since you just connected a new hard drive or a replacement drive you should already have this bit of information. In Linux the hard drives are labeled as “/dev/” and then a drive prefix and a drive letter. The prefixes are pretty standard, the prefix should be “hd” for an IDE hard drive and “sd” for data. The drive letter is the identifier for where the drive is located on the controller. The primary drive would be “a” and secondary would be “b” and so on. Putting this information together with the setup from above, should cause a primary sata drive to be located at “/dev/sda”. If using sata hard drives you can test this by typing “ls -lsa /dev/sda” into the terminal, you should see the following result:
0 brw-r—– 1 root disk 8, 0 Feb 14 09:14 /dev/sda
If the result looks the same then we are ready to learn about using dd. If not, double check the command settings and drive placement on the controllers. Make sure before continuing that you know the locations to the hard drives in Linux. The last thing anyone wants to do is find out they copied over the wrong drive and now their data is gone forever.
Using dd for drive copies is fairly simple. There are two parameters that need to be specified for the utility to copy the drives. The parameters are “if=” and “of=” these stand for “input file” and “output file”. The “input file” is the source drive that is to be copied and the “output file” is the destination drive. The dd command should look like the following based on the above information if using data hard drives:
dd if=/dev/sda of=/dev/sdb
Running that command right now however will result in nothing happening. This is because the Linux administrator has to run any executive level commands such as dd. This is done by filtering the command though the “sudo” command. The entire command should look like this:
sudo dd if=/dev/sda of=/dev/sdb
Typing the above command into the terminal window should cause the hard drive lights to go solid instantly. This is a sign that data is being copied. dd currently provides no progress bars or status indicators while it runs. The hard drive light is the only indicator that it is processing data.
The size of the source hard drive and the condition the drive is in will determine how long it will take dd to copy the data. For the size hard drives that are being in stores today, 80GB - 1TB, dd normally takes a few hours to get complete.
Once the copy is completed dd will exit returning the terminal window to a command prompt. dd will also provide final stats before it exits. The stats will indicate how many sectors were copied and any errors occured. If no errors occured, remove the dying hard drive and boot from the new hard drive. Hopefully there were no issues and disaster has been avoided.
The only catch to the dd recovery process is that the partitions on the new hard drive will be exactly the same as the old hard drive. This only tends to cause a problem if a larger replacement drive was purchased. Any additional space will not be allocated on the new drive. This space can be allocated by creating a new partition or by using another linux tool called Gparted to resize the new drives partitions, however article is for another time.