Champagne Dev VMs on a Beer Budget
Others have posted on this very topic, but I rebuild my home/dev VM lab this past weekend, and it went so well I thought I’d share the steps I went through, in case it helps someone else to get started. I got my start doing this a while back with a very helpful post by Jonathan Kehayias on Virtualbox, but I have evolved my home lab since.
As I see it, today you have two choices for this sort of work
- A cloud service like Azure or Amazon, etc.
- A small, local VM farm on your laptop with your own storage and hypervisor.
There are advantages and disadvantages to each, obviously. Using the cloud you can have zero footprint on your own hardware, and not worry too much about disks and so on. On the other hand, you are tied to an internet connection, which can cramp your style when doing presentations.
The cloud frees you from a lot of setup tasks. Setup can be, depending on your perspective, dull work you need to plow through or a learning experience. I personally still like going through the process because I learn so much each time. Building servers and performing installation is still part of my job, at least for the foreseeable future. With the cloud you typically click through a selection from a catalog and your VM comes pre-built.
Just for the experience, I did both in the past few days.
Azure is quite straightforward. Here’s a screenshot showing an RDP session to my remote Azure VM, which came with SQL Server 2014 CTP preinstalled:
This is a VM with SQL Server installed – not the Azure PaaS SQL Server offering – so I have the whole OS to fool with here. Creating this was super simple. I have the advantage of an MSDN subscription, which provides credits on Azure for dev/test work. I activated that, and then just followed the instructions on the web site to provision a VM from a catalog image of a Windows 2012 / SQL 2014 CTP virtual machine. Literally click New > Virtual Machine > From Gallery and choose from the catalog.
You end up with the machine, RDP access, and also a nice portal dashboard with stats about the VM:
A few things commend this approach:
- Super easy
- Nothing on your machine
- Not permanent – the VM can be deleted easily when you are done
- This is what the future looks like, truly. It’s useful to learn about it and mitigate what Grant Fritchey has aptly called Buggy Whip Weaving.
It’s still feasible, of course, to install VMs locally, and these days it doesn’t cost much. I do this with 16 GB RAM in my laptop and a modest USB 3 external disk enclosure with a Crucial SSD inside. This setup works well for demo and learning VMs. I did have to purchase a USB 3 express card, my laptop lacking built-in USB 3, and the only downside is that the express card itself has proven dodgy*. It does not like fancy stunts like “Sleep” or “Restart” or “Eject” and so on. But I blame the card, not the solution architecture.
Hosting the VMs takes some hypervisor. In my case I have tried several but settled on Windows 8’s built-in Hyper-V. It’s free with the OS, all the basics work, and it has good PowerShell support, which I appreciate.
The main challenges with Hyper-V I experienced:
- No easy clipboard support to copy and past into and out of VMs with the console
- It just flat will not work to share my wifi in the laptop with the VMs. In order to connect the VMs to the Internet, which I only do intermittently for stuff like patching, I have to plug in to a physical network. I believe this is by design, but I don’t exactly understand the reasoning behind it. I spent a fair amount of time trying to fight this one but gave up.
For this generation of my home lab I followed this basic outline:
- Download Windows Server 2012 Datacenter Evaluation from Microsoft as a VHD. This is a pre-built virtual hard drive with the OS “installed” on it, ready to complete setup and use.
- Download SQL Server 2012 Enterprise Evaluation Edition as an ISO. I went this way because I do want to go through the setup steps.
- Extract the delivered VHD download to my external SSD disk and rename it.
For the setup I wanted, I need a domain controller and three or four SQL Servers. SSDs are fast, but capacity is expensive, so I found I could save a lot of space by using Hyper-V’s differencing disks. This basically allows you to make a “parent” hard drive image file, and then derive multiple virtual hard drives from it, storing only the differences. Other hypervisors also have this feature. By using this technique I am able to store four servers’ hard disks in about 28 GB of space on disk. The trick is the install order, and what will maximize the shared disk space.
Four VMs’ hard drives with Differencing:
I got good results with these steps:
Make a parent virtual hard drive for the OS
- In Hyper-V manager, make a virtual machine, and choose the downloaded Windows 2012 VHD file from Microsoft as the hard drive.
- I use two virtual switches in my Hyper-V setup, one for internal communication and one to connect out to the Internet. I set the VM up with a virtual network adapter for each.
- Start the VM and go through the setup process. This process will make the "parent” hard drive in the differencing disks, storing the bulk of the bits for the OS, but I want to embed the things that all the servers will share. So:
- Patch the machine by configuring Windows Update while connected to the Internet.
- Install .NET Framework 3.5 in Server Manager > Features while connected to the internet. This is important because SQL Server requires this, but it’s not on the VHD from Microsoft, and feature setup has to download it using Windows Update.
- This provides a working server hard drive that will allow us to derive the others without needing as much space as a full copy of the VHD.
- Sysprep this server by running sysprep.exe with the “generalize” option, so we can make clones.
Make a domain controller
- The first real machine is the DC. Shut down the “parent” vm above.
- In Hyper-V Manager, edit the properties of the virtual machine (or make a new one and specify that you’ll “attach a virtual hard disk later.”)
- Set the hard drive to be a new VHD file, using the differencing option. This file will use snapshot technology to retain only the blocks on the disk that are different from the shared parent disk, in a sense de-duplicating most of the hard drive content.
- Choose the virtual hard drive from above as the parent for the differencing disk.
- Boot the VM and go through the configuration tasks.
- The DC will want to have a static IP address. Visit Settings > Control Panel > Network and Internet > Network and Sharing Center > Change adapter settings. Right-click the network adapter and choose properties. Locate Internet Protocol Version 4. Click Properties and set the adapter to a static IP address. To keep things simple I usually use 10.10.10.1, then 10.10.10.2, then 3, 4, as I add virtual machines to the lab.
- From Server Manager, add roles and features, add the AD domain controller role, and follow the wizard there to set this up as the DC for the lab. I just use a domain called “arch.lab.”
- That gets us a little domain controller.
Make a parent virtual hard drive for SQL Servers
- Create a new VM in Hyper-V Manager, using the same technique: choose the option to “assign a virtual hard drive later,” then add a new virtual hard drive using the Differencing option, and the OS parent hard drive from the first section above.
- Boot this new VM, and run through the OS setup
- Install SQL Server on this vm, by mounting the SQL Server ISO file as a DVD in the virtual “dvd drive” provided by Hyper-V.
- Sysprep this VM, so it, too, can be cloned.
- Shut this VM down. This virtual hard drive will become the parent for all the SQL servers, basically de-duplicating the SQL Server product bits, and again saving space.
Make the actual SQL Servers
- Create three or four more virtual machines in Hyper-V manager, and for each make a new virtual hard drive of the differecing type, where the parent SQL Server VHD from the preceding section is the parent. Each of these machines will act like SQL Server is “preinstalled,” because of the previous steps, and the redundant bits will be stored only once in the parent VHD file.
- Start these and run through the configuration steps to set them up.
- Set a unique static IP address for these machines like the DC.
- Use Server Manager > Local Server > Computer Name to add each machine to the lab domain.
This was fun and educational for me, and now I have a fresh lab for talks I am giving this fall. You can, I hope, see the appeal of Azure, though. Even though I made only one Azure VM, it took a few clicks and most of the installation pain is just not there. Making the same four VMs as on my local lab, I can tell, would be fairly simple.
Update 20 Sept 2013: I found the Express card problem (Huzzah!). It was the defaults for PCI power saving in my laptop BIOS.