Differencing Disks in Virtual PC 2007

Yesterday I mentioned I was going to get SQL Server 2008 installed in a Virtual PC (VPC). Now, I could have setup a virtual machine from scratch, or copied an existing one. But there’s a better way: differencing disks. Differencing disks allow you to create a virtual machine, then use it as a base for new machines. Much like you would create a base class and then let new classes inherit from your base.

My first step was to create a brand new virtual PC. I chose Windows Server 2003, using the one from my MSDN license. I could also have gone with XP, or the advanced versions of Vista licenses you to install up to four virtual machines in addition to itself as the host. So I get my VPC setup with Windows Server 2003, and make sure all of the windows updates have been applied, service packs, etc. In addition, if there are any additional tools / utilities I’d like to have available for every machine I’ll be wanting create from it I’ll install those as well. I’m thinking of things like UltraEdit / Notepad++, IE7, AllSnap, etc. I finally conclude by shutting down the machine.

Exit Virtual PC, and go to the folder where your virtual PC’s reside. First delete the VMC file (the small one) of your Virtual PC. You won’t need it any more, as you’ll never open this VPC directly. If you did, you would break all the machines that inherit from it. Again, not unlike changing the signature of a base class.

Next, mark the VHD, the hard drive as Read Only. Again this is for your protection, to keep you from doing something accidental to the base. At this point we have our base machine created, and can now make new machines from it.

Launch Virtual PC again. Click on File, Virtual Disk Wizard. You are given a simple dialog that lets you know you’re in the Virtual Disk Wizard. Click Next to move along.

[Picture 1 - Welcome to Virtual Disk Wizard]

Next it asks if we want to create a new disk or edit an existing one. We’ll want to create a new one, so just click Next.

[Picture 2 - Create a new virtual disk]

Now it wants to know what kind of disk to create. We’re doing a hard disk, so just take the default of virtual hard disk and click next.

[Picture 3 - Disk Type]

Now it asks where you want to put your virtual hard disk. I keep mine on my D drive, and use a naming convention. I start with the OS, then the main software I am using. I then use either the word Working, to indicate it’s alright to launch and work in it, or Base, to show the vhd should only be used to inherit from and not be launched. In this case I will be using this as a working area for my SQL Server 2008 CTP6, so I used Working. You are free of course to name it whatever you want, use a name like “Hanselman is cool.vhd” if you like I just prefer something a bit more logical.

[Picture 4 - Disk Location]

OK, this is where you need to pay attention, as this is the first time you’ll need to change a default. Here you are asked what type of virtual hard drive to create. The default is dynamically expanding, and it’s what you’d want to use if you are installing an OS from scratch or are creating a second hard drive for your virtual machine. Fixed size would be used if you are creating a disk for something like a USB drive and want to make sure it won’t get too big. Again, this would be used when you need an empty drive.

In our case we want the third option, Differencing. What this does is tell the Virtual PC application to base the new hard drive on an existing one. From here on out, only the changes you make to the virtual drive will be recorded. This has a lot of benefits. First it saves you disk space, in that you can use the same base with multiple virtual machines. Second, it lets you install the base OS only once, and not have to keep recreating it over and over. Finally, you can create multiple generations of disks. For example, I could create a base of Windows 2003, then another base with Visual Studio added. I could then use that base to inherit from, and create two drives. One could be used with SQL Server 2008, the other with SQL Server 2005. In our case we’re keeping it simple, so pick Differencing and click next.

[Picture 5 - Hard Disk Options]

Next we need to pick the virtual hard drive we want to base our new machine on. In this case I am selecting my Windows Server 2003 core base, and clicking next.

[Picture 6 - Pick Base Hard Drive]

Next we are told it has all the info it needs. All we have to do is click Finish and we’ll have our new Virtual Hard Disk.

[Picture 7 - Complete Disk Creation]

Virtual PC thoughtfully tells us it was successful.

[Picture 8 - Confirmation Message]

OK, we have a new disk, but now we need to tell Virtual PC we want to use it. Back on the Virtual PC Console, Select File, New Virtual Machine Wizard OR click the New… button on the console. Virtual PC has a need to tell us what we just picked, so just click Next.

[Picture 9 - Create Machine Wizard]

This time we are creating a new virtual machine, which will be based on the virtual hard drive we just created, so take the default and click next.

[Picture 10 - Create a machine]

Next we need to give our machine a name. I usually give it the same name as the hard drive, except for the vmc extension. Name yours and click next.

[Picture 11 - Macine name and location]

Now it asks what OS we’ll be using. Note it has automatically detected that I’m using Windows Server 2003, so all I have to do is click next.

[Picture 12 - Confirm Operating System]

Now it asks what my default RAM size will be. I figure 256 MB is a bit small, since I have the ram I upped it to 768 MB. Set yours according to the free space you can spare and click next.

[Picture 13 - Select default amount of memory]

Now we’re asked if we want to use an existing disk or create a new one. Obviously we want to use the differencing one we just created, so click next.

[Picture 14 - Existing Disk or New Disk - We want existing]

Next it asks where our existing drive is, pick it out using the Browse… button or type it in.

[Picture 15 - Pick name of existing disk]

Let me call your attention to the Check Box, “Enable undo disks”. If you leave this unchecked, your virtual machine will behave like a normal computer. Any changes you make are applied and saved. If you check the undo option on, then during your session any changes are written to a temporary file. When you exit the VPC, you are asked if you want to save any changes you made. If you say yes, they will be permanently applied to the virtual machine. If you say no, they are discarded, lost forever. Undo disks are ideal for test situations where you want to run the same changes over and over but not save them. Testing software installs, for example, or in a classroom where you want the students to do labs but not save them.

While Undo Disks can be very helpful, in this situation I don’t really need them as I want to keep all my changes so I will leave this unchecked and click next.

[Picture 16 - Complete Machine Wizard]

OK, we’re at the finish line. All we have to do is click Finish to complete the creation of our new virtual machine.

Let me call your attention to the file sizes of our new machine. Take a look at them in explorer…

[Picture 17 - Explorer snapsho showing small size of vhd]

Note how tiny the vhd file is right now. That’s because it’s based on another drive, where all the OS bits are. As we open it and apply changes (such as installing SQL Server 2008) it will grow in size, but we’ll always be able to save the disk space of the OS as it’s coming from another file.

The down side to differencing disks is speed, because they are in multiple files the performance won’t be as great. Additionally you can’t update the base machine without breaking its descendants. However, differencing disks offer several advantages as well. They save you time, in that you can create a base OS once and use it over and over. As you can see above they can also save you disk space, in that the core OS only takes up space once on your drive and not over and over.

Consider Differencing Disks, and whether they might be appropriate to your development environment.

Advertisement

11 thoughts on “Differencing Disks in Virtual PC 2007

  1. Hey Robert. Nice Post. I knew you could do this, but I never have sat down to figure out all of the steps. Thanks for saving me the trouble. I’ll be setting up some of these in a few weeks when my new laptop arrives.

  2. Good post!

    Two questions for you, 1. on each of the Differencing Disk, is there a need to require a Windows license key? Since the OS bits are not on the differencing disks, so may be not … ? 2. Can the Base Disk be patched? Say we need to apply a Service Pack or whatever on it after Differencing Disks been created? If we can patch the Base and it automatically applies to all Differencing Disks afterwards, then no need to patch each of every DD’s.

    Thanks.

  3. Hi William,

    As far as I can tell, and let me stress I AM NOT A LAWYER so this is not legal advice, just what I can figure out, the only need for a license key is for the base machine you inherit from. From there on out no matter how many differencing machines you create technically you are running the original OS.

    On question 2, No, from what I have read the base cannot be patched which is one of the drawbacks. If you patch it (or change it in any way) you break all the machines it descends to. It’s one of the few drawbacks to the way it works, any service packs, hotfixes, or patches have to be applied to the children.

    Arcane

  4. Pingback: vmc vhd
  5. I have a small issue with the Undo Disks option on my virtual machines. I have the option selected for all my different machines. But for some reason, only one of the machines (Windows Server 2008) asks to save changes. All the rest just close and never ask me if I wish to save any of the changes. Any suggestions?

  6. First off, let me apologize for the lame answer but I’ve been at TechEd for the last fourteen hours so I’m a little fried.

    I seem to recall there is an issue with Undo Disks and differencing disks, but can’t recall exactly what it is. I’ll try and ask around tomorrow and see what I can come up with.

  7. Do you know if there is a performance hit with differencing disks having more .vhd files to deal with?
    I.e. will it get much slower the more levels of differencing you have?

    I’m creating virtual machines mostly so they can be moved around when we get new PCs.
    They don’t get created and thrown away that often.

  8. “The down side to differencing disks is speed, because they are in multiple files the performance won’t be as great.”

    While I haven’t tried this yet, I would imagine that if you have multiple hard drives, you could put the base on one and the differencing on another, and might possibly obtain a performance improvement over having a single image on one hard drive. Even if not that performant, it should still be a big improvement over having the base and differencing on the same platter.

    To James: yes, it does get slower the more levels of differencing you have. Similarly, Hyper-V snapshots are slower when there are more levels (not necessarily more snapshots — with 20 snapshots, all from the same base, there’s only one “level” when running any of them (and 2 VHDs to look in); but with 20 snapshots, each taken from the preceding snapshot, then there would be 20 VHDs that the system may need to look in to find a file).

    Cheers,
    Ken

  9. I wonder if it would be advantagious to disable virtual memory on the base before you save and compact it, then enable it again on the child machines, since the base will be taking up 1gig(if that’s how big your page file is) as well as 1 gig on the child(because it is going to generate data in the child as memory is paged to the pagefile essentially wasting an extra gigabyte of space).

    However this means you need to remember everytime you create a new child to enable the page file for that child.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s