SEARCH

How-To Geek

Clone a Hard Drive Using an Ubuntu Live CD

Whether you’re setting up multiple computers or doing a full backup, cloning hard drives is a common maintenance task. Don’t bother burning a new boot CD or paying for new software – you can do it easily with your Ubuntu Live CD.

Not only can you do this with your Ubuntu Live CD, you can do it right out of the box – no additional software needed! The program we’ll use is called dd, and it’s included with pretty much all Linux distributions. dd is a utility used to do low-level copying – rather than working with files, it works directly on the raw data on a storage device.

sshot-1

Note: dd gets a bad rap, because like many other Linux utilities, if misused it can be very destructive. If you’re not sure what you’re doing, you can easily wipe out an entire hard drive, in an unrecoverable way.

Of course, the flip side of that is that dd is extremely powerful, and can do very complex tasks with little user effort. If you’re careful, and follow these instructions closely, you can clone your hard drive with one command.

We’re going to take a small hard drive that we’ve been using and copy it to a new hard drive, which hasn’t been formatted yet.

To make sure that we’re working with the right drives, we’ll open up a terminal (Applications > Accessories > Terminal) and enter in the following command

sudo fdisk –l

screenshot_001

We have two small drives, /dev/sda, which has two partitions, and /dev/sdc, which is completely unformatted. We want to copy the data from /dev/sda to /dev/sdc.

Note: while you can copy a smaller drive to a larger one, you can’t copy a larger drive to a smaller one with the method described below.

Now the fun part: using dd. The invocation we’ll use is:

sudo dd if=/dev/sda of=/dev/sdc

In this case, we’re telling dd that the input file (“if”) is /dev/sda, and the output file (“of”) is /dev/sdc. If your drives are quite large, this can take some time, but in our case it took just less than a minute.

screenshot_002

If we do sudo fdisk –l again, we can see that, despite not formatting /dev/sdc at all, it now has the same partitions as /dev/sda.

screenshot_003 
Additionally, if we mount all of the partitions, we can see that all of the data on /dev/sdc is now the same as on /dev/sda.

screenshot_004

Note: you may have to restart your computer to be able to mount the newly cloned drive.

And that’s it…If you exercise caution and make sure that you’re using the right drives as the input file and output file, dd isn’t anything to be scared of. Unlike other utilities, dd copies absolutely everything from one drive to another – that means that you can even recover files deleted from the original drive in the clone!

Trevor is our resident Linux geek, but always keeps his eyes open for neat Windows tricks too.

  • Published 06/9/10

Comments (42)

  1. slate

    Wow, this is really cool. I’ve had drives that Symantec Ghost wouldn’t make images of or would bomb during the image creation process. I’ll give this option a try and see if it can succeed where Ghost failed.
    Thanks “HowToGeeks”!

  2. Strodtbeck

    I love the live CDs especially for this very reason. You can get into a Windows system and do what you need. Windows is still in the weeds as far as total disk management goes compared to Linux.

    Nice tutorial.

  3. Scott

    In the example above, if sdc was larger than sda would the additional size show as free space after the clone?

  4. Hari

    I had cloned my 250 GB HD to a new 1 TB HD using ‘dd’. After that Ubuntu does not login. The MBR [Grub] and Windows 7 do start without any problem and all the programs are working perfect under it. When I boot to Ubuntu, the login screen just keeps displaying ‘Automatically logging in…’. On the first boot from the cloned HD, Ubuntu displayed that the /home is not found and offered Check/Skip/Ignore and I selected Check. After that the message is not shown. Another weird thing is that at logon, the system does a log off and display a warning that the Power Manager Applet is not responding and asks for Log off anyway.

    Is it possible to correct this? I have the old HDD intact with me.

    The complete thread is available in http://ubuntuforums.org/showthread.php?p=9428029#post9428029

    Thanks in advance.

  5. Fran

    One thing to avoid is using dd to copy a disk to another disk having a different geometry (i.e., a different number of cylinders, heads, or sectors/track. Even if both disks have equal capacity (or the second disk has greater capacity), the different geometry can prevent software from being able to access the data on the copy. For instance, a boot loader that stores the location of the kernel using LBA (logical block addressing — http://en.wikipedia.org/wiki/Logical_block_addressing) will fail to find the kernel on the copy. Some filesystems allocate data in cylinder groups (http://en.wikipedia.org/wiki/Unix_File_System), but the different geometry of the copy distorts the location of the original cylinder boundaries and makes the filesystem unusable.

    Also avoid using dd to copy a disk to an equal sized disk having the new 4096-byte sectors.

  6. Newbie

    Nice one, but of course this does only work on HDs of the same size… or?, what will happen when used to copy from a smaller one to a bigger sized HD??

  7. Newbie

    uppss… sorry, I overlooked the paragraph. Got it now.

  8. Spydeyrch

    Nice little program. I can already see why I would use it. Thanks for the article!! One quick question: You mentioned that dd can only copy from a smaller to a larger drive. I am assuming that it can also copy to a drive of equal size as the if (input file) drive. Would that be a correct assumption? Also, what if I have a 1TB drive, the input file, but the data on that drive only takes up less then 500GB of that drive, could I use dd to clone that data and output it to a 500GB drive? The amount of data from the if would be less than the capacity of the output drive. Hopefully that is clear enough. Thanks!

    -Spydey

  9. Trevor Bekolay

    @Scott

    No, because dd would copy over the partition table, it would partition the drive as being the same size as sdc; however, you could then open up gparted or something like that and expand the partition(s) to fill the extra space.

    @Hari

    Like people have said in the other thread, I would try booting the new drive without the old drive plugged in. You might also want to try booting into a recovery console and running fsck on the drive.

    @Fran

    Right, good point! Some things can be fixed post hoc, but it’s too complicated to bother with, I’d say.

    @Spydeyrch

    Oh, yes, equal sized drives are fine, which is what I did in the article.

    With dd, it would copy the entire 1 TB drive, even if 50% of it is just zeros. You can force it to stop at 500GB, using something like this:
    dd if=/dev/sda count=500000000 of=/dev/sdb
    But I’m not sure if that will really work, because data isn’t necessarily stored contiguously from start to finish.

    There are other drive cloning utilities, like Clonezilla, that will only copy the actual data, and should be better suited to the type of thing you’re doing.

  10. Fran

    dd can read from a device and write to a file, so if you have, say, an 80 GB drive at /dev/sda and a 1 TB drive with more than 80 GB free in its filesystem, you can backup your 80 GB drive to a file with:

    dd if=/dev/sda of=/home/fran/mybackup

    as long as /home/fran/mybackup is on the 1 TB drive (for obvious reasons, one should never dd a drive to a file on that drive).

    You can restore the drive from the backup with:

    dd if=/home/fran/mybackup of=/dev/sda

    This works regardless of drive geometry, because the file just contains the raw sector data which is being written back to the very same drive it came from.

  11. Fran

    Oh, and dd can make ISO images of CDs and DVDs:

    dd if=/dev/cdrom of=/home/fran/cd.iso

    But you can burn a disc by reversing the arguments. :) You need a tool like ImgBurn to do that.

  12. Fran

    Oops. I meant:

    But you CAN’T burn a disc by reversing the arguments.

  13. Trevor Bekolay

    @Fran

    I should mark those comments as spoilers for my next few articles!

  14. panoet

    Yupz, I don’t know this before. Whereas I’m linux user :(
    Thanks for your useful post. My question, may I backlink this post to my blog? I’ll put your link there, of course.

  15. Frank

    I tried this with a windows boot disk and although it mmade what looked like an identical copy the new disk would not boot.

  16. Trevor Bekolay

    @ Frank

    By Windows boot disk do you mean a hard drive, CD, floppy disk? If it’s hard drives, are the source and destination hard drives the same model? There can be some complications if you’re using dd to clone hard drives with different internal geometries…

  17. Anon

    Any easier methods (w/GUI) that can be used to clone Macs?

  18. John Fury

    A request please; A howto for cloning hard drive with different size… Like; a 1TB to a 500GB.

    The 1TB contains only the fresh installation of Linux (however, i already ‘apt-get update’ it)and i need to copy that to a 500GB.

    I’m searching the internet for that but i’m having a hard time looking over…

    Please Help… thank you.

  19. Jack

    If your system hasn’t used any of the last 500G of space, you might be able to get by with using dd as described above. It might be safer to reduce the size of your partition from 1T to 500G, then dd the drive
    up for the first 500G.

    No garuntee, but it is something to try.

    You can restore the 1T partition to its full size once you like your ‘small’ drive!

    Personally, if it hasn’t had much done to it, it is easier to do a second fresh install, unless I am making a ‘golden image’ for multiple future installs.

  20. Neill

    John Fury wrote:
    “A request please; A howto for cloning hard drive with different size… Like; a 1TB to a 500GB.”

    Well, first defragment the drive that you are cloning, then (using gparted during a live linux CD session) shrink the drive size to less than the size of the drive you are cloning too.
    Using a tool like Macrium Reflect (free edition) make a full backup of the shrunken drive partition to an external hard drive.
    Using Macrium Reflect again, clone the image you just took to the new drive.
    Boot up the live linux cd again and using gparted “expand” the partition on the new drive to take up as much/all space desired.

  21. JP

    Nice article! So clearcut and precise! What if the original drive has errors on it? Should the “conv=noerror” option be used? Or can the errors be fixed on the new drive (the clone) later? Or will the bad sectors just automatically be skipped? Or should dd_rescue be used instead?

    Specifically, here is my situation: I have a dell laptop dual boot XP pro and Ubuntu Jaunty. The hard drive (160gb) seems to be failing and chkdsk and gparted both find about 12 bad sectors. So I want to buy a 500gb drive and clone the 160gb original drive onto it, hopefully preserving all my OS’s, applications, and data. Then put the new drive into my laptop. I’d hate to have to start from scratch as I did that a few months ago to rebuild the windows side and make it dual boot. *side note: I wanted to rebuild windows because the original dell install was terrible from the get go (with bloatware etc), and it had become so WinRotted it was time anyhow… ;)

    Drive info:
    old: Hitachi 160gb dell e1505 OEM HTS541616J9SA00
    new: Hitachi 500gb travelstar 7k500 (considering this one, or maybe a seagate momentus, or WD scorpio black)

    The old drive works fine mostly, but makes strange noises and seems to slow down windows severely from time to time (about once a month) and then doing “chkdsk \f \r” seems to fix it. So I want to go ahead and replace it while its still on the up and up.

  22. James

    sudo fdisk –l was entered in terminal and the response is

    (unable to open -l) !! now what do I do?

  23. James

    found the cockpit trouble

  24. Jason

    Wow, great stuff. I’m in the process of building a new computer with two identical drives, one for use and the other for backup.

    On the first drive, I will have a windows partition and a linux partition. My linux distro uses Grub2. If I use the above command to clone the drive, will this copy the MBR, and everything needed to keep it working the same? If my main drive fails, I would like to simply change the main drive in the bios and restart the computer to have myself back up and running the same. Thanks!

  25. newbieDD

    Hi, I used this article to clone a laptop hdd. but now i want to do something completely different. Can i clone a desktop hdd to be used in a different desktop? all the hardware is completely different. i was gona try it for fun just to see the outcome. if it works then i have a bigger use for it.

    so is it possible to know whther i can do this with dd pls, using the above mentioned method or a different method? something tells me this is never gona work.

  26. Rich

    For anyone having the same problem as James:-

    “sudo fdisk –l was entered in terminal and the response is

    (unable to open -l) !! now what do I do?”

    In answer to James (although it appears he doesn’t need the help any-more)
    You need to replace the “–” before the “l” with the minus sign so that it reads

    sudo fdisk -l

    The code in the original article could do with changing so that other people aren’t tripped up by this.

    Also:-

    I wish people would clarify what they did to solve their problem, rather than just telling everyone that they fixed it.
    There are plenty of occasions where I’ve had a problem that someone else has encountered before me and that they have solved, but instead of saying what they did to solve said problem they simply say – It’s alright now I know what to do!
    What use is that?
    Help a fella out would you?

  27. Cherv

    Just used this to move a Window 7 Pro install from a 64 GB SSD to a 120 GB SSD using Ubuntu 11 Live on USB Flash drive. Took a couple hours via a USB-SATA connection, but worked great. On first boot of Windows it wanted to ‘restart to apply changes’, not sure what changes but it worked fine on second boot.
    I was planning to use gparted to extend the partition into the unallocated space, it didn’t want to do this, possibly because linux sees the Windows NTFS partition as two partitions i.e.) /sdc2 (boot) and /sdc3.
    But, I was able to just use Windows 7 Disk Manager to extend the partition into the unallocated space.
    Lots of free space again!

  28. Don

    Tried cloning one 1 TB HD to another using this method, but it would have taken about 30 hours. cpio, cp -a, or Clonezilla might be better choices for such large media. dd definitely works great for smaller media.

  29. sean

    Are there any good tutorials for CloneZilla? I’ve looked around a bit, and didn’t see anything that showed how to clone only the data. I don’t want an 130GB image when only 30GB of the drive is used….

    And is CloneZilla it’s own operating system or do you install it in your Ubuntu Live USB?

    As a side note: I tried to boot up into a Ubuntu USB and copy ALL of the files in a WinXP hard drive to an external USB drive (Just using the copy and paste option of Ubuntu). When the WinXP hard drive got a virus I tried booting up into Ubuntu, Purged the files from the local hard drive (delete, not move to recycle bin), and copied all files from external USB hard drive to the local hard drive (again just copy and paste). Reboot into windows.

    It kind of worked, but, I had all kinds of problems. Not all the installed programs still worked, had to use the Repair installation options from the “Add/Remove Programs” on several programs.

    Why didn’t that process work? Ubuntu sees ALL of the files, doesn’t respect any windows files, etc. So it should be a file for file match. So if all of the files are there and duplicated correctly, what’s the problem?

  30. Steve Faulkner

    Thanks guys this article was spot on , and really bailed me out …. your not geeks … you rock !!!!!! Thanks !!!!!

  31. Jarom

    To have a progress indication and progress bar while using dd, install the “pv” program and do the following command instead:

    pv /dev/sda | dd of=/dev/sdb

    or, if you’re not running as an administrator:

    sudo pv /dev/sda | sudo dd of=/dev/sdb

    (Make sure you pick the right devices! Don’t just copy-paste!)

  32. Jarom

    Also, to make it go faster, use a bigger block size for the command. From my limited experimentation, 64K seemed to be big enough to max out my SATA bandwidth, and about doubled the speed relative to the default dd block size.

    sudo pv /dev/sda | sudo dd of=/dev/sdb bs=64K

  33. Jarom

    If you want to do a backup instead of a copy, then do something like this:

    sudo pv /dev/sda | sudo dd bs=64K | gzip -c > /media/backups/full_sda_backup.img.gz

  34. Jarom

    Found an even better solution. From an Ubuntu Live CD (or USB drive),
    Install ddrescue:

    sudo apt-get install gddrescue

    Then you can run the following command, which both gives progress, as well as other nice features, like retries, stop and restart, etc.

    sudo ddrescue -v –block-size=64Ki /dev/sda /dev/sdb ddrescue.log

    (input is the first device specified, output is the second; also works on partitions)

    The ddrescue.log will keep track of which blocks you have tried/failed, and then if you re-run the command, it will only do those blocks that you need to. Also, it will retry blocks if an initial read fails.

    As always, MAKE SURE YOU CHOOSE THE RIGHT INPUT AND OUTPUT DEVICE!

  35. Hendra

    how about cloning just 1 partiiton, instad of the entire disk ?
    for instance /dev/sda1 . .
    also windows has been installed on the destination disk (/dev/sdb1) and I wanna put the clone on /dev/sdb2

  36. ggcc

    Thank you very much for your instructions. I have used dd, it took me 17hours 20 minutes to clone full 2TB hard drive FAT format (usb2 to usb2). Clonezilla won’t work to clone my 2TB (error is right at the beginning just right before cloning) beside if I use Clonzilla to clone 2TB by boot CD, I cannot use my computer so dd is a good choice. The same 2TB cloning if I use Acronis it took me 31 hours.

    Clonezilla is good for my backup image the whole drive 320G (ext4), then clone the backup to another drive 320G or larger it only takes about 40 minutes to backup/verify and about 30 minutes to clone about 50G data on the drive.

  37. Dave

    Is there any way to clone from a smaller disk to a larger disk that has different geometries? Or more specifically is there a way to fix the errors after a standard dd clone operation?

  38. Jarom

    @Dave
    To fix geometry issues after a clone to a larger disc, try using GParted, also from a Live CD. (see comments above. In Ubuntu 11.04, System -> Administration -> GParted Partition Editor.
    You want to extend the partition to fill the empty space. Should be pretty simple process. You might run into trouble if there are errors in the original disc.

  39. Jim Ketchum

    Hello,

    Thank you very much for this tutorial. I tried Clonezilla, and after copying to the new drive (Hitachi TravelStar 500g from a Seagate 250g) the process would hang at a certain point. I would then have to go back and reformat and partition the 500g drive and try again. This process (I am a newbie to Linux after years in the Windows world) seems to be working better. I’ll see what the end result brings Thanks for the help.

  40. Thomas Ulrich

    Thank you very much for this. It is truly the easiest way to clone a drive I’ve seen ever. It did take about 70,000 seconds :-) little under 20 hours for 1TB, but the new disk boots perfectly. Saved my a lot of time that I would otherwise have put into configuring my music server setup.

    Although everything appears to work I get:
    Partition 1 does not start on physical sector boundary (from fdisk -l see details below)
    Also “Disk utility says”: WARNING: This partition is misaligned by 512 bytes. This may result in very poor performance. Repartitioning is suggested.

    Do I need to worry about this?
    It may have something to do with minimum/optimal I/O size (the old drive was different than below).

    ~$sudo fdisk -l
    Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
    255 heads, 63 sectors/track, 243201 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disk identifier: 0×00040558

    Device Boot Start End Blocks Id System
    /dev/sda1 * 1 120855 970767756 83 Linux
    Partition 1 does not start on physical sector boundary.
    /dev/sda2 120856 121601 5992245 5 Extended
    Partition 2 does not start on physical sector boundary.
    /dev/sda3 121602 243202 976753664 83 Linux
    /dev/sda5 120856 121601 5992213+ 82 Linux swap / Solaris
    Partition 5 does not start on physical sector boundary.

  41. Kevin

    This process is not good if the hard drive you try to copy or to backup has a bad sectors in it, (e.g. the hard drive can’t access to a certain part of its cylinder or it says “I/O” error) because it halts and leave the cloning process unfinished.

    You can try the “ddrescue” in terminal, here is an example symtax:

    $ sudo ddrescue -v /dev/sda /dev/sdb

    or visit this link:

    https://www.linux.com/learn/tutorials/8225-clone-your-ubuntu-installation-onto-a-new-hard-disk

  42. Leo

    THANKS for the article. Yesterday I bought a new hard drive (750GB) and SATA enclosure kit (to be able to clone my original hard drive in one go). My laptop, an Acer Aspire 5610Z originally came with a 120GB hard drive, which got way to small after 4 years. A few months ago it ran Vista but I upgraded to Windows 7 Ultimate and disc space became a luxury, hence my decision to buy a new hard drive, especially now that I grew quite fond of the idea putting Linux on my machine in dual boot mode. Here is what I did to clone the 120GB (old drive) onto the new drive (750GB):
    1. I downloaded openSUSE-11.4-GNOME-LiveCD-i686.iso from http://software.opensuse.org/114/en
    2. I created a bootable CD with Windows Disc Image Burner under Windows 7
    3. I rebooted my computer (changed the boot order in the BIOS) and loaded openSUSE GNOME Live.
    4. I connected the new hard drive (750GB) – which I put into the HDD SATA enclosure – via USB
    4. I opened an XTerm session
    5. I checked which hard drive was which with: sudo /sbin/fdisk -l
    6. Once I found out the device name for my 120GB drive was (sda – so no surprise here) and for my 750GB drive (sdc) I started the cloning process with: dd if=/dev/sda of=/dev/sdc
    7. After just under 7 hours I had a 100% clone of my old hard drive
    8. I swapped the hard drives and started Windows 7 – no issue, however, Windows asked me to reboot so that changes to my hard drive could be applied
    9. Everything is working fine so far after this reboot

    Obviously no guarantee that it will work in any other case, maybe I just got lucky :-)

    THANKS to everyone who posted here, fantastic tips, which have helped me a great deal!

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!