The task here is to install, run and administrate Windows 2003/XP/7 on a
remote server in Internet where Xen 4.x is already installed and HVM is supported in hardware.
The steps to install and run Windows are slightly different than for Linux Guests OS.
In these cases Q Emu virtualization drivers are needed to complete this task.
Here I will only describe what should be done that is different.
So I assume that the reader has some basic knowledge of Xen.

Windows 2003/XP/7 in 32 bits can run as guest VM under Xen.
Installing Windows requires full machine virtualization to run. In order to achieve this,
your machine needs the following requirements:
– Xen 4.x.x Hypervisor (see packages list below)
– Support for Hardware Virtualization HVM (see below for checking it)
– Q Emu drivers which use the HVM for full virtualization (included in the packages below)

Checkin for HVM support in your machine:
To check if your hardware supports HVM (Hardware Virtualization) issue the command:
cat /sys/hypervisor/properties/capabilities
The result should include the ‘hvm-xxx…. and hvm-xxx..p’ capabilities.
eg:
xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64if not so, then it’s most likely not possible to run Windows as guest OS under Xen in this machine.

Packages to install on Debian Squeeze:
libxenstore3.0
linux-image-2.6-amd64
linux-image-xen-amd64
linux-image-2.6.32-5-xen-amd64
xen-hypervisor-4.0-amd64
xen-linux-system-2.6-xen-amd64
xen-linux-system-2.6.32-5-xen-amd64
xen-qemu-dm-4.0
xen-tools
xen-utils-4.0
xen-utils-common
xenstore-utils
xenwatch

Installing and running Windows 2003/XP/7 server:

– Make a copy of the install CD into an ISO file.
eg.
dd if=/dev/hdc of=winxp.isoordd if=/dev/hdc of=win2003serv.isoordd if=/dev/hdc of=win7.iso

– Copy the ISO file to the Xen server using scp or any other tool.

– Create an LVM partition called WIN7 from the Volume Group ‘virtuals’
lvcreate -L 8G -n WIN7 virtualsIt will then be called: /dev/virtuals/WIN7
OR
– Prepare a 8GB installation ‘destination partition’ image file
Note: The option ‘conv=notrunc’ might not be needed for Win XP but is needed for Windows 7 and 2003 server
to avoid a failed loading of NTDETECT at first restart.
dd if=/dev/zero of=/home/xen/domains/winxp/winxp.img bs=1M count=8192 conv=notrunc

– Enable VNC in Xen config file: /etc/xen/xend-config.sxp
(vnc-listen '0.0.0.0')
(vncpasswd 'secret')

Restart xend service:
/etc/init.d/xend restart

– Create a Xen VM configuration file for it as follows:
Note: You might need to adjust some paths to your environment and DOMU Name
Configuration file settings gives:
RAM : 4096 MB
IP : Set by Windows in system settings
Boot : Boot from D: fro installation (CDROM ISO installation file.)
Display : Virtual VGA reachable via remote VNC client on port 5900
Reboot : Needs to shutdown(destroy) the machine instead of rebooting
This give the chance to change the boot drive after the initial install steps are completed.

Xen VM Configuration file(/etc/xen/win.cfg)

# Kernel + memory size
#
#
import os, re
#
device_model = '/usr/lib64/xen-default/bin/qemu-dm'
kernel = '/usr/lib/xen-default/boot/hvmloader'
builder = 'hvm'
#
memory = '4096'
#
# Should be at least 2KB per MB of domain memory, plus a few MB per vcpu.
shadow_memory = 36
#
# Hostname
name = 'WIN7'
#
# Networking
# The bridge name should coincide with the bridge name in result of the command : brctl show
vif = [ 'type=ioemu, bridge=eth0' ]
#
#
# Physical volumes
# Note: Here below I give examples of installing windows 7 on an LVM drive, and other windows on Virtual Drives(8 GB File)
# Just use or combine what is appropriate for you.
#
########################
# For installation only.
########################
# Booting D: (CDROM) (Activate the appropriate line below, then deactivate it after installation before first boot from HD)
#disk = [ 'file:/home/xen/domains/winxp/winxp.img,ioemu:hda,w' , 'file:/root/winxp.iso,ioemu:hdc:cdrom,r' ]
#disk = [ 'file:/home/xen/domains/win2003serv/win2003serv.img,ioemu:hda,w' , 'file:/root/win2003serv.iso,ioemu:hdc:cdrom,r' ]
#disk = [ 'phy:/dev/virtuals/WIN7,ioemu:hda,w' , 'file://home/michel/ISO/win7_ultimate.iso,ioemu:hdc:cdrom,r' ]
#
# Activate the following 2 lines for installation then deactivate them after installation before first boot from HD.
#boot = 'd'
#on_reboot = 'destroy'
#
##########################
# After installation only:
##########################
# Note: this configuration is booting and only uses drive C:
# Booting from the HD. (Activate the appropriate line below)
#disk = [ 'file:/home/xen/domains/winxp/winxp.img,ioemu:hda,w' ]
#disk = [ 'file:/home/xen/domains/win2003serv/win2003serv.img,ioemu:hda,w' ]
#disk = [ 'phy:/dev/virtuals/WIN7,ioemu:hda,w' ]
#
# Activate the following 2 lines after installation, before first boot from HD.
#boot = 'c'
#on_reboot = 'restart'
#
# System
acpi = 1
apic = 1
#
on_poweroff = 'destroy'
on_crash = 'restart'
#
# Using VNC port 590x for as screen
vnc = 1
sdl = 0
vncunused = 0
pae = 1
vcpus = 2
cpus = "2-3"
vncconsole = 1
vncpasswd = 'secret'
serial = 'pty'
usbdevice = 'tablet'

STEPS:

0 – Activate the appropriate installation physical volume in configuration file(/etc/xen/win.cfg)
1 – Start the Xen VM for first installation, and interact via VNC client. (Xen-servername:5900)
2 – After initial installation steps are completed the system will shutdown.
3 – In configuration file, deactivate the line “boot = ‘d'” and activate the line “boot = ‘c'”
Deactivate the line “on_reboot = ‘destroy'” and activate the line “on_reboot = ‘restart'”
4 – Restart the VM(xm create ….), reconnect the VNC client and continue the installation
5 – Configure manually the TCP/IP parameters(IP, Gateway, DNS) in Windows
6 – Configure and activate RDP in Windows
7 – Shutdown windows
8 – Disconnect the Installation CD (ISO file) from within the VM config file
eg. Deactivate the lines above in configuration file that were needed for Installation and activate the ones for normal operation(After installation)
9 – Restart Windows and connect to its display and login as Administrator via RDP client

DETAILLED STEPS:

0 – Make sure the configuration is pretty much the same as above except for your paths, the ISO filenames.
Activate the appropriate media drive in the configuration as follows (eg. for windows XP)
disk = [ 'file:/home/xen/domains/winxp/winxp.img,ioemu:hda,w' , 'file:/root/winxp.iso,ioemu:hdc:cdrom,r' ]
#disk = [ 'file:/home/xen/domains/win2003serv/win2003serv.img,ioemu:hda,w' , 'file:/root/win2003serv.iso,ioemu:hdc:cdrom,r' ]
#disk = [ 'phy:/dev/virtuals/WIN7,ioemu:hda,w' , 'file://home/michel/ISO/win7_ultimate.iso,ioemu:hdc:cdrom,r' ]
boot = 'd'
on_reboot = 'destroy'

1 – Start the VM:
xm create /etc/xen/win.cfg
Connect to the VM via VNC
vnc-viewer xxx.xxx.xxx.xxx:5900
Go through the initial Windows installation steps.
Note: Make sure you fully format the destination drive as NTFS.

2 – After first initial installation Windows will provoke a reboot automatically.
Since the above configuration converts ‘reboot’ to ‘destroy’ (Shutdown) it won’t reboot but simply shutdown.
We use this opportunity to change the boot drive in the configuration file.
Therefore do the next step before booting again.

3 – Change the boot drive and reboot action directives in configuration file as follows:
Deactivate the following lines as follow:
#boot = 'd'
#on_reboot = 'destroy'

Activate the following lines as follow:
boot = 'c'
on_reboot = 'restart'

4 – Boot the VM again:
xm create /etc/xen/win.cfgand reconnect to its display via a VNC client.

5 – When Windows is fully installed, configure the TCP/IP connection manually incl:
– IP, Gateway and DNS settings.

6 – Activate RDP service in Windows
System Settings --> system --> remote ---> Remote desktop
(IMPORTANT: make sure Administrator has a password configured before you activate it)

7 – Shutdown Windows manually from within Windows.

8 – Disconnect the ISO file from Drive D: (Installation CD is no more needed)
Change the VM config file as follows:
Deactivate the line you had activated for installation so that it looks like this
#disk = [ 'file:/home/xen/domains/winxp/winxp.img,ioemu:hda,w' , 'file:/root/winxp.iso,ioemu:hdc:cdrom,r' ]
#disk = [ 'file:/home/xen/domains/win2003serv/win2003serv.img,ioemu:hda,w' , 'file:/root/win2003serv.iso,ioemu:hdc:cdrom,r' ]
#disk = [ 'phy:/dev/virtuals/WIN7,ioemu:hda,w' , 'file://home/michel/ISO/win7_ultimate.iso,ioemu:hdc:cdrom,r' ]

Activate the appropriate line according to the type of windows you have installed. eg, for Windows XP
disk = [ 'file:/home/xen/domains/winxp/winxp.img,ioemu:hda,w' ]
#disk = [ 'file:/home/xen/domains/win2003serv/win2003serv.img,ioemu:hda,w' ]
#disk = [ 'phy:/dev/virtuals/WIN7,ioemu:hda,w' ]

9 – Start Windows and connect to it via RDP
xm create /etc/xen/win.cfg

Note 1: The use of VNC client is absolutely needed and ‘kind of OK’ for the installation.
I say ‘kind of OK’ because the mouse movements were not tracking well with my VNC client. Maybe other are doing better.
I had to fiddle around with the way I move mouse (changing movement speed, etc.)
to get it to go to the right places. For that the use of RDP is much better and also faster.
If your VNC mouse tracks well, then you have 2 ways to chose from as remote display.

Note 2: After a shutdown of windows the ssh connection to the Xen Dom0 might be blocked for about 15 sec. and then works well again. At least that is what happened in my server.