Friday, 8 October 2010

Installing Windows on Xen

This article will address installing Windows 2003 server on Xen 3.x running on headless Centos server

The dom0 xen server is headless making it much difficult to transfer the graphical interface.

I thought installing windows was quite easy on xen by following various articles on the internet but it needed some troubleshooting and investigation to clearly install windows on xen as most of the articles show that the vnc or graphical display will automatically pop out. But the reality is that it is quite a task to figure out which options to configure for the display to come out and how to configure the configuration file properly as I struggled without proper errors in case the machine fails to boot as the disk in not bootable error. In that case we need to configure the options 'boot=d' instead of 'boot=c' and also change the cdrom option to the iso file properly in the domU config file. Then also have to do
1) xhost
2) ssh -X
3) virt-install --prompt
and follow the instructions
4) xm destroy
5) edit the configuration file according to the example given below
6) see that sdl = 1 and vnc = 0 is configured in case we need host access directly instead of vnc
7) xm create

At this point if everything is good the graphical installation should pop out on to the workstation. if not check /var/log/xen/qemu*, /var/log/xen/xend.log

Still I can't get VNC to work with the current setup will work on it afterwards if I have time but mainly I've managed to install the windows on xen using sdl.

Preparation Windows image
To create windows installation image is optional, and just describes a way that I’ve set things up that makes it easier to commission more than one VM. You can also use /dev/cdrom instead with the help of virt-manager.
Create a folder for the ISO image. the folder could be named like this /tmp/windows, we’ll use this directory to store a windows dump image from CDROM.
Put your windows installation disc in the CDROM drive.When it’s mounted, issue a command as follows:
dd if=/dev/cdrom of=/tmp/windows/windows-xp.iso
If the CDROM cannot mounted automatically, you might need to mount it yourself. It would take a long time to dump a full windows images depending on the disc’s size.
Create DISK file for Virtual Server
After that, we need to create a disk image file for the virtualized WinXP. Here we store this file in a new sub directory /srv/xen. You might need to create this directory yourself if you are using CentOS. The hard drive of the virtual machine can be created like this:
nice dd if=/dev/zero of=/srv/xen/winxp.img bs=1024k seek=4096 count=0

Dont forget that raw disk is also supported by Xen

If we want to use logical volumes we can create a logical volume as follows:

lvcreate --size 30G --name windowstest_root XenVolGroup01

nstall Windows in Xen Container
Then we can start the installation process with help of virt-install command:
virt-install -n winxp -r 256 -f /srv/xen/winxp.img -b xenbr0 --sdl -v -c /tmp/windows/windows-xp.iso
or we can use the following for interactive install: virt-install --prompt
This command will create a configuration file /etc/xen/winxp, start the new virtual machine, and try to connect to it. Here’s a bit problematic. As you may wonder how we gain the access to windows graphic desktop during the installation.
Generally there are two ways: 1, Using the physic server’s graphic instead. When you have grphic access to physic server, you can use virt-manager’s grphic interface to control the process. 2, You can use VNC client to connect virtual windows XP directly. By default when the installation started, there’s a VNC server running at localhost. It’s configurable in /etc/xen/winxp, you can set which socket it should bind to, and what password can be used to connect this running windows.
Some other adjustings to /etc/xen/winxp are highly recommended. We need to make note that when any error happened, the winxp should be shut down soon not hanging or doing some other crappy things that only god knows.
* ‘on_crash‘ should be changed to ‘destroy‘. * Change the line on_reboot = ‘restart’ to on_reboot = ‘destroy’. This will ensure that Windows doesn’t restart during setup without our permission, which will be required for ACPI support in the guest to be set up properly. * Add file:/var/lib/xen/images/winxp-install.iso,hdb:cdrom,r’, to the list in the line disk = [ ... ] * Add new line boot = ‘d’ (preferably after the line disk = [ ... ].).
name = "winxp" uuid = "821cc805-ecc3-cc1a-20de-79d4bc99c134" maxmem = 256 memory = 256 vcpus = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" pae = 1 acpi = 1 apic = 1 localtime = 0 on_poweroff = "destroy" on_reboot = "destroy" on_crash = "restart" device_model = "/usr/lib64/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 vnclisten = "" vncpasswd = "virtual-chen" keymap = "en-us" disk = [ "file:/srv/xen/winxp.img,hda,w", "file:/tmp/windows/windows-xp.iso,hdc:cdrom,r" ] vif = [ "mac=00:13:34:ae:70:3b,bridge=xenbr0" ] serial = "pty"
Then re-launch the virtual machine with “xm create winxp“,and use VNC to connect the virtual OS, and direct the installation process. When finished, setup tries to reboot, it will instead be shut down. Don’t panic, this is intentional and was created by the line on_reboot = ‘destroy’ that we modified in the config file.
Things to do when installation finished
Now we need to recover the settings that we’ve made to /etc/xen/winxp:
* Change the line boot = ‘d’ to boot = ‘c’
* Change the line on_reboot = ‘destroy’ to on_reboot = ‘restart’
Continue the setup process by restarting the virtual machine with “xm create winxp“. Run through the rest of the normal Windows setup process, for example add the machine to the domain.
Install TightVNC in the guest so that you can access the guest remotely, so that the virtual machine is accessble while we are not logged into the physical machine. Boot the virtual machine with xm create winxp. If successful, the virtual machine will not show a display, but will show up in the results of xm list and you can connect to it with vncviewer,TightVNC, etc.
Trouble shooting
If something goes wrong and you can’t connect via VNC or rdesktop, you can use virt-manager (aka Applications → System Tools → Virtual Machine Manager) to connect directly to the virtual machine’s console and see what it’s doing. Please keep note that using virt-manager depends on graphic destop at the physical server, which always eats lots of system resournces
Following is the forum entry which helped me figure out my error:
Upon further investigation the 'exception looking up...' is a harmless warning.
I changed the configuration file to
on_poweroff = 'preserve' on_reboot = 'preserve' on_crash = 'preserve'
This then allowed me to connect with VNC since the domain is not destroyed on a failed boot or crash. This showed the error message
CDROM boot failure : 0002
I then reverted to the original cdrom access syntax
disk = [ 'file:/etc/xen/win2000.img,ioemu:hda,w', ',hdc:cdrom,r' ]
This then shows the following console output
ata0 master : QEMU ... ata0 slave : Unknown device ata1 master: QEMU CD-ROM ... ata0 slave: Unknown device
CDROM boot failure code : 0003 Boot from CD-Rom failed FATAL: Could not read the boot disk
I know the boot disk is readable, and a bootable Windows 2000 CD. >>>> Anyone any ideas?
I then created a copy of the CD ROM as a disk file, and changed the disk line to read
disk = [ 'file:/etc/xen/win2000.img,ioemu:hda,w', 'file:/etc/xen/win2000.iso,hdc:cdrom,r' ]
And wow! windows boots. Now to get a clean Windows install working fully.
PS. pardon the poor file locations - this is a scratch install until I get everything working.
appologize for taking so long on this, it has taken a bit of infrastructure to be able to set up for testing. As a result, responses shoudl come more quickly now. As I understand it now, your remaining problem is using the CDROM itself vs an iso image file? For this you would need to specify the disk line as:
disk = [ 'file:/etc/xen/win2000.img,ioemu:hda,w', 'phy:/dev/hdc,ioemu:hdc:cdrom,r' ]
Assuming your CDROM drive is /dev/hdc. If it is not you can replace the /dev/hdc piece with the physical location of your cdrom drive on the dom0
YEAH ! Now I can get the console. VNC has a really slow rendering. But "ssh -X" looks nice.


  1. after successful installation dom0 is successfully listening on 5919 port therefore we can use


    for connecting to the windows domU and enable remote connections and terminal services for remote desktop connection which will be much faster than vnc

  2. we may also have to enable vnc configuration in the xen config file /etc/xen/xend-config.sxp to listen on either for complete listing or localhost or < server ip>

    then restart xend and domU's

    xend restart

  3. to remove the logical volume :

    lvremove -f /dev/XenVolGroup01/windowstest_root