In this article I will show how to install a Windows 7 64-Bit image on OpenStack. For different versions of Windows watch out for the corresponding notes in the article.
Prepare the Installation
Ubuntu, QEMU and KVM
Creating a Windows image from scratch is best done by using a linux distribution to do the installation process. To create the image we will use QEMU and KVM, which is a full virtualization solution for Linux. On Ubuntu you can install KVM using the following commands in the shell:
$ sudo apt-get update $ sudo apt-get install qemu-system-x86 $ sudo apt-get install qemu-kvm $ sudo apt-get install virt-manager $ sudo apt-get install libvirt-bin libvirt-doc
If you are working on a Windows or Mac machine you can not use a Linux-VM to do the installation. The VM will not be able to use the hardware virtualization extension (Intel VT or AMD-V).
To store the iso files we create a directory called “iso” in the home directory. That step is not mandatory, but will help you to use the following commands.
$ mkdir ~/iso
First you need an iso-file of Windows. Download a Windows ISO-File from your preferred site; e.g. a link for Windows 7 Professional can be found on the community website of microsoft). Move the iso file in the “iso” directory.
As for all Microsoft products you need to buy a license key to use the operating system, even if it is used as a VM.
The tricky part to create a Windows image for OpenStack is to use the proper driver for the virtualized hardware components like the IDE controller and the network interface. Download the latest digital signed VirtIO drivers from Fedora and move it to the iso directory.
Create the image
Create the container file
Now after doing all preparation steps we can create the image. This image file will hold the Windows installation. Like before you could create a directory called “image” on your home directory to store the image file.
$ mkdir ~/image $ cd ~/image
Use the following QEMU command to create the image file.
$ qemu-img create -f qcow2 win7_sp1_x64_en_vlk.qcow2 100G
That command will create a image with qcow2 as format, win7_sp1_x64_en_vlk.qcow2 as a name and with a capacity of 100GB. At the moment that is only a container for the installation.
Start the VM
The next step is to launch a VM with KVM and start the Windows installation.
$ sudo kvm -m 2048 -drive file=~/iso/windows_7_professional.iso,index=1,media=cdrom -drive file=~/image/win7_sp1_x64_en_vlk.qcow2,if=virtio -drive file=~/iso/virtio-win-0.1-74.iso,index=3,media=cdrom -net nic,model=virtio -net user -nographic -vnc :9 -usbdevice tablet
That command will start a VM with following settings:
- -m 2048: does allocate the memory size of the VM
- -drive file=~/iso/windows_7_professional.iso,index=1,media=cdrom: the VM will have a virtual CD-ROM drive attached containing the Windows 7 iso (will act like a normal Windows 7 installation CD/DVD)
- -drive file=~/iso/virtio-win-0.1-74.iso,index=3,media=cdrom: the VM will have a virtual CD-ROM drive attached containing the VirtIO iso
- -drive file=~/image/win7_sp1_x64_en_vlk.qcow2,if=virtio: the VM will have a virtual hard disk attached which will use the image file we just created as storage and the VirtIO drives as a storage interface
- -net nic,model=virtio -net user: sets the VirtIO driver for the network interface card (nic) with a user-mode network stack that bridges to the host’s network
- -nographic: disables graphical output
- -vnc :9: enables VNC on port 5909
- -usbdevice tablet: Use an USB tablet instead of the default PS/2 mouse. Recommend, because the tablet sends the mouse cursor’s position to match the host mouse cursor.
Use a VNC-Client to connect to your new VM (on Ubuntu you can use Remmina, which is part of the distribution). The server is reachable on the server address: localhost:5909.
The first one is while choosing the type of installation. You need to do a custom installation, which allows you to install the VirtIO drivers.
Choose “Custom (advanced)”.
Select “Load Driver”.
Navigate to the CD Drive with the VirtIO drivers. For the Windows 7 64bit version you need to select the “WIN7” -> “AMD64” directory. Click “OK”.
Find the right driver for your Windows Version:
|Windows Server 2008 32-bit||\VISTA\X86|
|Windows Server 2008 64-bit||\VISTA\AMD64|
|Windows Server 2008 R2 32-bit||\WLH\X86|
|Windows Server 2008 R2 64-bit||\WLH\AMD64|
|Windows 7 32-bit||\WIN7\X86|
|Windows 7 64-bit||\WIN7\AMD64|
|Windows 8 32-bit||\WIN8\X86|
|Windows 8 64-bit||\WIN8\AMD64|
|Windows Server 2012||\WIN8\X86|
|Windows Server 2012||\WIN8\AMD64|
Select the listed drivers (one for the Ethernet Adapter and one for the Hard Disk Controller). Click “Next”.
Now you should be able to select the prepared image file as the disk for the installation.
The second step of the installation where you need to be careful is when you have to insert the Windows product key.
This step is not crucial. You do not have to insert the product key right now. Windows will run for 30 days without product key. So it could be handy to insert the product key and activate Windows when the installation is completely done and Windows is running on OpenStack without troubles.
Click on “Skip”.
Finish the installation, but do not install the updates right away. You will do that on OpenStack.
Image is complete
The underlying image file that you created further up with the shell command qemu-img create, such as ~/image/win7_sp1_x64_en_vlk.qcow2 is now ready for uploading to the OpenStack Image Service.
At that point the image should be about 8GB big for Windows 7. That image can now be uploaded to OpenStack. There are mainly 2 ways to do that; either by the OpenStack Dashboard or the CLI-client. The size of Windows images can grow rapidly. After an update you might end with a size of 17GB. We had problems to upload big images, so try out both upload method.
To upload the image you can login to the dashboard, switch to “Images & Snapshots” and click on the “+ create Image” button.
The image can be uploaded from a valid HTTP URL or from the local disk.
The format needs to be QCOW2.
You can use the python glance client to upload the image via a terminal. Install the python client and than use the command similar to the following one to upload the image:
glance image-create \ --name Windows-7 \ --disk-format=qcow2 \ --container-format=bare \ --property hw_disk_bus=virtio \ --property hw_vif_model=virtio \ --file=./win7sp1_x64_vlk.qcow2
The meaning of the parameters are as follows:
- — name: sets a name for the image
- — disk-format: file format of the disk image, qcow2 is the file-format supported by QEMU
- — container-format: container which holds the image and metadata, bare indicates there is no container or metadata
- — property hw_disk_bus: sets metadata properties on glance, here: sets the disk controller to virtio
- — property hw_vif_model: sets metadata properties on glance, here: specifies the model of the network interface device to virtio
- — file: location of the file that needs to be uploaded
Use the image
Launch an instance of Windows image
On the dashboard you need to go to the image section. There you can create an instance from your new Windows image.
Choose the flavor which fits the disk size of the image. In our case the disk size of the image was set to 100GB so we choose the flavor with 160GB total disk.
The first build of the VM can take a while.
Connect to Windows
Click on the Windows instance and than on “Console”. This will open a connection through the embedded VNC client of the browser. If all went right the Windows welcome screen should show up.
Remote Access Protocol (RDP)
To be able to use the RDP to open a connection to Windows you need to enable the access in the Windows settings. From a RDP client you can than connect to the VM by using its allocated floating IP address. The standard port for RDP is 3389.
Enable the remote desktop on Windows
Open the “Control Panel” and chose “Allow remote access” from “System”.
Select the middle option: “Allow connections from computers running any version of Remote Desktop”
This will do the necessary firewall settings.
Enable the remote desktop on OpenStack
You also might need to set a new rule in the security group of OpenStack to allow a connection with RDP.
Troubleshooting measurements for RDP-connection interruption
If the connection is lost after a few seconds the problem is probably DHCP. Deactivate DHCP in the Windows settings and use the IP address (e.g. 10.10.x.x.) you got from DHCP as a fix address instead. Do not use the floating IP address. The IP address can be taken from the OpenStack dashboard under “Instances”. In Windows you have to open “Network and Sharing Center” -> “Change adapter settings” -> right click on your network connection -> Properties.
Double click on “Internet Protocol Version 4 (TCP/IPv4)”.
Click on “Use the following IP address”.
Then set the “IP address”, the “Subnet mask” and the “Default gateway”.
It is also necessary to set the DNS addresses.
By following this guide you should now have a Instance of Windows running on OpenStack. Enjoy your new image!