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

r-370-synology-ds112j-right-45

Synology Diskstation DS112j

Lots of impressive features, but expensive for a single-bay NAS enclosure

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

Question & Answer

Q.Why are some of the keys on my keyboard doing strange...

> Read the answer

Q.Is my phone’s Bluetooth any use?

> Read the answer

Q.Can I switch boot drives so that I can work on older...

> Read the answer

Best deals on the web

img

Apple iMac 21.5" (MC309)

£926.40- Buy it now

img

Dell Inspiron 620 ST Intel Core i3-2100 3.10GHz / 3GB / 500GB / DVDRW / Win 7 Home Premium

£329.00- Buy it now

img

ZooStorm 7877-1023

£386.38- Buy it now

Latest issue & subscription deals

Poll

Are you concerned about viruses that target mobile phones?

Jargon Buster

Computing terms explained in plain English

Bittorrent

A technology for downloading files. Allows even very large files to be downloaded quickly.

Great shopping deals from Computeractive