Monday, June 21, 2010

Command line hard disk cloning with gddrescue

There's a wealth of command line tools just waiting to be explored. Take gddrescue as an example. It's a nice little open source tool that can be used as both a simple disk cloning tool, yet at the same time it's main purpose is that of hard disk rescue.

gddrescue doesn't come with Ubuntu, so to install do the following:

~$ sudo apt-get install gddrescue

It's a very small package hardly noticeable with today's hard disk capacities, but it packs the power you just might need someday to save your bacon.

To use, simply do:

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

A little explanation is in order.

Although the package is called gddrescue you use it with the ddrescue command. This is due to there being another package by the name ddrescue. You use dd_rescue with that other package and it's supposed to perform the same function. Confusing I know but I'm not the packager and I don't question the packager's wisdom.

Well, actually I do but I'll leave it at that.

Next, -r3 tells ddrescue to retry 3 times if there are any errors. Only the sectors with errors are retried. If you're simply cloning a healthy drive it's safe to omit that. rescue.log is the log file to use when recording current progress. That comes in handy if you need to interrupt the copying process and resume later (using the same command line).

/dev/sda and /dev/sdb refer to input and output devices respectively. You'll need to replace it with what's appropriate for your computer. The order is input file first followed by output file. In other words, the command ddrescue /dev/sda /dev/sdb means copy contents of /dev/sda to /dev/sdb destroying the contents of /dev/sdb.

To see what storage devices are currently available you can do the following:

~$ sudo fdisk -l

That will show you all attached devices along with partition information, device capacities and much more.

Related posts:

Speed up your disk cloning process