For the past month I've been tinkering with OpenStack on my home server just to see what it's all about. If you're not familiar with this software please feel free to check out the link I've included at the bottom of this post in the references section. Basically, it's open source software that allows you to build your own private or public cloud. The actual installation of the software is outside of the scope of this post but Martin Loschwitz has already done an excellent job of this (You can find the link for this at the bottom of this post as well). Since there didn't seem to be a great deal of information on how to properly create a Windows image in OpenStack I figured I'd throw a little something together for everyone else out there that's interested.
If you haven't done so yet we'll need to create a Floating IP range within OpenStack but before we do this let's make it a bit easier on ourselves and run the following commands:
If this isn't performed then you would need to append --os_tenant_name, --os_username, --os_password, and --os_auth_url to almost every command we will be running in this post. Now that we've taken care of that let's go ahead and create some floating IP addresses.
The floating IP range we're about to create will allow access from the outside world to your guest machines but is not necessary for them to be able to communicate to the outside world. If you don't need access to these machines publicly or you've already created a floating IP range then you can skip this step:
nova-manage floating create --ip_range=192.168.1.32/27
I should note that I have deviated from the walk-through I mentioned earlier just a bit as I am using the 192.168.1.0 network for public access and the 10.10.10.0 network for the IP scheme of the guest machines.
Now that the IP range has been created we will need to create the initial image that we will use to install Windows by issuing the following command:
kvm-img create -f raw server2008.img 50G
There are two different formats that can be used here, raw and qcow2. I would recommend using the raw format rather than qcow2 as raw performs better and does not require any additional tools to work with it. The last part of the command is specifying the amount of hard drive space that will be allocated to this image. Microsoft recommends 32 GB of hard drive space for Server 2008 but I will be installing some additional software on the image as well so I gave it some extra space.
The next step in the process is to mount the iso for the server installation and connect to it using VNC to perform the actual install. I used TightVNC for this as it's free (In case you haven't noticed I'm a pretty big fan of free ). You will also need the virtio drivers in order for Windows to be able to see the disk. You can download the virtio drivers via wget by using the following command:
Here is the command you will need to execute next:
kvm -m 2048 -cdrom server2008.iso -drive file=server2008.img,if=virtio -drive file=virtio-win-0.1-30.iso,index=3,media=cdrom -net nic,model=virtio -net user -nographic -vnc :0
The main items you need to know about this command is the -m is the amount of memory you are allocating to the initial image in megabytes, the -cdrom should point to the iso you are using for the installation, and the -vnc :0 portion establishes the port you will need to connect to over VNC where :0 is equal to port 5900. If you already have some virtual machines running on OpenStack you may need to specify a higher value for the VNC parameter, such as -vnc :5, and connect to it using port 5905.
Once connected over VNC you will notice that Windows can not detect any hard drives so you'll have to install the virtio drivers from the file that was downloaded earlier. You can find these drivers in the WLH folder under the x64 folder (These drivers also work for Server 2012). After the installation is complete you can now modify the image to suit your liking. Here's a short list of some changes that I made:
- Disable UAC
- Disable Windows Firewall (this should be left on if your server is not behind a hardware firewall)
- Enter a valid license key
- Install the drivers for the network adapter
- Enable Remote Desktop
- Rename the administrator account
At this point your machine will not have network connectivity so running Windows Updates is not possible. Also, it's a good idea to move the drivers from the virtio.iso folders over to a new folder on the image. That way you can install the virtio drivers for the network adapter later on if you forget. The drivers for the network adapters can be found in the Win7 folder under the x64 folder (again this same driver will work for Server 2012). Once you have configured the image to suit your needs shut it down. If you need to install additional software, such as SQL 2012 or SharePoint 2010, you can do so by issuing the following command:
kvm -m 8192 -smp cores=4,threads=1,sockets=1 -cdrom sql2012.iso -drive file=sql2012.img,if=virtio -net nic,model=virtio -net user -nographic -vnc :0
Since the operating system has already been installed you can attach another iso in the -cdrom parameter and since the virtio drivers are no longer needed it can be removed as seen in the command above. You can also assign multiple CPU cores with the command to help make the installation process a bit faster. As you can see in the command I used I assigned 8 GB of RAM and a quad-core CPU. Once you are ready you can upload the image to Glance using the following command:
glance add name="Windows Server 2008" is_public=true os_type=Windows container_format=ovf disk_format=raw < server2008.img
This command will fail at the very end if you've forgotten to export the variables I mentioned at the very start of this post. You can also perform a dry run to verify the command will work as expected by adding --dry-run after glance in the command shown above. You can verify the image was successfully uploaded by running the 'glance index' command.
Now that the image is uploaded and available let's access the dashboard to create our first instance of the image. The first step in this process will be to create a new flavor which is basically a template specifying the amount of RAM, CPU, and disk space that will be allocated to your instance. Once you have logged into the dashboard you can create the flavor simply by selecting Flavors from under the System Panel and selecting Create Flavor on the top right hand side. From here you can assign it a name, VCPU's, RAM, and disk space (If you have no need for an additional drive you will need to specify 0 for the Ephemeral Disk).
Once the flavor has been created click on the Project tab on the left, select Images & Snapshots, and select Launch.
Give the instance a name and select the appropriate flavor you would like to use for the instance. While the instance is being built let's go back to the Project tab and select Access & Security. From this screen you can choose to Allocate IP to Project from the top right hand side and you should see an option for nova in the drop-down. Click on Allocate IP and you should see the new IP address available in the dashboard. You can then select Associate Floating IP and choose the instance you are creating to allow public access to the machine.
The final step in this process will be edit the rules of the default security group which can be found on Access & Security section as well. Under the Security Groups section you will see a group called default. Select Edit Rules on the right hand side to open up the next dialog so we can allow the Remote Desktop port.
This part can be a bit misleading as it almost looks like you are setting up port forwarding but we're actually doing is allowing a range of ports so they guest machines can be accessed externally. You can also allow ping requests by adding another rule using ICMP as the IP Protocol and -1 for both the Type and Code. Once that's been set up and the instance has been built you should be able to successfully establish a Remote Desktop session to it using the Floating IP we created.
OpenStack Essex - http://docs.openstack.org/essex/
Install OpenStack - http://www.hastexo.com/resources/docs/installing-openstack-essex-20121-ubuntu-1204-precise-pangolin