Linux and the DD tool.

First things first, the DD command is a Unix command line tool that allows you to copy data from one place to another. A more accurate description from Wikipedia, “In computingdd is a common Unix program whose primary purpose is the low-level copying and conversion of raw data. According to the manual page for Version 7 Unix,it will “convert and copy a file”. It is used to copy a specified number of bytes or blocks, performing on-the-fly byte order conversions, as well as more esoteric EBCDIC to ASCII conversions. It can also be used to copy regions of raw device files, for example backing up the boot sector of a hard disk, or to read fixed amounts of data from special files like /dev/zero or /dev/random.

Wow! That’s a lot of fancy words! If that last part made little or no sense, ignore it and move on, I will explain a little bit at a time one of the many ways we can use this powerful tool.

I was going to write this as a how to a how to for Intel employees on how to clone a Linux disk. Apparently no one cares for Linux as much as I do. So I thought it would be easier to use the famous Linux DD command line tool to copy disks, but found that Clonezilla is much easier to use. And since I don’t like wasting information, I’ll share with what I wrote on dd.

Note! To be able clone a Disk Drive with Linux on there, be sure to boot into Ubuntu, live USB, CD, or natively. But before that, this command is for the disk you are about to clone. Make sure you are booted into the disk you want to clone.

sudo dd if=/dev/zero of=/home/ bs=8M

sudo rm -r /home/

First one creates a huge file that you will have to delete as root.(This command takes the free space and writes 0’s all over it making Disk to image faster) (also note that after a while Ubuntu will whine about not having enough free space this is normal, you will take care of this by deleting the file located in /home or anywhere else you decide to put it. Second command) It takes a long time to create the file so first command may take some time.

Now after it’s done, to start cloning that disk! This method is disk to disk. Plug the Source drive and the target drive into the same machine and boot off of another disk or USB.

First off, let’s see if all three hard drives are there. The OS (USB) drive, the source drive, the cloned drive. Type the following into a terminal.

sudo palimpsest

(if this is not installed please connect Ubuntu to the internet and type “sudo apt-get install palimpsest” and try again.)

This powerful Gui program will list off the disks you have installed, click on one to see what it’s proper device name is and you may find something like this.

Ohh look, the Fujitsu one is the one I want to copy so this is the source drive!
Now we start cloning as soon as you know what /dev/sd? your drives are. (see top line where it says Device:?) The source and the target. We will be using the DD (Data Description) tool that take a while and lots of space, it’s free and it works so don’t whine.

sudo dd if=/dev/sda conv=sync,noerror bs=64 of=/dev/sdc (This does the actual disk to disk) DO NOT COPY AND PASTE THIS COMMAND, READ BELOW!

Wow that’s a killer! In my case, this is what I had to do to clone the disk, but for you the command may be different. So YOU have to jot down out what your disk is listed under. eg, my source drive is on /dev/sda, but the to-be-cloned drive is on /dev/sdc

Let’s look at the command in detail and learn from it.
sudo is the administrator Privileges.
dd is the program that does all the work.
if=/dev/sda is grab from this disk.
conv-sync,noerror is to skip all errors.
bs=64K means copy in 64K blocks, this speeds things up a bit, usually.
of=/dev/sdc is put it here.

And remember, capitalization is important, the Terminal will also check for spelling mistakes and grade you one them.

If you paid attention to the disk utility that listed my disks, we could see which disks are what. Also please note that the source drive has to be smaller or the SAME EXACT SIZE to be cloned. That’s how it is. Using the method described above 80GB of data should take no more than 45 Minutes even on laptop spinning disks. I’d like to try this on SSDs.


If you want to save an image instead of clone it. You need to do this command instead.

dd if=/dev/sda | gzip > /home/disk.img.gz

(if you do it like this, it will drop the image file in your /home folder. If you still don’t know where that is, please don’t touch Linux.) Also keep in mind that this is going to compress the image while copying it, saving you a lot of space, but it takes twice as long to save.

dd if=/dev/sd? | gzip > /media/images/disk.img.gz

(if you do it like this, it will put it in this /media/images directory, that’s an extra Hard drive I plugged in to store my images.) That’s the only difference in this command compared to the last one.

To restore a saved image do the following command.

gzip -cd /home/disk.img.gz | dd of=/dev/sdc

(This command is a little simpler since we don’t have to worry about copying any bad sectors, the hard drive will naturally ignore them.

And that should be it. Keep in mind, in my tests the only commands that worked reliably where the ones where did to disk. But the DIsk to image ones where not very reliable for me, could have been something else I’ve done, but before you rely on any of this for your backup needs, make sure that this works by doing some trial and error testing. Have fun!
Sources for this info.


About Zerin

But can you show me the source code?

Posted on February 10, 2012, in Computers and Internet. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s