Creating a Windows Virtual Machine Using Xen Project Hypervisor

In this tutorial we describe how to create a Windows 10 virtual machine using Xen Project hypervisor. To complete this task, we use an ISO file for the operating system (“OS”) installation and work our way through the process via a VNC connection to the new virtual machine.

The steps below assume you already have Xen Project hypervisor working on your computer. If this is not the case, check out our tutorial on how to get Xen Project working on Debian.

As the Windows instance will run as a hardware virtual machine (“HVM”), you’ll need the computer’s BIOS properly configured to get the HVM up and running. For more information on setting up your BIOS, see our post about BIOS Configuration Requirements for Xen Project HVM.

Finally, this tutorial assumes you have an ISO file with Windows 10 installation media. In this tutorial we’ll be using a file named “windows-10-pro-x64-en-us.iso”. Substitute the name of your Windows ISO in its place.

Step 1 – Create VM Disk

At this point, we need to manually create a disk or partition to allocate to the new virtual machine (“VM”). In past tutorials we’ve illustrated how to complete this step using LVM; however, in today’s tutorial we’ll create a raw disk image using qemu-img.

Since Windows 10 needs adequate space to run, let’s create a 50GB disk image named “windows10-hvm.img” in the “/root/” directory.

$ sudo qemu-img create -f raw /root/windows10-hvm.img 50G

Make sure to choose a disk image size for your VM based on your personal requirements. Keep in mind the basic Windows 10 OS install for this tutorial came in at around 37GB.

Step 2 – Create VM Configuration File

Now that we’ve created a disk image for the new VM, it’s time to create its configuration file. Note that the default directory for Xen VM .cfg files is “/etc/xen/”. Also, the Debian package maintainers have conveniently supplied us with example PV and HVM configuration files in this directory.

Opening the “/etc/xen/xlexample.hvm” file on my Debian 10 system shows the following uncommented lines:

type = "hvm"
name = "example.hvm"
memory = 128
vcpus = 2
vif = [ '' ]
disk = [  '/dev/vg/guest-volume,raw,xvda,rw' ]
sdl = 1

For references on these and other available key=value pair options refer to the xl.cfg manpage.

Let’s make a copy of this example configuration file for our new VM and call the copy “windows10.hvm”:

$ sudo cp /etc/xen/xlexample.hvm /etc/xen/windows10.hvm

Now we’ll open the new file with nano and edit it to suit our purposes:

$ sudo nano /etc/xen/windows10.hvm

Going down the list, the first option “type” is required for us to generate a HVM type VM: otherwise the configuration defaults to PV. As to the name of the new VM, we’ve chosen “windows10” as we’re not planning on having multiple Windows 10 instances and don’t need a unique name.

The memory value will be increased to 8000, which is in MB, as we have more than enough memory in our system to pass along to the Windows VM. Note that Microsoft’s minimum Windows 10 recommended memory is published as 2GB for a 64-bit system. However, we haven’t tested a Windows 10 VM running the minimum memory allocation and can’t attest to its stability.

Vcpus can stay at 2, and we’ll configure the VM to connect its virtual interface to our “bridge=xenbr0” setup.

Since we created a disk in Step 1, and we have our Windows ISO in the dom0’s Downloads folder, the disk section will look like this:

disk = [
    '/root/windows10-hvm.img,raw,xvda,rw',
    '/home/vidigest/Downloads/windows-10-pro-x64-en-us.iso,raw,hdc,cdrom'
    ]

Finally, we’ll turn off “sdl” by changing “sdl = 1” to “#sdl = 1”, and turn VNC on for the installation process by uncommenting the line that shows “#vnc = 1”.

In summary, the modified lines of our HVM configuration file should appear as follows:

type = "hvm"
name = "windows10"
memory = 8000
vcpus = 2
vif = [ 'bridge=xenbr0' ]
disk = [
    '/root/windows10-hvm.img,raw,xvda,rw',
    '/home/vidigest/Downloads/windows-10-pro-x64-en-us.iso,raw,hdc,cdrom'
    ]
#sdl = 1
vnc = 1

Don’t forget to save the changes to the configuration file.

Step 3 – Install VNC Program

Since we need to see and guide the Windows 10 installation process, the next step is to install a program that works with the VNC protocol. As we’ll be accessing the new VM via Dom0, we’ll need to install the VNC program on Dom0.

Although we have successfully installed Windows 10 on a HVM DomU using gvncviewer in the past, we regularly use remmina for remote desktop sessions and it’s a simple set up for the DomU VNC connection. On Dom0 run the following command to install remmina:

$ sudo apt-get install remmina

Once remmina is installed, setting up the VNC connection is as easy as going to “New Connection”, selecting the VNC protocol, and entering the Server as “localhost”.

Step 4 – Install Windows OS

Now that we have a virtual disk on which to install the VM, the DomU configuration file, and a way of supervising the OS installation process, let’s move on to the final step of actually installing Windows 10 on the VM.

Using the “xl create” command, start the OS installation process with the following command:

$ sudo xl create /etc/xen/windows10.hvm

Once the xl create process is initiated, we can connect to the DomU session over VNC using reminna. To do this, in remmina’s main window, double-click the localhost VNC connection you created in Step 3, above.

Follow the Windows 10 installation steps using the Tab, Space bar, and Enter keys to make selections if your VNC/Windows mouse/cursor alignment is off. Once the OS installation process is complete, if you find your VNC session finicky, considering enabling RDP connections in Windows for a better user experience.

One final tip: if your VNC session is not connecting and other VMs are running at the same time, note that you may have multiple VNC sessions running simultaneously.

To change VNC sessions, try modifying the VNC server address in remmina from “localhost” to “localhost:1”, or “localhost:2” to see if it fixes the connection issue.