dd: the ultimate disk cloning tool - gHacks Tech News

dd: the ultimate disk cloning tool

I recently had to clone a hard disk so I naturally turned to solutions such as Acronis True Image, but I discovered these did not work (the start-up disk claimed the clong was 'complete' when it blatantly wasn't) and I also tried copying the partition using gParted in Ubuntu but this froze at about 3%, due to corrupt data, which seemed not to be caught in a chkdsk.

I was about to give up hope and copy the files manually when I came across an extremely powerful, yet simple, Unix command: dd.

Using a Linux live disc, dd can be used to copy files, disks and partitions. It can output directly onto another disc or as an image (like an iso).

dd copies data byte-exactly, meaning it won't get stuck should it encounter corrupted or fragmented data.

dd is nicknamed 'destroy disk' as mistyping one letter can wipe your hard disk, so caution must be used.

To copy a hard disk, one would use the following command (whilst root):

dd if=/dev/hdx of=/dev/hdy

hdx is the input hard disk (to be copied) and hdy is the output hard disk (where it is to be copied to).

if = input
of = output

This is extremely important to remember and their names must be altered according to how they are on your computer (use a tool like gParted to find out your drive's paths). For example, your 'if' may be /dev/sdb whilst your 'of' may be /dev/sda, but this obviously varies according to how you want to use it and computer-by-computer so you MUST check. An extremely intelligent friend of mine accidentally wiped a hard drive using this command!

Another use would be to use it to produce a CD image:

dd if=/dev/cdrom of=image.iso bs=2k.

Debian Help has a more complete guide.

We need your help

Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.

If you like our content, and would like to help, please consider making a contribution:

Comments

  1. Paul. said on January 17, 2009 at 2:32 am
    Reply

    Hey Joe,do you know or those command also apply for openSUSE-11.1? And is it possible to change the command into, dd if=/dev/dvdrom of=image.iso bs=2k to write it to a dvd disk?

  2. What is Linux? said on January 17, 2009 at 3:41 am
    Reply

    if = input file
    of = output file

    That makes it easier to remember. And besides the nickname, what does “dd” really stand for?

  3. VD said on January 17, 2009 at 5:43 am
    Reply

    I always used Ghost as ist does have a boot-disk which lets you recover even without a running os. Seems to having difficulties with ntfs-partitions though (or my version is simply to old^^).

  4. LECHIFFRE FREDERIC said on January 17, 2009 at 1:03 pm
    Reply

    I think dd stands for disk dump

  5. What is Microsoft Windows? said on January 17, 2009 at 3:12 pm
    Reply

    @Paul: Yes

  6. Casey said on January 17, 2009 at 4:50 pm
    Reply

    This utility was originally “convert and copy,” however the name “cc” was already taken by the c compiler, so for some reason the author decided to make it “dd,” which earned its nickname “disk dump.

  7. Daniel Pataki said on January 17, 2009 at 7:31 pm
    Reply

    Isn’t that the most awesome thing about Linux?

    You search for an app, and then you realize there’s a command as “complicated” as “dd”. Totally aweomse Joe, thanks!

  8. Dotan Cohen said on January 17, 2009 at 7:34 pm
    Reply

    @Daniel:
    I know what you mean. I often find the CLI to be both easier to use and more intuitive than GUIs for many common tasks.

  9. rupert said on January 18, 2009 at 2:46 pm
    Reply

    Personally, I prefer clonezilla:
    http://clonezilla.org/
    Just as powerfull and opensource, and is has a nice GUI to boot.

  10. Casey said on January 18, 2009 at 5:16 pm
    Reply

    Clonezilla actually uses dd as one of it’s tools. Other tools it uses are ntfsclone for NTFS and partimage for just about everything else. The good thing about dd is that it will work regardless of file system type or if there are errors on the disk.

  11. Russ McClay said on June 2, 2009 at 8:11 am
    Reply

    dd is a common UNIX program whose primary purpose is the low-level copying and conversion of raw data. dd is an abbreviation for “dataset definition” in IBM JCL, and the command’s syntax is meant to be reminiscent of this.

    http://en.wikipedia.org/wiki/Dd_(Unix)

  12. Charles said on December 20, 2009 at 1:04 am
    Reply

    I am duplicating my TimeMachine drive now to a larger drive. Mac users might be interested to know that the drive identifiers can be found using DiskUtility.app — click on the volume and click the Info icon. I have a lot of drives attached and found mine were disk3s1 and disk7s1. As a sanity check I did the following:

    $ ls -la /dev/disk3s1
    brw-rw-rw- 1 root operator 14, 10 Dec 18 00:51 /dev/disk3s1

    $ ls -la /dev/disk7s1
    brw-rw-rw- 1 root operator 14, 17 Dec 19 16:46 /dev/disk7s1

    Note that the disk3s1 was mounted yesterday and the newer one was just plugged in today. This gave me some confidence I was doing the right thing.

    Finally, I had to unmount (eject) the two drives because I got the following warnings:

    $ sudo dd if=/dev/disk3s1 of=/dev/disk7s1
    dd: /dev/disk3s1: Resource busy

    $ sudo dd if=/dev/disk3s1 of=/dev/disk7s1
    dd: /dev/disk7s1: Resource busy

    The third time was a charm. I expect it to take an hour or so to complete. If something goes wrong, I’ll be back to tell you about it.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.