Tuesday, May 22, 2007

No more room in my VHD

UPDATE #2:
Hold the phone. A reader just tried the procedure described in the UPDATE section below and found out that when you finally go to convert from the fixed back to a dynamically expanding disk, you never get prompted for a new disk size. If this is true, this handy workaround is pretty much worthless. Has anyone else attempted this that could confirm? Yes, I'm too lazy to do it myself.

UPDATE:
The information in the original post is pretty much obsolete, or perhaps more accurately put, incompetent. Thanks to a recent anonymous comment, all I had to do was convert the VHD to a fixed disk and then back to dynamically expanding. Read on if you'd like to learn how to do it the hard way.
:)

So, you may or may not know that I'm a huge fan and user of Virtual PC and Virtual Server. For over two years, I've been using virtualization exclusively for software development. Sure, there's a slight performance hit, but you can't beet the flexibility you gain from having one (or more) isolated development environments. Before using Virtual PC, it was common for me to be wiping my laptop once every 4 to 6 months. Now, since I don't run any development tool software on my host OS, it's rare that I have to rebuild my host machine. And, of course, creating new virtual PC's is a snap.

Virtual PC, Virtual Server, and VMWare all use the concept of virtual hard drives (or VHD's). These are nothing more than files on your physical host OS's drive that represent a virtual drive. They can be fixed in size (like a physical drive) or dynamically expand. The later option is handy in that such a VHD only takes up as much physical space as it needs, gradually growing over time. The benefit is it saves a lot on physical drive space, especially if you manage multiple virtual machines.

When you create a virtually expanding VHD you have to specify its maximum size; for Virtual PC the default max size is 16MB. The kicker is when you're using that VHD and all of the sudden one day you run out of room. It's the same experience you have when you run out of room with a physical drive - you immediately try to free up space by deleting unnecessary files and uninstalling unused apps.

However, I recently ran into a scenario where making more room wasn't enough. I was installing Visual Studio 2005 Service Pack 1, which requires a ton of free disk space (over 2GB I think) and I couldn't make it happen. Since you can't change the max size of an existing VHD, I only had two options:

  1. Rebuild my virtual machine with a larger VHD.
  2. Somehow transfer the contents of my existing VHD to a new empty VHD.
The second option was much more appealing since it would require minimal effort. I just needed a tool that could do it. Transferring or cloning a disk is more involved that simply copying files since you need to transfer boot record, partition, as well as other information.

Doing a little digging, I found there are several utilities out there. Norton Ghost is one. The one I chose was Acronis True Image Server (I installed the Server version since my OS was Windows Server 2003). Neither of these are free, so you have to either buy them or use their trial edition. The process I used was the following:

  1. Create a new empty dynamically expanding VHD (with a more desirable max size) and mount it to the virtual machine.
  2. Install Acronis True Image Server on the virtual machine.
  3. Start True Image and run the Clone Disk wizard.
  4. Unmount the old VHD.
  5. Mount the new VHD as drive 0.
I think there are free disk cloning utilities out there, but I'm not sure how trustworthy they are. Disk cloning isn't something you want to mess up.

AN IMPORTANT NOTE:
Before you perform this operation, make sure you have plenty of room on the physical drive that contains the new VHD. Running out of physical drive space as the new VHD is getting filled (and expanded) can cause the clone to fail. Learned that one the hard way :).

7 comments:

Hadi said...

Hi,

I would like to ask some questions about your post "Building a virtualized Team Foundation Server development environment".

May i know your email address ? Please post an email to hadi(dot)ismanto(at)gmail(dot)com

Thanks,

hadi

Anonymous said...

Couldn't you just have converted to a fixed size then back to a dynamically expanding VHD and set a larger size?

Pete said...

Holy crap, you're right! Disregard my post. All I had to do was convert to fixed and then back to dynamic.

Anonymous said...

The workaround to convert to and from a fixed size disk does not work, you do not get an option to change size. I've tried it yesterday in Virtual PC 2007..

Anonymous said...

Maybe this will help: VHD Resizer, available from http://vmtoolkit.com/

OracleOne said...

I tried VHD Resizer, but the VM could not see the new expanded space. Is there anything I should do? Thanks!

OracleOne said...

My bad. Please disregard my previous post. I just found out that the new expanded space is unformated. Just need to go to the computer management (right-click on my computer), and then go to disk management. This a post from the VMToolKit web site:
================================
The extra space will appear as unformatted raw space. Depending on your drive setup you may be able to resize in in Disk Management, otherwise you need to use something like partition magic to resize your original partition to use the new space.