Hard drive crash

I didn’t post anything for a few days, sorry… I’ve been busy with a hard drive crash.¬†Indeed, my BIOS reported a SMART alert on my main hard drive, requesting a quick backup and replace. Even if ignoring the warning worked, I definitely had to consider it and move to a new drive… This has been the opportunity to learn a few things about rescuing tools. Nothing related to OpenViBE in this post, just feedback on what could be learned from this last two weeks.

I have been using Norton Ghost for partition cloning many years ago but have not used it recently. I’m not sure I still have a backup of this really great application anyway. Also, I’ve been reading about Linux’ tool dd here and there for several years now. I never tested it. So I decided this would be the way to go this time…

dd is basically a tool that copies the content of a file to another. On Unix systems, the hard drives and partitions can be seen as files such as the /dev/sdXX nodes. So basically, you can use dd to copy an entire disk to another or a partition to another. I googled many keywords to find out if the disk size mattered, particularly if it was possible to copy a given disk to a bigger one. Obviously, this is possible… The rest of the disk would be seen as unallocated.

Now, I also had to google and visit dozen of pages to understand what switches should be used. I found out three options to add to the -conv switch : noerror, sync and notrunc.
noerror tells dd not to stop the copy if a read or write error happens (default stops at the first error !).
sync tells dd to keep the read and write offsets synchronized (if an error occurs while reading, dd does not copy anything but keeps moving the write offset).
notrunc tells dd to continue copying even if the content of the partition or disk is empty.

I also searched some information about the -bs (block size) switch to find an optimal value. When using two different devices as source and destination, it seems like a block size of 4 kilobytes is optimal on recent hardware (understand less than 5 years).

Here we go, I booted an ubuntu live cd, opened a console and ended up with a command line looking like this one :

$ sudo dd if=/dev/sda of=/dev/sdb -conv=noerror,sync,notrunc -bs=4096

Of course, I expected a working copy of my hard drive before going to bed… so I watched a couple of episodes of my current favorite TV series… But I finally had to surrender. This process is very long (as in veeeeeery long) and is even longer (as in even looooooonger) when read errors occur… And they occurred ! Indeed, it took 7 hours to copy my 500 gigabytes drive ! dd does not display any progress information so I could not know about this at the first run… I googled again to find out if it was possible to have an idea of dd‘s progress… This is possible thanks to a specific signal you have to send to dd. Find dd process id and send it the USR1 signal. This will force dd to output its progress to stderr.

$ ps ax | grep dd
$ sudo kill -USR1 dd_pid

Eventually, you could request an update every minute thanks to watch :

$ sudo watch -n 60 kill -USR1 dd_pid

At the end, only my system partition had some read errors… Most of the time, this is not an issue on Linux : all my data were on separate partitions including my home directory. Nice :)

To terminate this article I would like to mention another great software I didn’t use this time but tested a few months ago : testdisk. It is able to rebuild a complete partition table if it was corrupted… It goes through all the disk trying to find existing partitions and rebuilds a clean partition table from it.

Of course, all of this does not replace regular backups. It seems that NAS prices are dropping down. We probably should think about that for a clean and efficient backup@home solution…

Comments are closed.