This is the set of instructions I use to clone one of my virtual machines. First I prepare two logical volumes (partitions): one for the / filesystem and one for swap. Here we go:
hydra xen # lvdisplay -C LV VG Attr LSize Origin Snap% Move Log Copy% dom1 vg1 -wi-a- 4.00G dom1swap vg1 -wi-a- 1.00G dom2 vg1 -wi-ao 4.00G dom2swap vg1 -wi-ao 1.00G
Here I want to clone dom2 into a new dom3 (and I’m going to be lazy and not shut dom2 down, just pause it):
hydra xen # lvcreate -L 4G vg1 -n dom3 Logical volume "dom3" created hydra xen # lvcreate -L 1G vg1 -n dom3swap Logical volume "dom3swap" created hydra xen # lvdisplay -C LV VG Attr LSize Origin Snap% Move Log Copy% dom1 vg1 -wi-a- 4.00G dom1swap vg1 -wi-a- 1.00G dom2 vg1 -wi-ao 4.00G dom2swap vg1 -wi-ao 1.00G dom3 vg1 -wi-a- 4.00G dom3swap vg1 -wi-a- 1.00G hydra xen # xm pause blog.fc5 # that's the machine running in dom2 hydra xen # dd if=/dev/vg1/dom2 of=/dev/vg1/dom3 bs=30M
BTW, it’s possible to check on the progress of the dd using kill -USR1 <pid>
hydra xen # xm unpause blog.fc5 hydra xen # mkswap /dev/vg1/dom3swap
Now create the xen config file for the new machine and change:
- the name
- the mac address
- the disks
kernel = "/boot/vmlinuz-2.6.16-r1-xenU" #kernel = "/boot/vmlinuz-2.6.16-1.2080_FC5xenU" memory = 128
name = "trac.fc5" vif = [ 'mac=00:16:3E:00:00:23' ] disk = ['phy:vg1/dom3,sda1,w', 'phy:vg1/dom3swap,sda3,w'] root = "/dev/sda1 ro"
Now mount the new filesystem and fix a few things:
hydra xen # mkdir /mnt/xen/dom3 hydra xen # mount /dev/vg1/dom3 /mnt/xen/dom3 hydra xen # cd /mnt/xen/dom3/etc/sysconfig hydra sysconfig # vi network # fix hostname
Start the machine, holding on to the console:
hydra sysconfig # cd hydra ~ # umount /mnt/xen/dom3 hydra ~ # xm create-c trac.fc5 hydra ~ # xm create -c auto/trac.fc5
Other things to do:
- add the hostname to DNS
- generate new SSH keys
- …