How to clone a partition or hard drive in Ubuntu (Linux)

Cloning a hard drive can be useful for backing up (byte for byte) or moving data to a new hard drive. In Ubuntu this is pretty simple, though it is important to pay attention!

We’re going to use a linux command called “dd“, a low level copying program.

So, how to clone a hard drive?

Let’s open up a terminal firstly. You can do this by:

  • opening up your accessories menu and clicking on terminal
  • opening your unity dash and typing in terminal, then clicking on it!
  • press ctrl-alt-t

Create partition to copy to

Get Gparted

For this we’ll need a program called Gparted (it can be done from command line but for the sake of simplicity we’ll use a gui). Gparted can be found on the Ubuntu live media (CD or USB). Alternatively you can download it by typing this command into a terminal:

sudo apt-get install gparted

Open up Gparted (from your accessories menu, unity dash or terminal)

Create partition to backup to (target)

You should now see a screen like this. Make a note of the partition you want to clone/backup (source/input file):

In this case, lets backup the Ubuntu partition, /dev/sdd5.

To create the partition we select unallocated space and click new:

My original drive was 80gb, so I need to create a new partition of the same size and click Add. You need to click Apply after to actually apply the changes you are making here.

Note: A gb (gigabyte) is actually 1024mb (not 1000) so make sure you input the correct size!

Make a note of the newly created partition (target/output file).

Now its time for the juicy work…

Clone the partition

There are 2 things we need for this:

  1. if (input file): /dev/sdd5
  2. of (output file): /dev/sdd6

In the terminal type:

sudo dd if=/dev/sdd5 of=/dev/sdd6

This will start copying your “if” to your “of”. It may take a while so be patient, there won’t be any output so keep the terminal open until you get your command prompt back again.

Cloning a drive

In the case of cloning a whole drive, the “if” here would have been /dev/sdd. The command would have been the same format but the “of” would have to be another drive or partition of capable size.

  • S Hodge

    Very helpful. This dd command is what I was missing in cloning my data.

    • http://www.sudo-juice.com/ Gareth Parmar

      Glad it helped.

  • Pingback: How to Clone a Hard Drive or Partition using GParted and DD | Wasamara

  • jb0nez

    What if I have bad sectors on the original? (It’s failing, with SMART errors, that’s why I want to clone) will dd skip those?

    • http://www.sudo-juice.com/ Gareth Parmar

      No, dd will copy them. have you tried repairing through the disk utility?