Creating Differencing Disks with Microsoft Virtual PC

As I mentioned in my “Creating Virtual Machines with Microsoft Virtual PC 2007” article, Microsoft Virtual PC is one of the top contenders in a growing line of Virtual Machine utilities. I will not go into the age-old fight on who’s best – Microsoft Virtual PC or VMWare’s software. Both are free and both are good, but as far as I am concerned, the latest version, called Microsoft Virtual PC 2007, is my preferred VM tool for my own personal use. You can download Microsoft Virtual PC 2007 for free from the following link:

Download details – Virtual PC 2007

Note that besides Virtual PC, Microsoft also offers a more robust product called Virtual Server 2005 R2. We will deal with that product in a later article. When you work with Virtual Machines you must allocate at least one virtual hard disk per machine. The virtual machine “sees” the virtual hard disk as a real hard disk, and is able to format it and install itself on it. Microsoft Virtual PC also supports two types of virtual hard disk that I want to talk about in this article:

  • Differencing virtual hard disks – Differencing virtual hard disks allow multiple users and multiple virtual machines to use the same parent virtual hard disk at the same time. Virtual PC stores any changes to the virtual hard disk in the differencing virtual hard disk. For example, you can build one instance of a given operating system, configure it as a parent disk, and then create many alterations of the same operating system by simply adding differencing virtual disks that rely on the parent disk. Another example might be to store a parent virtual hard disk somewhere on the network and share it with many users. You can then configure Virtual PC to store any changes that the users make in local differencing virtual hard disks.  
  • Undo disks – Undo disks allow users to delete any changes they make to the virtual hard disk during a session that lasts from the time the virtual machine is started until it is closed. Virtual PC stores these changes in a separate temporary file called VirtualPCUndo_VM-NAME_DATE.vud  
  • At the end of the session when the user stops the VM, he or she can choose to save, commit, or delete the changes. Undo disks are convenient because they allow users to start with the exact same virtual disk every time. For example, you can use undo disks to test a deployment scenario in a safe environment and delete the changes at the end of the session. The next time you start the virtual machine, it will be in a clean state ready for another test.

As you’ve see, differencing virtual hard disks are a good method of sharing the same VM with many users, or share the same virtual hard disk with many VMs. So how do we create one? Creating differencing hard disks is easy. Just follow these steps:

Step #1 – Create and install the base image VM

Without going into great detail here, create a new VM by specifying the name of the VM, the location of the virtual hard disk and the .VMC file, select the type of operating system you’re going to install, and allocate the right amount of memory to the VM. You can read more about creating virtual machines in Microsoft Virtual PC 2007 on my “Creating Virtual Machines with Microsoft Virtual PC 2007” article .

After creating the VM you need to boot it, and install the required operating system on it. The installation process is as smooth as installing the OS on a real computer, and is only a notch slower (based upon your host’s machine hardware specifications.

If the OS requires entry of a CD-Key (or Product Key) – do it. If not (like Windows Vista), you can leave it to a later phase.

Make sure you install all the relevant components. Also, you might want to leave the ISO image for the installation CD available on the network in order to allow for future additions of OS components. In order to keep the virtual disk as small as possible I try not to copy the i386 (or equivalent) installation folder to the VM.

Step #2 – Customize the base image VM

In this step you will want to customize the base image VM as you want it to appear in all subsequent clones of that VM. For instance, install any file, tweak, addition, program, tool or other item that you want to have on ALL the VMs that are based upon this base VM.

If you plan to clone the base VM many times and you plan to have these machines on the same network (for example when creating an Active Directory-based lab of several servers and a few client machines) do NOT activate the base VM!

If all subsequent clones will work independently from one another (for example when creating a lab of one Windows XP Pro SP2 machine that will have several applications installed on it but none will work together at the same time or will not be part of the same AD domain) then you can activate the base VM.

Remember, cloning VMs is like “ghosting” a real machine. You must use SYSPREP in order to create unique SIDs, computer names and other settings for each cloned machine.

Read the Links section for more info on SYSPREP.

Also, note that you should install the VM Additions on the base VM.

Step #3 – Temporarily enable undo disks for the base image VM

Next comes the nice part. After customizing the base image you need to shut down the base VM. Make sure you do NOT perform the following step unless you are 100% sure that the current state of the base VM is EXACTLY like you want it to be cloned. You will NOT be able to easily modify the base VM AFTER you’re created differencing disks of it, so pay close attention.

In the Microsoft Virtual PC console, click on the Settings button for the base image VM. Click on the Enable Undo Disks checkbox and click Ok.

diff disks vm 7 small

At this moment you should have 2 files in the base VM’s folder. A VHD file for the virtual disk, and a VMC file for the VM settings.

diff disks vm 8 small

Step #4 – Boot the base image VM once and quickly shutdown without committing changes

Now you need to boot the base image VM once. Let it boot all the way, log on to the OS if you want to.

If the base image cannot be booted “all the way”, because, for example, you’ve got a SYSPREP unattended script waiting for the cloned machines to be booted and you’d like to keep it that way, do NOT boot it “all the way”, and instead just let the VM boot for a few seconds. When either the logon page has appeared, or you think enough time has passed (and a few seconds is all you need), close the base VM by closing the Virtual PC window for the VM.

diff disks vm 9 small

Make sure you select Turn Off and Save Changes from the drop-down list, and UNSELECT the Commit Changes to the Hard Disk checkbox. Now press Ok.

diff disks vm 10 small

If you look at the base VM’s folder you will see 3 files. A VHD file for the virtual disk, a VMC file for the VM settings, and a VUD file for the undo disk. The VUD file is probably very small, but fear not, it will not remain so for long.

diff disks vm 11 small

Step #5 – Rename the undo disk

Now we need to rename the VUD undo disk to whatever the new cloned hard disk will be called, and change the file type to VHD. Click on the VUD file and either right-click and select Rename or press F2.

diff disks vm 12 small     diff disks vm 13 small

Now you have a (small) new VHD that is linked to the base virtual hard disk of the base VM.

You can also copy the original VMC file, or, if you want to, you can create a new one in step #7.

Step #6 – Disable undo disks for the base image VM

Now we need to disable the Undo Disk feature for the base VM. In the Microsoft Virtual PC console, click on the Settings button for the base image VM. Click to UNSELECT the Enable Undo Disks checkbox and click Ok.

Note: You must never re-boot the base VM. If you do so, you might ruin all the differencing disks that are related to it.

Step #7 – Delete the base VM from the Virtual PC console

Since you are not allowed to ever reboot the base VM you can simply delete it from the list of VMs in the Virtual PC console.

Step #8 – Configure the base VM hard disk to be read only

Open Windows Explorer, right-click on the original VHD file, and select Read Only. Press Ok.

diff disks vm 15 small     diff disks vm 16 small

Step #9 – Create a new VM by using the renamed undo disk of the base image VM

Now we can create as many new VMs from the cloned VUD file that we renamed in step #5. You can copy that file as many times as you want, and for each time you copy it you can create a VM out of it. Follow the steps outlined in my “Creating Virtual Machines with Microsoft Virtual PC 2007” article.

diff disks vm 14 small

Note: Remember the SYSPREP issues mentioned in step #2. Any cloned machine that you want to place on the same network as other cloned machines must be SYSPREPed. Note: The cloned VM hard disks can have Undo Disks enabled on them, if you so please. Note: Remember, you will (probably) need to activate each cloned machine, unless you’re using an OS that does not require activation or has a VLK license. Finally, when you boot your cloned machines they work normally, and when you close them they save their changes to the differencing virtual hard disk that uses the now-unchanged base VM hard disk.

diff disks vm 22 small      diff disks vm 23 small


How to use the Sysprep tool to automate successful deployment of Windows XP – 302577 How To Use the System Preparation Tool (Sysprep.exe) to Perform Disk Duplication – 298491 Download details: Windows XP SP2 Deployment Tools for Advanced Users

Related Articles

Recent Virtual Server & PC Forum threads

Got a question? Post it on our Virtual Server & Virtual PC Forum!