I was setting up Team Foundation Server Virtual PC the other night and thought that my initial estimate of only 8GB being required would be enough, but turned out I was wrong. After getting SQL 2005 Standard Edition installed I had a mere 800MB of free space left!
After some Googling around a bit I was able to locate a great tool from the guys over at vmToolkit.com called VHD Resizer. Basically it creates a new empty VHD file and copies sector by sector the data from your original VHD file to the new VHD file.
So now I had two VHD files but now my problem was that they were exact copies of one another and resizing the VHD container was only half of my problem. Now I needed to somehow resize the 8GB partition in my new VHD file to use the full 16GB of space I allocated to it.
I Googled around some more and read about a built in command line utility (Windows XP or newer) called diskpart. This program is a command line version of the Disk Management MMC plugin used in Windows, but it has a few extra features. The feature of diskpart I was most interested in was the “extend” command. I would just boot into the Virtual Machine and run the extend command from within diskpart, but then I read the following:
Diskpart blocks the extension of only the current system or boot partition.
How can I resize my new Virtual Machine partition without booting it? Simple!� I setup my Virtual Machine to boot off my original “small” drive with my new “larger” VHD as a second hard drive (D:). Doing this allowed me to extend the partition using the diskpart utility.
Shut down the Virtual Machine, set your new “larger” VHD as your boot drive and BAM! You have a resized Virtual PC drive
Hopefully this information will help someone else out there who was in the same delima I was
Cheers!
UPDATED 05/15/09: Hey everyone! I’ve found another issue with the solution listed above. The VHD file you’re trying to extend cannot be the same as the VHD you’re booting into to extend it. For example, if I have VPC “A”, and make a copy of the VHD, I cannot attach the copied VHD and boot into VPC “A” and extend the partition, because both “hard drives” will be signed with the same ID and Windows will be confused and not let you extend the partition. We found we had to boot into a completely different VPD to use the above method and that seemed to work fine!
Cheers (again)!


#1 by Cour on February 11th, 2008
hello thankjs for the info, one mor thing that may be usefull, i tried this on a windows 2003 and did not work, it seems windows 2003 has a problem to use the extend, the workarount is to start a XP pc, with the Virtual disk and extend from there.
Greetings.
#2 by eric on February 11th, 2008
I actually used the method in this article on a VPC running Windows 2003 Standard R2, so I’m not sure what troubles you may have had attempting to use diskpart on Windows 2003.
Are you sure you mounted the new VHD file as the D: ??
#3 by Liron on February 23rd, 2008
Hi,
I have encountered also the same problem.
I have run VPC with W2k3 and try to extend the partition using diskpart utility but I have got an error:
“The volume you have selected may not be extended.
Please select another volume and try again.”
do you have any suggestions .. ?
Thanks Liron
#4 by Liron on February 23rd, 2008
Hi,
I try also using XP as my OS of the VPC.
but still without success …
I’ll be glad for help ..
Thanks
#5 by eric on February 25th, 2008
Did you use the above method of creating an expanded VHD file using “VHD Resizer” then mounting the new VHD file as the D: on your existing VPC??
You cannot resize a disk if it’s the active boot drive.
#6 by Thiago on February 27th, 2008
I need to run a bootrec.exe /FixMbr later to recovery windows.
#7 by ken on March 1st, 2008
Thanks for the blog, saved me a lot of time.
I have a VPC running Win2003StdR2. After running VHD Resizer, I attached the new VHD as E: (D: already used) to my existing VPC. Booted up on the old vhd, ran
c:\diskpart
list volume
select volume 2
extend
Shutdown vpc
Changed vpc settings
Removed old vhd
Attached new vhd as C:\
Started vpc and everything is working fine.
#8 by Paul on March 5th, 2008
Thanks for the blog and Ken’s comment as well.
It solved my problem.
Thanks again.
#9 by Mike on April 21st, 2008
I received the same error message Liron mentions above. I got around it by assigning a drive letter to the new drive, then selecting it as the current volume and finally running extend.
#10 by tony on November 21st, 2008
Worked for me. Thank you!
#11 by Richard Berger on December 11th, 2008
Just another vote that Mike’s comment (#9) is key – I kept getting the error:
“The volume you have selected may not be extended.
Please select another volume and try again.”
Even though my drive was not the system drive and I was running a recent version of Windows that had a diskpart hotfix.
Assigning a letter (using Microsoft Disk Manager) was what allowed me to follow the standard instructions for extending the partition (using Microsoft’s DiskPart).
Thanks Mike!!
RB
#12 by NCH on December 18th, 2008
Mike/Richard Berger,
I am getting this same error msg “The volume you have selected may not be extended.
Please select another volume and try again.”
I tried your way of assigning a drive letter, but it doesn’t seem to be working.
While assiging, it is also formatting and making the partition Active, etc. Not really sure if I am doing things correctly.
Can you pl let me know the step-by-step process so that i can extend my vhd.
Thanks in advance.
NCH.
#13 by J5 on December 31st, 2008
To help clarify some of the steps follow these instructions – works great! Thanks to all the people who posted on this blog!
Run VHD Resizer (before you resize make sure you either backup the original .vhd or create a new resized .vhd instead of replacing the original)
On the settings for the old .vhd (Virtual PC Console->Settings) add the newly created .vhd as Hard Disk 2 by browsing to the .vhd
Startup the old .vhd
Start->Run and type in “diskpart”
Type “list volume”
Locate the volume # of the new hard disk 2 (the new .vhd)
Type “select volume X” where X is the volume # of the new .vhd
Type “extend”
Should say successful
Shutdown the .vhd
On the settings for the old .vhd select none for Hard Disk 2 and select the new resized .vhd for Hard Disk 1
Startup the new .vhd
Should be all set
#14 by ming on January 4th, 2009
diskpart also can’t extend partitions with page files, this was the problem I had, as soon as i moved page file to other partitions. I was able to extend it.
#15 by Prad Nathan on February 19th, 2009
You guys are great. I was able to extend XP VHD but had problem with my Win2003 VHD. After reading your notes and changing the drive letter of my new VHD i was able to Extend.
#16 by Paul on May 15th, 2009
Really useful post! Solved my problem!
Thanks a lot!
#17 by james on June 22nd, 2009
Its not working with 2008.. this everything and when i boot with the new ext hdd..it wont boot.. still googling how to get rid of this.. ig anyone have solution pls post it here..
#18 by Shiv on June 29th, 2009
Really useful. Solved my problem too..
I would like to add one small thing. Before going to diskpart, check whether the new drive is showing up in My Computer. Else, right click My Computer > Manage > Disk Management. Right click the unnamed drive > Change drive letter and Path > Name the drive > Add > Set the drive letter. Then, continue with the diskpart activity.