How to clone a partition or hard drive in Ubuntu (Linux)
November 6th, 2011 | By: Gareth Parmar | How to’s | No comments »Cloning a hard drive can be useful for backing up (byte for byte) or moving 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.
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-del
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) or you can download it by typing this in 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 create partition (target/output file)
Now its time for the juicy work…
Clone the partition
There are 2 things we need for this:
- if (input file) – /dev/sdd5
- 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” in here would have been /dev/sdd. The command would have been of the same format but the “of” would have to be another drive or partition of capable size.