How to migrate a Linux physical machine to a XEN virtual machine

Home | UNIX | Code | Philosophie (FR) | Practical

How to migrate a Linux physical machine to a XEN virtual machine

XEN Guide : pbraun.nethence.com/doc/sysutils_xen/xen.html
XEN Redhat specific : pbraun.nethence.com/doc/sysutils_xen/xen_redhat.html
XEN NetBSD specifics : pbraun.nethence.com/doc/sysutils_xen/xen_netbsd.html


Full-virt guests - VMware to XEN
To convert windows vmware images to XEN HVM guests (untested),
ian.blenke.com/vmware/vmdk/xen/hvm/qemu/vmware_to_xen_hvm.html
You need VT or AMD-V into machine's BIOS for that.


The ghost-like technique
Send the harddrive to another host,
dd if=/dev/sda | ssh user@host cat '>'/path/to/virtual.disk
Or use one of those,
G4L see pbraun.nethence.com/doc/sysutils_vmware/p2v_linux_fr.html (FR)
Partimage
G4U
Partimage : www.partimage.org/
G4U : www.feyrer.de/g4u/
G4L : fedoragcc.dyndns.org/
P2V & ghost : www.usenet-forums.com/linux-general/83847-bash-progress-bar-command-like-g4u-bsd.html


tar.gz COLD system image
To create a tared up system image, boot the machine with some NFS-client capable LiveCD, in example Gentoo Linux. Thereafter,
mkdir /migrate
mount /dev/sda3 /migrate
mount /dev/sda1 /migrate/boot
mkdir /nfsshare
# ifconfig... route...
/etc/init.d/portmap start
mount -t nfs NFS_SERVER:/path/to/share /mnt/nfsshare
cat > /exclude.txt << EOF
/dev/log
/proc
/sys
EOF
cd /migrate
tar czp -X /exclude.txt -f /nfsshare/migrate.tar.gz .
Note. don't use tar -P as we may extract the archive inside vm's virtual disk from the XEN dom0.
Note. /dev may also be excluded


tar.gz HOT system image
If possible switch to init 1,
telinit 1
At least stop the databases if there are some (and check, if this is Oracle, it's using filesystem, not RAW).
Then for example,
mkdir /mnt/nfsshare
# ifconfig... route...
/etc/init.d/portmap start
mount -t nfs SERVER_IP:/path/to/share /mnt/nfsshare
cat > /exclude.txt << EOF
/dev/log
/proc
/sys
  EOF
cd /
tar czp -X /exclude.txt -f /nfsshare/migrate.tar.gz .
Note. don't use tar -P as we may extract the archive inside vm's virtual disk from the XEN dom0.
Note. /dev may also be excluded


tar.gz VM creation
Place the tar archive into VM's folder, for example /data, create the virtual disk, mount it. In example,
cd /data
mkdir vmname
cd vmanme
dd if=/dev/zero of=vmname.ext3 bs=1024k count=10000 seek=1
Note "seek=" is usefull for sparse disks. Copiable with cp --sparse=always (default) and tarable with tar -S/--sparse.
mkfs.ext3 -F vmname.ext3
mkdir loop
mount vmname.ext3 loop
Create the swap virtual disk,
dd if=/dev/zero of=vmname.swap bs=1024k count=1000
Note no "seek=" here.
mkswap -L swap vmname.swap

And extract the archive,
tar xzpf /data/migrate.tar.gz -C loop

Now is the time to tweek the VM to make it work (boot).
Either install bare XEN domU kernel from xensource,
# mount & bind /proc ?
chroot loop
cd root
wget xen.xensource.com/download/....
tar xvzf xen-*
cd dist
./install.sh
#[...]
exit
hostname
pwd
or install the relevant kernel-xen package,
yum --installroot
or
rpm --chroot

Copy domU's xen kernel to dom0 and check modules' relevant version. for example,
cp loop/boot/vmlinuz-2.6.18-53.1.4.el5xen .
ll loop/lib/modules

Also edit fstab,
vi loop/etc/fstab

Deactivate TLS,
mv loop/lib/tls loop/lib/tls.disabled

At last, edit VM's config,
vi vmname
See "Creating a VM" config example : pbraun.nethence.com/doc/sysutils_xen/xen.html
Note we're not adding .conf at the end, it's faster to call it with shell's completion feature in example,
xm create vmname (-c)

Also see the domU single user mode tip (pbraun.nethence.com/doc/sysutils_xen/xen.html) to update modules.dep,
# boot vm in single user mode and
/sbin/depmod -a
/bin/sync



Page generated Mon May 11 13:34:24 CEST 2009
Home | Donate | Print | html/css
Copyright 2009 Pierre-Philipp Braun