Tuesday, February 12, 2008

Copy One Hard Disk to Another with Ubuntu 6.06 LTS

  1. With the machine off plug your target hard drive into a second channel on your computer.
  2. Boot the machine, when you see the grub start menu hit ESC
  3. Choose "Recovery Mode"
  4. When it prompts, enter your root password
  5. If you have IDE hard drives your drives will be /dev/hda for the source drive and /dev/hdb for the target. If they are SATA then they will be /dev/sda and /dev/sdb
  6. Type fdisk /dev/sda
  7. Type "p" to print a list of the partitions. Write these down, trust me it will make things easier in the future.
  8. quit out of fdisk with a CTRL+C
  9. Start FDISK again with /dev/sdb
  10. Press "n" to start a new patition segment
  11. Fill in the parameters you wrote down
  12. Try to duplicate the partition tables the best you can, here's the time to make the partition layout larger if you wish.
  13. Once you are done, type "w" to write the partition info to the disk
  14. Now you can copy the data over to the target disk
  15. mkdir /new in the root of the source disk
  16. mount /dev/sdb1 /new
  17. I have var on a separate partition on my system so I'm going to exclude it for this step and handle it later. However we still need to create a var mount point in what will be /
  18. mkdir /new/var
  19. mkdir /new/var/run
  20. mkdir /new/var/lock
  21. Now we do the copy:
  22. cd into /
tar --exclude var --exclude new -cvf - . | (cd /new; tar xf -)
  1. You will get error messages saying that the size has changed during copying, this is normal.
  2. Once it's done copying, we will do the same for the var partition.
  3. umount /new
  4. mount /dev/sdb3 /new
  5. cd into /var
tar -cvf - . | (cd /new; tar xf -)
  1. That copy should be pretty quick, we are done with the copy process.
  2. umount /new
  3. poweroff the system
  4. Next we need to reinstall grub on the new hard drive
  5. Remove the source disk from the system
  6. Power on the system, insert the ubuntu 6.06 installation CD and boot from it
  7. Select the "Rescue a broken system" option.
  8. This will look like it's installing the system again, just select all the appropriate options, enough to get you to the recovery screen.
  9. At one point it will ask which partition you want to be your root file system, 99% of the time this is part1, select it.
  10. It will then ask you what you want to do, select "re-install grub boot loader"
  11. It will give big long thing to read asking you where do you want to install the boot loader; we want it on /dev/sda, so we type that in and hit enter.
  12. It should install the boot loader, reboot the system and take the installer disc out of the drive.
  13. Done, you should have a fully working system on a new drive.