THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

The Rambling DBA: Jonathan Kehayias

The random ramblings and rantings of frazzled SQL Server DBA

Simplified Virtual PC Creation with Differencing Disks

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:

  1. Create a new Virtual Machine and install the OS and whatever I wanted to test onto it.
  2. Copy an existing Virtual Hard Disk that had the OS installed and then install whatever I wanted to test onto it.
  3. 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:

image

Then select the Windows Server 2008 Base disk as the parent virtual hard disk:

image

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.

image

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.

Published Monday, August 31, 2009 6:07 AM by Jonathan Kehayias

Comments

 

John Paul Cook said:

For test environments where the entire vhd is copied instead of using differencing disks AND the virtual machine is not domain joined, using sysprep isn't necessary. People who don't know what a SID is get along just fine without changing the SID if they don't join a domain. Changing the machine name is still needed to avoid the duplicate name on network problem.

For the copy the entire vhd approach (what you call option 2), NewSID is a good alternative to sysprep. It's somewhat more convenient.

Your sysprep with differencing disks approach can be enhanced further by using a sysprep.inf file to minimize or eliminate the setup questions.

As a reminder to readers, Windows Server 2008 is the last Microsoft server OS with a 32-bit version. All version of Virtual PC only support 32-bit operating systems. If you need to test with Windows Server 2008 R2, you'll have to move up to Hyper-V. The approach you described will also work in a Hyper-V environment.

August 31, 2009 9:52 AM
 

Jonathan Miller said:

I use the free VMware server all the time for this stuff.  I don't understand why anyone uses virtual pc.  I like Microsoft and I realize Virtual pc is free.  The problem I run into is that installing an OS on virtual pc takes like 2x-5x longer than on the free vmware server (I'm talking about the free one that runs on top of windows).  Starting up, shutting down and just plain running is really slow on virtual pc.  So why is it that most ms developers use virtual pc?  

September 2, 2009 10:37 AM
 

TheGoth said:

You get better VPC performance if you have the master VHD in the same folder as the child VPC

May 3, 2010 2:56 PM
Anonymous comments are disabled

This Blog

Syndication

Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement