English

Cloning your drive with the dd command (step-by-step guide)

Looking for a simple way to clone your drive? Once again your Ubuntu Live CD has the tools you need to backup your hard drive safely and for free. It takes some time, but it works just as well as Norton Ghost, but it lets you use applications from the Live CD in the meantime.

In this tutorial, I used a Ubuntu 9.04 Live CD as it already has all the tools required and supports my wireless card out of the box, but as long as you can have Gparted, you will be fine.

Some things you should know:

  • This command is safe when used safely, but make sure you understand it well before you do anything stupid.
  • Running a file system check (fsck) is highly recommended.
  • You might want to try this overnight, as it takes a lot of time and cannot be paused.*
  • dd will make a byte by byte copy of your input location to your output location. Unless you output it to a file (like an ISO image), you will have to dedicate your entire output drive to the backup, as it will overwrite any file system previously there.
  • Even if you already have a linux partition, use a Live CD it will result in errors in your backup. Altering files while they are being copied will create various problems.

Preparations:

1. Plug your external drive.

2. Boot on your Live CD and open GParted (System>Administration>Partition Editor).

 

3. Select your external hard drive from the drop-down menu in top right corner.

 

4. Once you are absolutely certain you've selected the right disk, erase every partition on your external hard drive. If you don't want to dedicate a hard drive to a file, you can also output the command to a file (just like an iso image). In this case, this step is not necessary.

5. Find the name of your source and destination. This can be found, once again, using GParted. In the top right menu, find the drives you copy from and to. Make sure you don't confuse the input source and output source or you are going to be in hot water!

 

The command

The dd command is a really simple and efficient command. Here's how it works:

dd if=[input location] of=[output location] conv=sync,noerror

conv=sync,noerror will prevent problems from read errors. You don't need it, but it sucks to see your backup halt 12 hours in because of a small error on your disk.

The input and output locations can be files, folders, partitions, media, anything. You can, for example, make an ISO image of a CD by setting the input as /dev/cdrom and the output as cdcopy.iso.

6. In our case, we will set the input to the drive to backup and the output to our external drive. Open a terminal and type your command using the locations from #5:

dd if=/dev/sda of=/dev/sdb conv=sync,noerror

(make sure you have the right locations!!!)

7. To restore your backup, simply invert if and of.

*It took me 12 hours to copy a 250GB, 7200rpm laptop drive to a 5400rpm external drive. This is because the dd command copies the hard disk byte by byte.

  1. Scot a dit (29 mai. 2010):

    Thanks Nic – gave it a go and it works fine – I was creating a clone of my bootable USB memory stick – this has saved me a lot of hassle and given me some peace of mind – much appreciated

    Scot

  2. jake a dit (14 juil. 2011):

    Hi
    I am an advanced dos and windows user, but a complete newbie with linux. I use EasyPeasy Linux (the only version EVER to run with no major issues just after installation). Just because it goes so well I thought I could switch to linux permanently (I do NOT love windows). One problem though… Disk image. System is as safe as it’s backup… The « dd » command sounds obvious and easy enough. Well, would be if my system wasn’t telling me that access to my sda1 is denied. Im working from prompt lokking like this: ubuntu@ubuntu:~$. I guess I should be at root for dd to work, but how to get there?

  3. admin a dit (14 juil. 2011):

    Hello Jake

    Have you tried running the command as root (sudo…)?

    You might also want to try rsync, since it’s much faster if you need to copy files and not individual bits. That’s what I use for my backups (both local and remote) nowadays.

Laisser un commentaire