Saturday, July 23, 2011

vmware, qemu & winxp

so linux now has great support for virtual machines. i use virtualbox on my macbook but for years have used vmware on my debian box. now that i don't have to rely on vmware's resource-intensive hypervisor, i started to research alternative solutions. i came across qemu; apparently xen open source and kvm use qemu under their hoods. qemu can also be utilized independently, so i decided not to bother with xen or kvm. my first problem was that i my vmware vmdk image file was distributed instead of centralized (i had multiple vmdk files).

matthew@hufflepuff:~$ ll ~/vmware/
total 11G
drwxr-xr-x 2 matthew matthew 4.0K Jun 8 14:18 .
drwxrwxrwt 3 root root 4.0K Jun 8 20:19 ..
-rw------- 1 matthew matthew 8.5K May 18 19:37 nvram
-rw-r--r-- 1 matthew matthew 43K Mar 19 2010 vmware-0.log
-rw-r--r-- 1 matthew matthew 49K Mar 18 2010 vmware-1.log
-rw-r--r-- 1 matthew matthew 49K Mar 17 2010 vmware-2.log
-rw-r--r-- 1 matthew matthew 50K May 18 19:37 vmware.log
-rw------- 1 matthew matthew 2.0G May 18 19:37 Windows XP Professional-f001.vmdk
-rw------- 1 matthew matthew 2.0G May 18 19:37 Windows XP Professional-f002.vmdk
-rw------- 1 matthew matthew 2.0G May 18 19:37 Windows XP Professional-f003.vmdk
-rw------- 1 matthew matthew 2.0G May 18 19:37 Windows XP Professional-f004.vmdk
-rw------- 1 matthew matthew 2.0G May 18 19:37 Windows XP Professional-f005.vmdk
-rw------- 1 matthew matthew 1.3M Dec 5 2007 Windows XP Professional-f006.vmdk
-rw------- 1 matthew matthew 732 May 18 19:25 Windows XP Professional.vmdk
-rw------- 1 matthew matthew 0 Dec 5 2007 Windows XP Professional.vmsd
-rwxr-xr-x 1 matthew matthew 1.4K May 18 19:37 Windows XP Professional.vmx
-rw-r--r-- 1 matthew matthew 1.7K Mar 16 2010 Windows XP Professional.vmxf


i needed to merge these files without damaging the windows' ntfs. i came across a utility called "vdiskmanager". this merged all my files into one vmdk:

matthew@hufflepuff:~/vmware$ vmware-vdiskmanager –r Windows\ XP\ Professional.vmdk –t 0 WinXP.vmdk

i then needed to convert it to a qemu raw image format:

matthew@hufflepuff:~/vmware$ qemu-img convert -f vmdk WinXP.vmdk -O raw WinXP.img

then to verify the conversion:

matthew@hufflepuff:~/vmware$ qemu-img info -f raw WinXP.img
image: WinXP.img
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 7.4G

and double check (because i'm paranoid):

matthew@hufflepuff:~/vmware$ file WinXP.img
WinXP.img: x86 boot sector, Microsoft Windows XP MBR, Serial 0x2e682e67; partition 1: ID=0x7, active, starthead 1, startsector 63, 20948697 sectors, code offset 0xc0


i then proceeded to launch my vm:

matthew@hufflepuff:~/vmware$ qemu -hda WinXP.img -m 365 -vga std

but it blue screened ... the only reliable function in windows. so, i researched the issue, turned out it was because i didn't remove the vmware drivers before performing all this work on my image file.

http://support.microsoft.com/kb/324764

The agp440.sys service had to be disabled so that WinXP would only load basic vga drivers.

i made an image of my WinXP install cd via dd:

matthew@hufflepuff:~/vmware$ dd if=/dev/sr0 of=./XPInstall.img bs=1024

then i ran qemu, let the cdrom image boot and followed microsoft's instructions:

matthew@hufflepuff:~/vmware$ qemu -hda WinXP.img -cdrom XPInstall.img -m 365 -vga std

and after making the changes, i booted my vm as normal:

matthew@hufflepuff:~/vmware$ qemu -hda WinXP.img -m 365 -vga std

tada! we have a hypervisor running a vm and utilizing less resources than vmware.

houston, mission accomplished!