This how-to describes the process for migrating a SLES Xen virtual machine from one physical host to another. In this scenario, the new VM will be hosted on shared storage mounted via NFS. This scenario may also work for Physical to Virtual (P2V) migration.
1. Shut down source vm on Dom0, mount the hard drives.
xm shutdown vm1
# list the drives to find which one is the root
fdisk -l /dev/sda
# Gain access to the old virtual hard drive: create the mapping under /dev/mapper
kpartx -a /dev/sda3
mount -o loop /dev/mapper/sda3p2 /mnt/temp
2. Create a new hard drive image file (60GB) on the new location using dd:
dd if=/dev/zero of=/mnt/vm2/disk0-new.img bs=1M count=1 seek=60000
# Make the file system
/sbin/mkreiserfs -q -f disk0-new.img
# Make the swapfile
dd if=/dev/zero of=/var/lib/xen/images/vm2/vm2-8g.swap bs=1k count=8392930
mkswap vm2-8g.swap # it is large because of oracle reqs
# Mount the new filesystem
mount -o loop /mnt/vm2/disk0-new.img /mnt/img
3. Create new virtual machine minimal install with SLES 10 SP2 on new Xen host, pointing to new hard drive files. Use Yast’s “Create a Virtual Machine.”
4. rsync the file system from /dev/mapper/sda3p2 to /mnt/img
### exclude_file.txt
/dev/
/mnt/
/lost+found/
/sys/
/boot/
/media/
/proc/
/selinux/
/tmp/
sysconfig/
$ rsync -rlpogt –progress –exclude-from=”exclude_file.txt” /dev/mapper/sda3p2/ /mnt/img/
5. Correct entries in files in the newly replaced /etc for the new vm configuration: /etc/fstab (now /dev/xvda1 instead of hda2 for /, /dev/xvdb1 for swap instead of hda1), /etc/passwd, /etc/group, /etc/sysconfig/network/ifcfg_eth.. Kept the new vm’s mac address and updated the IP for vm2 in the config file /etc/xen/vm/vm2.
6. Start up the new virtual machine. Don’t forget to do an ‘xm delete vm1’ on the old system once you are sure it is no longer needed.