Sunday 29 November 2009

Cloning an Ubuntu Server

I recently needed to clone an Ubuntu 9.04 server to another machine for one of my customers thinking that it would be simple. It wasnt. But here's how I got it to work.

Firstly from searching the net it would seem that there are a lot of different ways of doing this. dd, ddrescue, partimage, ping. They did not work for me for various reasons. I ended up using the tar method.

You will need a LiveCD that you can boot on the machine that you are copying to. And your original Install CD of Ubuntu. Because my original was server which is not a live CD I used Minibuntu. You will also need a USB drive that is big enough to hold the image.

First log in to the machine that you are copying. cd to /. sudo su.
tar -cvpzf backup.tar.gz -–exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media /

Copy the backup.tar.gz to  a USB drive attached to the machine.

mkdir /mnt/usb


mount /dev/sdb1 /mnt/usb
(sdb1 may be different on your machine dmesg | grep -i "SCSI" should list it with sd?)

cp /backup.tar.gz /mnt/usb


Next install a basic Ubuntu Server on the new machine.  Reboot and plug in the USB drive. Mount it as before and copy the backup to the root directory of the new machine. Then extract the archive.
sudo tar -xvpzf backup.tar.gz -C /

Reboot but this time to the LiveCD. If you use Mini Buntu command line LiveCD you need to select another terminal after boot. Ctrl-Alt-F2.

Since you are running from a live cd you need to mount the HDD of the machine. Same way as mounting USB.

Then you need to install grub again to get the boot stuff correct.

sudo grub
will bring up the grub prompt if not
sudo apt-get update
and
sudo apt-get install grub
. Note that you will need the internet for that. If you can not connect to the net just make sure that the LiveCD you use has grub on it. Mine didnt.

at the prompt
find /boot/grub/stage1

root (hd0,0)
(Replace with whatever the find returned)
setup (hd0) 
(Again replace the hd0 with the results of the find)

quit


Now we need to fix up the UUIDs. These are identifiers from the HDD which you have just overwritten. To get the UUID of your drives

ls -l /dev/disk/by-uuid/


or

sudo vol_id /dev/sda1


Note them down and for which partition root and swap. Check them and then check them again.

now change the grub loader and fstab.

sudo nano /mn/etc/fstab
.

update the UUIDs

sudo nano /boot/grub/menu.lst


update the UUIDs


Reboot and you should be a go.

You may get an issue with networking. Because a new card is recognized the ethernet adapter name on my system changed from eth0 to eth1. I worked this out by dmesg | grep eth0. edit the /etc/network/interfaces file and change all instances of eth0 to eth1.

References
https://help.ubuntu.com/community/BackupYourSystem/TAR
http://linux.byexamples.com/archives/321/fstab-with-uuid/
http://stringofthoughts.wordpress.com/2009/05/25/grub-error-15-debianubuntu/

1 comment:

  1. The personal loans suppose to be important for people, which are willing to start their business. By the way, that is comfortable to get a short term loan.

    ReplyDelete