Monday, July 20, 2009

Converting VMWare image to SLES Xen

UPDATE (22 Jul '09): Ron Terry has uploaded his virt-tools RPM package online at . Hence, with regards to point 4 below in this entry, you could simply download and install the virt-tools-0.1.0-4.1.noarch.rpm and use the sparsify-disk script. Thanks Ron! sembah

I had to conduct a demo of a product that only works on Windows. I could spend time to setup a Windows 2003 environment in Xen and then install the product/s and perform the necessary demo configurations etc... but my colleague have it all setup and ready to rock in a VMWare image... heheheh... let the fun begin! kenyit

PS: Yes, I could simple reboot SLES 11 and use VMWare Server but I had all my other demos in Xen... besides, I really dig the fact that I can have virtualization capabilities using open source software.

1) Using the qemu-img-xen tool in SLES 11, I was able to convert the VMWare VMDK file (single file) into a raw sparse file. If your VMDK is split into multiple files (2GB each - gotta love FAT), you can use vdiskmanager (a VMWare tool) to combined all these little files into a file before using qemu-img-xen.

qemu-img-xen convert demo.vmdk -O raw disk0

That's all there is to it... EASY!... oh... unless of course, you have my luck and the original Windows VM is virtualized on VMWare using SCSI disk drivers. You can take a look at the VMX file to verify. Or you could attempt to boot up the Windows VM in Xen and have it hang with the all so familiar BSOD (Blue Screen of Death). sengihnampakgigi

2) With many Thanks to Mr Ian Blenke and his blog entry, I managed to overcome the "Windows VM using SCSI disk drivers and will not boot up in Xen because the disk is now IDE" challenge. The trick is to simply copy the appropriate IDE drivers and merge additional registry entries into the Windows VM. Next, perform step 1 and that's it! senyum

For Windows 2003, the IDE drivers can be found in C:\WINDOWS\Driver Cache\i386\ I extracted pciide.sys and copied it to C:\WINDOWS\system32\drivers\ directory. Additionally, check and ensure that Atapi.sys, Intelide.sys and Pciidex.sys are also in C:\WINDOWS\system32\drivers\

The additional registry entries and instructions on merging with existing registry can be found at the latter half of the very long page at

3) Optionally, probably a good idea, I downloaded the latest Virtual Machine Driver Pack for Windows from (search term "virtual machine driver pack"). Direct link for this at time of this writing is

Download Windows driver directly into the Windows Xen VM and double-click to install. Done! senyum

I did notice an improvement in overall speed during boot (I/O bound) and when copying files over the network (Network I/O).

4) Finally, I did some spring cleaning within the Windows Xen VM... managed to reclaim 6Gb of hard disk space. Now comes the next labourious bit, I need to re-sparsify the disk so as to translate this disk usage savings onto the physical hard disk drive. With much Thanks to Ron Terry, I managed to do just that by a wonderful script he provided.

Since I did not get his kind permission to put that script up in the public domain, I will describe the process (and commands) in sparsifying the disk.

a) Mount the Xen disk on dom0:

xm block-attach 0 file:/directory/disk0 xvde w
mount /dev/xvde1 /tmp/disk1

b) Use the dd command to fill up the rest of the empty spaces with zeros.

dd if=/dev/zero of=/tmp/disk1/zerofile bs=1M
rm /tmp/disk1/zerofile

c) Unmount and detach the Xen disk from dom0:

umount /tmp/disk1
xm block-detach 0 51776 -f

d) Make a copy of the Xen disk with the cp command and --sparse=always flag:

mv disk disk.tmp
cp -a --sparse=always disk.tmp disk

PS: Please ensure you have 1.5 to 2.0 times the disk image file (disk0) of free hard disk space on your system.

Life is good again. peace

No comments:

Post a Comment