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
(say you found hda1, which must be copied to sda1)
sudo dd if=FROM of=TO
and await finish. Now move on to "then"
sudo dd if=/dev/hda1 of=/dev/sda1
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
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=/location/of/image/save/file.raw of=TO
and you then dismounted sda1, inserted your new hard drive, which became /dev/sda1 instead. You'd then have to run
sudo dd if=/dev/sda1 of=/home/user/image.raw
(this can be VERY slow if you're using an external hard drive connection, especially at USB 1.1)
sudo dd if=/home/user/image.raw of=/dev/sda1
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:
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 runand 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.
- Boot the live CD
- Wait for the GUI and use CTRL + ALT + F1 to get a a terminal
- Wait for a "grub>" prompt
in order to locate the cloned hard drive. You'll get a result like hd(0,0) - REMEMBER THIS
- Enter with RESULT being the result of the last action, the find. So if hd(0,0) was found, run
- Now run regardless of the result you got in #5.
- Grub will complete the installation, you can use a command to exit the grub prompt, then
to reboot (make sure you eject Live CD at reboot to boot from new hard drive)
sudo shutdown -r now
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 typeand enter password at prompt. Then use, in the root terminal
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.
dd if=FROM of=TO && shutdown -h now