Copying virtual machines made easy (sort of)
As I mentioned in my previous post on Virtual Server 2005, it’s very easy to create a base virtual machine that contains (for instance) a fully patched version of Windows XP Pro and copy it around to work with multiple instances since all a VM really is is just a .vmc (Virtual Machine Configuration) and .vhd (Virtual Hard Drive) file. Making a copy of a VM is just a matter of creating a new machine in the Virtual Server web interface and copying the .vmc and .vhd files over the ones created. The only changes required are two values in the .vmc xml file: one pointing to the absolute path of the .vhd file to use and another that points to the relative path of the same file (in my experience if you change only one of these it will use the absolute path, don’t ask how I discovered that, it wasn’t very funny, especially the part where throwaway.vmc’s VM wrote to donttouchthisbaseimage.vhd). After that you can start up the just created VM and it’ll be a copy of the base image.
One problem remains however: machine name. This didn’t seem like much of an issue, but having multiple instances running will mess with file sharing, besides producing annoying error messages. Fortunately, there’s a solution to this, one that’s probably known to system administrators but not to a developer like me. What you need is deploy.cab in /support/tools on the Windows XP or Windows 2003 installation disk. Install the files from this archive on the base image and first run setupmgr.exe. This tool will help you create a sysprep.inf file. First you choose to do a fully automated install, next select the options you want to automatically configure on a copied image, like generating a machine name. When you’re done the tool will have automatically created a sysprep-directory with the sysprep.inf file in it (it will ask you to save the sysprep.inf file but regardless of where you save it, it will also place it in the correct directory).
Next you can run the sysprep.exe tool. Here you choose to do a mini-setup and click “Reseal”. This will freeze the VM shortly and then shut down. Now you can create a copy of the virtual machine. When you boot into that copy for the first time, you’ll see an automated configuration taking place and a reboot, after which the virtual machine is done: fully customized with a unique machine name! This is especially useful if you plan to do automated resets of a virtual machine using a script or a custom application: just copy the .vmc/.vhd files and change the path in the .vmc file. After that you’re set to start over again from scratch. This might seem like a far-fetched solution, but being able to select what to automatically set during configuration and what to ask the user is very useful: for instance setting the localization during setup can be used to test localized versions of your application without having to maintain a bunch of localized base images.
A note on licensing though: I’ve called Microsoft to ask about licensing in such a scenario and they’ve told me that my MSDN Universal subscription is enough for doing it like this when I’m the only user of the virtual machines. I’m not a lawyer so I can’t say anything about what you’re allowed to do in other situations/with other licensing schemes.