Saving a Failing Hard Drive with GNU/Linux

I came to find out that my mother’s computer’s hard drive was failing. Programs took a long time to open and the computer would suddenly reboot for no reason. I discovered that the hard drive had bad sectors, which means potentially lost data if it decided to quit before I could save the data onto a different drive. Various GNU/Linux-based systems saved the day.

I determined that the problem must have been a failing hard drive, although there was very little to go by, so I purchased a new one and began the copy process. I started with Clonezilla, which is a very good drive duplication utility, but it kept failing. At first I thought this was because of the bad sectors, but it may have been because the USB drive that I had connected would turn off after a while (perhaps it wasn’t getting enough power from the one USB port). I decided to try something different.

Within Linux there’s a program called ‘dd‘. This program can take a bit-for-bit backup of a drive and copy it to another. Since each bit on the drive is duplicated, it will also copy partition maps and boot sectors. Surprisingly, it also copies potentially bad data from within a bad sector, but this is easily fixed afterward. The problem again with dd is that if the external backup drive keeps disconnecting from the computer then I would always have to restart it. This is where a program called ddrescue saves the day

ddrescue takes the power of dd and gives it a memory. In the simplest configuration you would tell it what drive to copy from, what drive to copy data to, and where a log file can be found. If anything happens during the copy process, such as if a drive suddenly fails or stops responding, then ddrescue can continue where it left off because of the log file.

I was able to use the following command:

ddrescue -B -v /dev/sda /dev/sdb /mnt/log/ddrescue_logfile_AAAA-MM-JJ.log The “-B” option will display units of 1024 instead of 1000 for the number of bits copied. The “-v” option is for verbose mode. “/dev/sda” is the source drive that has the errors. “/dev/sdb” is the new destination drive, it can be a larger size with Windows Vista or later computers. The “mnt/log” location is a mounted folder that is not located on either drive. This can be a flash drive or, in my case, a network share. The log file is named “ddrescue_logfile_2012-02-19.log”. As long as this same command is used whenever the copy process is interrupted, the process will automatically continue where it left off, as if nothing ever happened.

Once ddrescue was complete (a long time later), I put the new drive in the computer and booted into Windows. Windows booted up and I was able to log in. I told it to do a chkdsk by opening the command prompt and typing “chkdsk C: -F -R -B” and rebooted. Windows found several bad files and fixed them during the reboot. Using Windows’ disk management tool I was able to extend the volume to fill the new, larger drive.

Later on I found out that Microsoft Office was unable to run due to the bad sectors being where an important Office file was located. I was able to use the Programs and Features Control Panel application to repair the Office install. I didn’t even need the Office disk (which you never get with new computers). Now everything works again. I do have to say that LibreOffice was used to supplement MS Office until I could find out the problem with MS Office and figure out a solution.

With this I have to thank the GNU/Linux developers, the creators of Clonezilla, dd, and ddrescue, Ubuntu for their live CDs, and the LibreOffice developers.

Latest Posts