Resize Microsoft VHD and Partition

Steps to resize a Virtual PC Hard Disk and Partition using VHD Resizer

Because of a little downtime I'm reworking my development environment. For years I've been using Microsoft Virtual PC (VPC) and a differenced disk setup based on Andrew Connell's post. The setup is great for spinning up a new development environment for new clients or for just an isolated development / testing environment.

I primarily use Windows 2003 R2 as my development OS. The cool thing about this setup is I haven't had to install the OS for over 3 years! The problem I've had though is that when I set this up I set the dynamic disk size for the Base VHD to 16GB. This only becomes a problem when I use up the 16 gigs and start to run out of disk space. There are several tricks you use to deal with this, the simplest is to create a separate VHD to install applications on, this way the differenced disk isn't used and space isn't eaten up on your VPC's C: drive.

So getting to the point... In reworking my development environment I want to do a couple of things:

  1. Install latest OS patches
  2. Increase base VHD size

The first one is simple. The second one might seem a little tricky but luckily it's not.

I searched around and found the VHD Resizer utility from (note: the website is no longer running but you can download the VHD Resizer Setup here. The tool allows you to select a VHD and increase the physical size of the disk. I gave it a go and it worked like a charm. Only one thing I didn't think about, it did increase the size of the VHD but not the partition on the VHD. So basically this just gave me unallocated space on the disk. Not what I wanted but I can work with this. Time to put on my old sys admin hat. Now I just needed to extend the primary partition to fill up the unallocated space.

Simplest way to do this is to use the built in Windows utility diskpart.exe. Only thing is you can't use it on a disk that is running. No problem, just mount the VHD as a disk in another Virtual Machine and you're good to go. Also just ask a tip this is a good way to defrag before precompacting the disk (use the -SetDisks option for precompact.exe to specify which disk to precompact).

After going through the steps I'm ready to start my chain of VHDs and now my base image is up to date, 50GB, and only 200MB larger than the original 16GB VHD on the disk. :)