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
.
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.
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)
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.
Personally, I prefer clonezilla:
http://clonezilla.org/
Just as powerfull and opensource, and is has a nice GUI to boot.
@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.
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!
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.
@Paul: Yes
I think dd stands for disk dump
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^^).
if = input file
of = output file
That makes it easier to remember. And besides the nickname, what does “dd” really stand for?
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?