Configuring Virtual Machines with Windows Templates

We have recently been working on deploying Windows VMs using OpenNebula templates and, although the process can be optimized, the basic steps are enough to automate this process and deploy dozens of Windows VMs simultaneously in a couple of minutes. We thought we would share our experience through the OpenNebula blog.

Basically, we developed a set of scripts that handle the contextualization of the Windows VM on boot. Using the OpenNebula context.sh script, ours scripts configure username, password, IP, gateway, DNS, hostname, Remote Desktop and even leave a README file on Desktop with credentials and recommendations.

To use these scripts, you must have a Windows machine installed on a raw or qcow file. Windows 2008 (64-bit) and Windows 7 (32/64-bit) have been successfully tested with this approach.

To give you an idea, here is an example of a Windows 2008 ONE template:

CONTEXT=[
  FILES="/opt/opennebula_shared/context-scripts/windows/startup.vbs
              /opt/opennebula_shared/context-scripts/windows/one-context.ps1 
             /opt/opennebula_shared/context-scripts/windows/unattend.xml
             /opt/opennebula_shared/context-scripts/windows/README.txt 
             /opt/opennebula_shared/context-scripts/windows/SetupComplete.cmd",
  HOSTNAME=Win2008-$VMID,
  IP_PUBLIC="$NIC[IP, NETWORK=\"Classes Network\"]",
  PASSWORD=thepassword,
  ROOT_PUBKEY=id_rsa.pub,
  USERNAME=theusername
]

CPU=1

DISK=[
  BUS=virtio,
  DRIVER=qcow2,
  READONLY=no,
  IMAGE_ID = 12,
  TARGET=vda,
  TYPE=disk 
]

FEATURES=[ ACPI=yes ]

GRAPHICS=[ TYPE=vnc ]

MEMORY=2048

NAME=Windows2008-SQL2008-VS2010

NIC=[
 MODEL=e1000,
 NETWORK_ID=4 
]

OS=[
  ARCH=x86_64,
  BOOT=hd 
]

TYPE=kvm 
]

We are already using these templates on our OpenNebula server at the Institute of Electronics and Telematics Engineering of Aveiro, and everything has been running smoothly for a month!

Feel free to comment or ask for help. Please visit our guide on Using Windows Images for new Virtual Machines for more information, including the contextualization scripts needed by the template.