Home
|
UNIX
|
Code
|
Philosophie 
|
Practical
How to migrate a Linux physical machine to a XEN virtual machine
Full-virt guests - VMware to XEN
To convert windows vmware images to XEN HVM guests (untested),
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,
Partimage
G4U
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
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)
# boot vm in single user mode and
/sbin/depmod -a
/bin/sync