In the previous articles in this series (already a few months ago) we’ve setup our hypervisor, virtual networks, internet connectivity, routing and firewall. But apart from our virtual router, our testlab is still looking rather empty. How about some virtual machines?
I also received some comments on why I don’t go to the cloud with my setup? As a matter of fact – I have almost the same setup in Microsoft Azure, but conference wifi has bitten me more than once so having a backup available offline saved me quite a few times already. I can’t count the times I’ve witnessed nervous fellow presenters in a speaker room because the internet connection was lacking. Granted, you can’t demo cloud stuff with my setup.
Template Creation & Maintenance
The idea is to have as little work as possible to instantiate a new virtual machine. I usually create two basic templates: one running the latest server OS, and one running the latest client OS. From those templates I then create additional ones with basic SharePoint or SQL Server builds.
Creating these templates is easy: just start by creating a new virtual machine. For both templates I create a 2nd generation virtual machine with all default options and attach an ISO file for Windows setup. After creation, I make the following changes:
- Attach to the external “NAT” virtual network
- Increase the assigned memory to 2048 MB
- Increase the number of virtual processors to 2
- Don’t startup the guest automatically when the host starts
- When the host shuts down, shut down the guest too
I then proceed to the operating system setup, which is basically next-next-finish. I usually choose the Datacenter edition with a GUI. After setup, I perform the following additional steps:
- Change the hostname
- Change the DVD drive to X
- Change Power Options to “High Performance”
- Activate the operating system
- Install all Windows Updates through PowerShell
- Notepad2 & 7-Zip installation
- Install the .NET 3.5 & Telnet Client features
- Enable Remote Desktop and disable Internet Explorer enhanced security
- Disable CRL checking
- Change PowerShell execution policy to RemoteSigned
- Disable loopback checking – with the less recommended workaround 🙂
- Install the current Sysinternals suite in c:\tools
When the basic build is done, I shutdown the guest and take a checkpoint (snapshot). I call this checkpoint “Baseline”. Then I power on the machine again and run Sysprep with the “Generalize” option. Can you can tell I’m an old school IT PRO now?
Finally I shutdown the guest again and create a final checkpoint called “Sysprepped”. Whenever I create a new virtual machine in the future, it’s going to be based upon this “Sysprepped” image.
Creating a new virtual machine
In VMware Workstation I used cloning to create new virtual machines based on my templates. In Hyper-V I’m using another approach.
First of all I export the Sysprepped image to a standalone, consolidated disk image. Select the checkpoint, right-click and choose Export:
I export the virtual machine checkpoint to my local disk. You can follow the progress of the export in the Hyper-V Manager console.
After the export is finished, I just keep the virtual disk file and remove all the rest. Then I give it a more descriptive name and we’re done:
Now when I want to create a new virtual machine, I just copy that vhdx file to my regular virtual disks folder and reference that when running the new virtual machine wizard. Sure, that takes a minute and sure, you could use PowerShell to automate all this – but I don’t rebuild my testlab that often so I don’t really care.
This is how my virtual machines folder looks like at this point. The DC01.vhdx file is the copied checkpoint export.
Connect your new virtual machine to the provisioned vhdx file upon creation:
Next, startup your virtual machine and run through the setup options. After a few seconds your new server is up & running with all the configuration and utilities you want.
Keeping the templates current
A few times a year I want to update my virtual machine images with Windows Update or new tools. To do so, apply the baseline template to your original machine, make your changes and follow the same sequence again:
- shutdown the guest
- create the “Baseline” checkpoint
- poweron the guest
- run sysprep with the generalize options
- shutdown the guest
- create the “Sysprepped” checkpoint
- remove the original “Baseline” and “Sysprepped” checkpoints
- export the “Sysprepped” virtual machine
- rename the exported virtual disk file
- remove the original exported virtual disk file
Now you have a new fresh template to create new virtual machines from.
The last part in this series will focus on the creation of the domain controller. Stay tuned!