How do I copy an existing hard disc to a new one so I can boot off the new disc?

6,176

Solution 1

Yes, a 100% exact copy of your HDD is possible, and it would preserve all your files, data and system configurations intact. And, as you've already correctly guessed, simply copying files over won't work. (it can be done, but not worth the trouble of doing it right)

A HD cloner tool is your best bet. There are dozens available.

  • Is the new hard drive larger than the old one?
  • Do you have any Ubuntu bootable CD / USB key?

If so, I recommend the good old dd. Its a one-liner, rudimentary, ancient solution for cloning a HDD. But it works, and its amazingly easy. dd is also pre-installed in Ubuntu.

  • Boot using your Live CD or USB stick
  • Using System > Administration > gparted (Disk Utility also works), take note which is your old and which is your new hard drive (sda, sdb, etc).

enter image description here

  • Checked? Great!
  • Now check them again:

enter image description here

  • Ready?
  • Now Triple check it. I mean it! dd will have no mercy if you use the wrong letters. dd is commonly known as "d isk d estroyer" for a reason!

From now on, Ill assume the old is /dev/sdX and the new is /dev/sdY. Check your actual values! (did I say that already?)

  • Using Terminal, issue the granddaddy of all HDD cloners:

    sudo dd if=/dev/sdX of=/dev/sdY bs=1M
    
  • bs=1M is optional, only to improve performance. The best value depends on your drives/cache/cpu/ram. Commonly used values are 4K, 64K, 1M, 16M. Try for yourself in a 1GB test (add count=256K, 16K, 1K, 64 respectively). For my machine, anything from 4K to 32M leads to very similar results.

  • If you want to monitor the copy, you may try this fancy version:

    sudo su - # neccessary to get correct pid
    dd if=/dev/sdX of=/dev/sdY bs=1M & pid=$!
    while kill -USR1 $pid 2>/dev/null; do sleep 10; done
    

It will output dd's progress every 10 seconds.

  • Now go grab a lunch. Or better, go to sleep. It will take long ;)

Post-copy procedures:

  • Remove the old drive
  • Install the new one in the same connector as the old (so you dont need to reconfigure BIOS)
  • Boot and check that everything is fine
  • Since dd makes an exact copy, partitions will be the same size. If new hdd is much larger than the old one, use gparted to expand partitions to claim the unused space.

Solution 2

I have used "clonezilla" in the past,i had the same problem as you but my system had xp and ubuntu 9.04 on it,it will clone the drive to a new drive just as long if the new drive is bigger or the same size. this is a few vids on youtube on how to use it. its free and saved my butt a few times.

http://clonezilla.org/

Solution 3

It might be useful to use the System Rescue CD (which can be run from an USB stick too). E.g. when you get read errors you'll want to use the included ddrescue. Note that the applications are not always easy to use (they often only work from the commandline), but they can be very powerful!

Share:
6,176

Related videos on Youtube

Jesper Rønn-Jensen
Author by

Jesper Rønn-Jensen

I started off programming in BBC Basic and 6502 assembler. I got my first job programming in FORTRAN on VMS, and since then have picked up C, C++ and SQL on VMS and Unix, with excursions into VB and IBM 360 assembler. I drink real ale, play wargames and contract bridge, and walk in the country. And, yes, I have a beard.

Updated on September 18, 2022

Comments

  • Jesper Rønn-Jensen
    Jesper Rønn-Jensen over 1 year

    I currently have a failing hard drive which is the only hard drive in the machine. I have just bought a new hard drive to replace it, and my plan is to copy the contents of the old drive onto the new one, and then replace the old drive in the machine with the new one.

    I presumably can't just copy the whole directory structure (or can I)? What do I need to do to manage this, assuming it is possible? Is there a utility to do this for me? (The old drive is hopefully good for a few more hours.)

    (I hope by this means to keep all the software and configuration files as they are, to avoid having to re-install everything. Can that be done?)

    • JanC
      JanC almost 13 years
      If the disk doesn't give read errors, you can copy the whole directory structure when you use the correct cp parameters to keep all attributes (ownership, permissions, times, ACLs, etc.), but then you have to make the disk bootable afterwards.
    • MestreLion
      MestreLion almost 13 years
      The problem using cp is not only finding the necessary parameters, but also requiring to create the partition(s), issue cp for each, and setup grub afterwards. dd (or your suggestion on ddrescue) does this all in 1 line
    • JanC
      JanC almost 13 years
      @MestreLion: dd is (probably) useless if the new disk is smaller than the old one though, and if the new disk is bigger you'll probably have/want to resize partitions afterwards... Both approaches have pros & cons, and I think Brian will have to decide what is likely to work best for him.
  • JanC
    JanC almost 13 years
    I would only use dd if the disk is mostly full; otherwise you'll be copying mostly unused bytes...
  • sabna
    sabna almost 13 years
    @JanC it is a one-use-only throw away solution, so the overhead should be tolerable
  • MestreLion
    MestreLion almost 13 years
    @JanC: true, but dd one of the few solutions that copy not only the files, folders and partitions themselves, but also the partition table, MBR code (grub, for instance) and everything else. And its by far the easiest way to do this 100%-exact clone of the entire hard drive
  • JanC
    JanC almost 13 years
    well, PartImage is probably easier than dd and can do that too. But I agree that copying the MBR and maybe the gap before the first partition (in case grub or other tools embed code there) separately from a FSArchiver or cp copy of the filesystems requires more knowledge.
  • MestreLion
    MestreLion almost 13 years
    Ive never heard of ddrescue before. Ive googled it, and it sounds very nice! Its as simple as dd, and it also has reading errors handling and logging. Sweet ;)
  • MestreLion
    MestreLion almost 13 years
    @JanC: Partimage would be nice, but it currently does not support ext4 partitions, which is Ubuntu's default (maybe thats why its not in the repos). Also, it works in a per-partition basis. It does not clone the entire drive at once (all partitions including MBR)
  • JanC
    JanC almost 13 years
    @MestreLion: there are actually 2 tools like that in the Ubuntu repositories, ddrescue (command: dd_rescue) & gddrescue (command: ddrescue). I'm not sure which one is best...
  • djeikyb
    djeikyb over 12 years
    If you use dd, stop and use dc3dd instead. It includes a patch that shows a bunch of stats, notably: throughput (MB/s), percent completed, bytes and/or GB completed.
  • MestreLion
    MestreLion over 12 years
    dc3dd is not installed by default in Ubuntu. It's not even in the repositories. No PPA or .deb package either. Compiling software from source is not a good idea for a new user who just wants to clone his HDD. Specially since he will be operating from a USB Live session. For more stats or GUI, i would recommend ddrescue, gddrescue or clonezilla