If you regularly test software, or do development, then you probably use Virtual PC or one of the other virtualization technologies out there. I like Virtual PC because it is free, easy to use, and gets the job done. I used it for testing SQL Server 2008 from CTP to RTM, and I am using it again to test SQL Server 2008 R2. However, I only recently learned how to simplify rolling out new virtual machines for testing by using what’s known as Differencing Disks.
Differencing disks aren’t complete virtual hard disks by themselves. Instead they are based off of an existing virtual hard disk which I will refer to as the master disk. Previously whenever I needed a test machine I had to do one of three options:
- Create a new Virtual Machine and install the OS and whatever I wanted to test onto it.
- Copy an existing Virtual Hard Disk that had the OS installed and then install whatever I wanted to test onto it.
- Use an existing Virtual Machine with Undo Disks to allow me to undo whatever I was testing.
For the most part I used option #2 because it has always been faster for me to copy an existing VHD and base a Virtual Machine off of it than it was to install the OS and configure everything for use. I use option #3 when I am doing presentations so that I can revert the machine back for use in another presentation later with predictable results. Differencing disks changes how I do this now completely.
To start with I create a basic install of just the OS that I intend to use. Currently I have four virtual hard disks that I consider to be my master OS installations; Windows Server 2008, Windows Server 2003, Windows XP, and Ubuntu. Each of these is a basic installation that have the most recent (as of the date created) service pack and hot fixes applied. To make this easy to follow, I will use my Windows Server 2008 install for the rest of this post.
After installing the OS, applying Service Packs and Hot fixes, I ran sysprep to clear the system settings from the machine allowing it to be used as a OS image that will regenerate the system SID and clear settings allowing each machine based on this image to be setup when it first starts. After SysPrep runs, the machine shuts down. At this point I deleted the VMC file associated with the machine and moved the VHD file into my OS Base Files folder and set it to read only. This VHD can now be used to rapidly create a Windows Server 2008 VPC with just a few clicks. To do this, just create a new virtual hard disk using the Virtual Hard Disk Wizard. When the Virtual Disk Wizard opens select the Differencing Disk Option:
Then select the Windows Server 2008 Base disk as the parent virtual hard disk:
Then finish creating the disk. Now you can create a new VPC using this new existing disk. Setup any remaining VPC settings to your needed configuration and then startup the VPC. When the new VPC starts it is based on the parent disk (Windows Server 2008), but all changes are written to the Differencing Disk, preserving the master VHD for reuse by other VPC’s. This saves significantly on disk space since the OS is only installed once, and then referenced for all other VPC’s. If you choose to use SysPrep, which you should, when the machine starts up, it loads in a setup mode that allows you to configure the machine for use.
Once you configure the machine, it will drop to your desktop and you can then begin to test whatever you need to test. So far, I can’t see much of a performance decrease from having used Differencing Disks, in fact I am using multiple nested Differencing Disks and am very happy with the performance currently.
In my next post I’ll cover how to optimize your VPC’s for best performance.