this is obsolete doc -- see http://doc.nethence.com/ instead

P2V for XEN 

 

 

Introduction 

Here's a few ways to make a physical to virtual convertion for XEN : 

- Ghost-like disk image (HVM & para) 

- Cold system image (para) 

- Hot system image (para) 

 

 

Ghost-like disk image 

See the Ghost-like rescue documentation (http://pbraun.nethence.com/doc/sysutils/ghost_rescue.html), but make ghosts against partitions (sda1), not the whole disk (sda). 

 

 

Cold system image 

To create a tared up system image, boot the machine with some NFS-client capable live CD (e.g. Gentoo installer) and proceed, 

mkdir -p /mnt/migrate
mkdir -p /mnt/nfs
mount /dev/sda3 /mnt/migrate
mount /dev/sda1 /mnt/migrate/boot
#ifconfig...
#route...
/etc/init.d/portmap start
mount -t nfs dom0host:/data/guestX /mnt/nfs
cd /mnt/migrate
cat > /exclude.list << EOF
/dev/log
/proc
/sys
EOF
tar czp -X exclude.list -f /mnt/nfs/migrate.tar.gz .

Note. don't use '-P' as we may extract the archive inside vm's virtual disk directly from the dom0. 

Note. '/dev' also may be exluced 

 

 

Hot system image 

If possible switch to init 1, 

telinit 1

at least, stop the databases if there are some. And if there's Oracle, make sure the databases are stored on filesystem, nor RAW nor ASM. And proceed, 

mkdir -p /mnt/nfs
#ifconfig...
#route...
/etc/init.d/portmap start
mount -t nfs dom0host:/data/guestX /mnt/nfs
cat > /exclude.txt << EOF
/dev/log
/proc
/sys
  EOF
cd /
tar czp -X /exclude.txt -f /mnt/nfs/migrate.tar.gz .

Note. don't use '-P' as we may extract the archive inside vm's virtual disk directly from the dom0. 

Note. '/dev' also may be exluced 

 

 

Deploy the system image and customize the paravirtualized guest 

On dom0, prepare the virtual partitions and swap, 

cd /data/guestX
dd if=/dev/zero of=guestX.ext3 bs=1024k count=1 seek=10000
dd if=/dev/zero of=guestX.swap bs=1024k count=1024
mkfs.ext3 -F vmname.ext3
mkswap vmname.swap

note. no sparse for swap 

note. 'mkswap -L' for swap label 

 

Mount the virtual partitions and extract the archive, 

mkdir tmp
mount -o loop guestX.ext3 tmp
tar xzpf migrate.tar.gz -C tmp

 

Prepare the kernel and initrd. If it's the same Redhat major release, 

cp /boot/vmlinuz-`uname -r` vmlinuz
cp /boot/initrd-`uname -r`.img initrd.img
cp -R /lib/modules/`uname -r` tmp/lib/modules

if it's a different Redhat major release, 

chroot tmp /bin/bash
#rpm -ivh ...
#yum install ...

otherwise you may get working kernels from Xensource directly (IIRC, no xenblk though), 

chroot tmp /bin/bash
cd root
wget xen.xensource.com/download/....
tar xvzf xen-*
cd dist
./install.sh
#[...]
exit
hostname
pwd

 

Configure the mount points, 

vi tmp/etc/fstab

 

Disable TLS, 

echo 'hwcap 0 nosegneg' > tmp/etc/ld.so.conf.d/libc6-xen.conf

Note. on non Redhat distributions, you may have to, 

#mv tmp/lib/tls tmp/lib/tls.disabled

 

Prepare the guest configuration, 

vi guestX

like, 

name = "guest2"
memory = "256"
kernel = "/data/guest2/vmlinuz"
ramdisk = "/data/guest2/initrd.img"
disk = [ 'tap:aio:/data/guest2/guest2.disk,xvda,w' ]
vif = [ 'bridge=xenbr0' ]
vcpus = "1"
#console = "/dev/console"

 

Start the guest in single user mode, 

vi guestX

add this, 

#extra = "init=/bin/sh"
extra = "1"

start the guest, 

xm cr guestX -c

update module symbols, disable unwanted services and prevent hardware clock synchronizations, 

mount -n -o remount,rw /
/sbin/depmod -a
chkconfig microcode_ctl off
mv /sbin/hwclock /sbin/hwclock.dist
echo '/bin/true' > /sbin/hwclock
chmod +x /sbin/hwclock

 

Note. on RHEL 4.4 you need to fix "/etc/inittab" inside the guest, 

1:2345:respawn:/sbin/mingetty console

 

 

References 

Converting a VMWare image to Xen HVM : http://ian.blenke.com/vmware/vmdk/xen/hvm/qemu/vmware_to_xen_hvm.html