Simple clear advice in plain English

Duplicating partitions

How to use dd and ddrescue to back up your data

A few months ago we looked at duplicating partitions as a way to back up your data. A number of readers have expressed an interest in knowing more about this, so I’m going to look at it in a little more detail this month.

As a reminder, we used the ‘dd’ and ‘ddrescue’ tools to perform a cloned image backup, and the ‘partimage’ tool to create a special image format. The difference between the two types is as follows: the first copies every single byte of raw data from the hard drive’s partition, thus creating a backup image of exactly the same size; the second copies only the used data from the partition and then compresses the result, leading to a much smaller file.

With the first method, the type of filesystem you are backing up is irrelevant, as a duplicate of the original is made. With the second method, the partimage tool must be able to understand the filesystem used on the partition in order to extract and back up only the used data.

The ‘dd’ and ‘ddrescue’ tools will copy data from any source to another, byte by byte. This could even be a single regular file, thus doing the same job as running the ‘cp’ command. Linux and other Unix-based systems treat everything as a file, and so a partition, or indeed a whole hard drive, can be duplicated in the same way. It is therefore possible to clone a hard drive, either as a backup, or to use the second drive in another machine. An example command, one you should not enter yourself, is:

$ sudo ddrescue /dev/sda /dev/sdb

We are using the ddrescue command instead of dd, simply because it does everything ‘dd’ does, but shows more information about progress and errors, and is more resilient. You can install this command in Ubuntu by running:

sudo apt-get install gddrescue

Running this command will copy every byte from the drive found at /dev/sda to the one at /dev/sdb. It makes sense therefore that the second drive should be an identical model to the first, as every byte, even those that are untouched, and not even in a partition, will be copied across to the second, overwriting whatever is currently there. The duplicate will boot just like the first, with every file and operating system intact. An installation of Windows will boot too, though be aware that it can lead to activation problems; there will be no such issues with Linux.

The usual method of backing up in this fashion is per partition. This is where the choice of ddrescue or partimage comes in. Where space is no issue, or the filesystem to back up is almost full, ddrescue is probably the wiser and simpler choice. It is guaranteed to work on any filesystem as a fail-proof backup that can easily and very quickly be restored.

However, one particular advantage of partimage is for freshly installed and configured operating systems. For instance, if you have just installed a copy of Linux with all the updates your partition will probably only be using two to three gigabytes. You can make a clone of the partition with partimage, taking only a couple of gigabytes of disk space on another partition or drive, so that if you later decide to reinstall the operating system, you can go straight back to this fresh installation image. You could even write out the image file onto a blank DVD.

Partimage works with any Linux filesystem and Fat 32. For Windows installations using NTFS, which is almost any since Windows XP, an alternative to partimage, ntfsclone, is required. This is a command-line tool that performs the same job ­ it creates a special image of only the used data, which can then be restored back. An example of this command is:

# ntfsclone --save-image -o backup.img /dev/sda1

Reader Comments

   

Add your comment

All fields must be completed. Your email address will not be displayed or used to send marketing messages.

All messages will be checked by moderators before appearing on the site.

See our Privacy Policy for more information.

Related articles

Fix-virtualbox-problems-in-ubuntu

Get VirtualBox working in Ubuntu Linux

Virtualbox is great if you need to get Windows apps working in Ubuntu but it may need help to get working

myunity-customiser-utility-for-ubuntu

Tame the Ubuntu 11.10 Unity interface with MyUnity

Customise how the Unity desktop looks and works

Organise files easily illustration

Organise and keep track of files with filters, labels and star ratings

While Windows' folder system gives a serviceable way to organise files, a free tool indexes files automatically and arranges them in a calendar format

Question & Answer

Q.How do I store musician and other information about...

> Read the answer

Q.Why can't my browser find the website address I typed...

> Read the answer

Q.All updates have been downloaded, so why won't Windows...

> Read the answer

Best deals on the web

img

Apple MacBook Pro (MC724LL/A)

£999.99- Buy it now

img

Sony Vaio VPCF23P1E/B

£679.98- Buy it now

img

Sony Vaio VPCEH1J1E/W

£349.99- Buy it now

Great benefits for subscribers!

Poll

Which is your preferred web browser

Jargon Buster

Computing terms explained in plain English

Router

A device used to connect more than one computer or other device to the internet.

Great shopping deals from Computeractive