Results 1 to 10 of 33

Thread: HowTo: Transfer your bootable Ubuntu installation between hard drives

Threaded View

  1. #1
    Join Date
    Aug 2006
    United Kingdom
    Ubuntu 7.10 Gutsy Gibbon

    HowTo: Transfer your bootable Ubuntu installation between hard drives

    Maybe you're moving to a bigger/faster/quieter hard drive. Or just want a complete backup. Or maybe you're cloning systems in order to get closer to world domination, it doesn't matter. This is a guide to clone the contents of one hard drive to another.

    Basically, use dd to clone your hard drive. The hard drive/partition you are cloning to will need to be formatted first. It's recommended you dd to an identical partition for optimal results. If you're upgrading to a larger hard drive, create a partition the same size as the old partition first, follow this guide then use the Live CD to resize the new partition. It is possible to dd a smaller partition into a larger partition, but results differ.

    If you can get both plugged in at the same time (maybe you have two internal slots, or an internal slot and an external hard drive case) then it's simply a case of finding the two in /dev and running
    sudo dd if=FROM of=TO
    (say you found hda1, which must be copied to sda1)
    sudo dd if=/dev/hda1 of=/dev/sda1
    and await finish. Now move on to "then"

    If you can only mount one at a time, you'll need to dd to an image, and then dd to the next hard drive.
    sudo dd if=FROM of=/location/of/image/save/file.raw
    and then
    sudo dd if=/location/of/image/save/file.raw of=TO
    so say you had sda1, which was going onto another hard drive. But before this you needed to make an image, as you had no way of mounting both. So you'll put the image in /home/user (assuming your username is user) you'd use:
    sudo dd if=/dev/sda1 of=/home/user/image.raw
    and you then dismounted sda1, inserted your new hard drive, which became /dev/sda1 instead. You'd then have to run
    sudo dd if=/home/user/image.raw of=/dev/sda1
    (this can be VERY slow if you're using an external hard drive connection, especially at USB 1.1)

    Then you have a clone of your hard drive. You need to boot from a Live CD with the clone in a computer in order to install/fix grub on the MBR. To do this:
    1. Boot the live CD
    2. Wait for the GUI and use CTRL + ALT + F1 to get a a terminal
    3. Run
      sudo grub
    4. Wait for a "grub>" prompt
    5. Enter
      find /boot/grub/stage1
      in order to locate the cloned hard drive. You'll get a result like hd(0,0) - REMEMBER THIS
    6. Enter
      root RESULT
      with RESULT being the result of the last action, the find. So if hd(0,0) was found, run
      root hd(0,0)
    7. Now run
      setup (hd0)
      regardless of the result you got in #5.
    8. Grub will complete the installation, you can use a
      command to exit the grub prompt, then
      sudo shutdown -r now
      to reboot (make sure you eject Live CD at reboot to boot from new hard drive)
    Now, your system may boot fine, it will certainly process grub OK and get to your Ubuntu loading splash. Chances are though in all the dd'ing, you'll have hurt the image a little, and maybe gotten a few sectors broken on the way. If this is the case, you hard drive will try to force a scan. Usually these fail, and you are told to run fsck yourself, and given a root terminal. If this should happen, merely run
    and answer all questions. If you don't know the answer, hit return/enter to accept the default answer. fsck should complete fairly quickly and leave you with a healed, bootable hard drive. Just use CTRL + D to reboot after fsck has succesfully completed.

    Enjoy your new hard drive! (of course, now it's bootable, you may choose to move it elsewhere, or store it safely if it's just a back up. The old one will work just the same, as if nothing had happened)

    Variations of this: (will be updated often)

    If you're going out, and want to leave dd copying your stuff around while you go, you can set your computer to shut down afterwards. sudo only lasts 15 minutes, so to do this you'll need a root terminal. Simply open a normal terminal and type
    sudo su
    and enter password at prompt. Then use, in the root terminal
    dd if=FROM of=TO && shutdown -h now
    having read above for FROM and TO information, and your system will complete the dd and go to shutdown with a "halt" - you'll return to a copied hard drive and a nicely shutdown system.
    Last edited by Old Pink; November 3rd, 2007 at 10:08 PM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts