Page 1 of 4 123 ... LastLast
Results 1 to 10 of 33

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

  1. #1
    Join Date
    Aug 2006
    Location
    United Kingdom
    Beans
    989
    Distro
    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
    Code:
    sudo dd if=FROM of=TO
    (say you found hda1, which must be copied to sda1)
    Code:
    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.
    Code:
    sudo dd if=FROM of=/location/of/image/save/file.raw
    and then
    Code:
    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:
    Code:
    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
    Code:
    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
      Code:
      sudo grub
    4. Wait for a "grub>" prompt
    5. Enter
      Code:
      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
      Code:
      root RESULT
      with RESULT being the result of the last action, the find. So if hd(0,0) was found, run
      Code:
      root hd(0,0)
    7. Now run
      Code:
      setup (hd0)
      regardless of the result you got in #5.
    8. Grub will complete the installation, you can use a
      Code:
      quit
      command to exit the grub prompt, then
      Code:
      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
    Code:
    fsck
    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
    Code:
    sudo su
    and enter password at prompt. Then use, in the root terminal
    Code:
    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.

  2. #2
    Join Date
    Nov 2007
    Beans
    1

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

    A couple points:

    In the last example, where it uses the "dev" command I think you mean dd.

    Be very careful with dd. Make sure the "if=" and "of=" files are pointing at the correct partitions. dd will cheerfully overwrite partitions without warning.

    If there's any chance of errors on your disk, use the noerror and sync flags on dd. For example,

    dd noerror sync if=/dev/hda1 of=/dev/sda1

    Another way to copy a data from one partition to somewhere else is "cp -a". This works on mounted file systems, not raw partitions. For "cp -a" to work, the target partition must already have a file system on it. Assuming we want to copy from /mnt/hda1 to /mnt/sda2,

    cp -av /mnt/hda1/* /mnt/sda2
    The v flag causes cp to list all the files as it copies them.

  3. #3
    Join Date
    Aug 2006
    Location
    United Kingdom
    Beans
    989
    Distro
    Ubuntu 7.10 Gutsy Gibbon

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

    Thanks, fixed the "dev" thing, was tired and wrote this quickly.

    Also, the "cp" command is great for some things but for this I'd recommend dd. You can't guarantee it will be bootable, certain things (like /dev /mnt /tmp and /media) can get in the way, file permissions aren't kept, not everything can be moved whilst in use and lots of files can get confusing. dd makes the move alot more simple.

  4. #4
    Join Date
    Jun 2006
    Location
    UK
    Beans
    Hidden!
    Distro
    Ubuntu 14.10 Utopic Unicorn

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

    Quote Originally Posted by Old Pink View Post
    Also, the "cp" command

    <snip>

    file permissions aren't kept
    Actually, they are, so long as you use the -a flag as ManInTheLake says. I've used cp several times to clone/move whole partitions and it has always worked.

    Quote Originally Posted by Old Pink View Post
    not everything can be moved whilst in use and lots of files can get confusing.
    Agreed for the first part. It's best to cp a mounted partition from another distro on another partition or from a live CD. As for getting confusing? Just issue the cp command and go and have a coffee. You don't have to watch the terminal output.

  5. #5
    Join Date
    Aug 2006
    Location
    United Kingdom
    Beans
    989
    Distro
    Ubuntu 7.10 Gutsy Gibbon

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

    Quote Originally Posted by coffeecat View Post
    Agreed for the first part. It's best to cp a mounted partition from another distro on another partition or from a live CD. As for getting confusing? Just issue the cp command and go and have a coffee. You don't have to watch the terminal output.
    True, but you agreed with not everything being available for copy while in use. Then you have to sift through and find what didn't copy. And it's just generally less neat than keeping everything concealed in one image with dd.

    Whatever, it's personal preference. This is dd specific, and people are offered cp as an alternative when they scroll to the replies. I may add it to "variations" at a later date

  6. #6
    Join Date
    Jun 2006
    Location
    UK
    Beans
    Hidden!
    Distro
    Ubuntu 14.10 Utopic Unicorn

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

    You mention everything in one neat image - or words to that effect. Have you tried using tar? That's my preferred method for archiving/cloning/copying partitions now. As you say - one image, and a nicely compressed one too.

    There is one problem - Ubuntu's use of UUIDs in fstab. Of course, they will have changed if you've moved your installation from one HD to another using tar or cp, so you have to edit fstab. I've never used dd. Is the UUID preserved or is this something you need to add to your howto?

  7. #7
    Join Date
    Aug 2006
    Location
    United Kingdom
    Beans
    989
    Distro
    Ubuntu 7.10 Gutsy Gibbon

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

    In my experiences with using dd, the UUIDs are preserved, yes.

    Remember, with using tar, not everything can be copied if in use, and you need to to trigger it into keeping file permissions, and avoid certain folders being archived (such as /mnt, /tmp and /proc), and of course, you have to extract everything as soon as it's archived, what a hassle!

    But yes, there is some element of personal preference. dd just worked perfectly for me, and was very fast and efficient, with absolutely no flaws (most of the time I don't even get prompted to fsck after) and I thought I'd share my method.

  8. #8
    Join Date
    May 2006
    Beans
    250
    Distro
    Xubuntu

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

    While it's pretty cool that you can do these things from the command line, I'd still like to recommend the excellent GParted LiveCD.

  9. #9
    Join Date
    Aug 2006
    Location
    United Kingdom
    Beans
    989
    Distro
    Ubuntu 7.10 Gutsy Gibbon

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

    Quote Originally Posted by agurk View Post
    While it's pretty cool that you can do these things from the command line, I'd still like to recommend the excellent GParted LiveCD.
    Why spend ages downloading and burning the CD image, not to mention booting in RAM from a CD, just to copy the image, when, as the website says
    The actual copy is performed by 'dd'.
    meaning it's the same function, you just waste an unnecessary half hour plus getting a slow GUI up? Follow my guide, quicker, easier, makes much more sense.

  10. #10
    Join Date
    May 2006
    Beans
    250
    Distro
    Xubuntu

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

    I'm not knocking your nice how-to, it's just that with age I've come to appreciate the simplicity of point-and-click, not having to memorize or print a list of cli commands. Each to his own, I guess.

Page 1 of 4 123 ... LastLast

Bookmarks

Posting Permissions

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