Expand A Virtual PC VHD File And Extend The Partition
7 February 2008I 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!
13 Responses to “Expand A Virtual PC VHD File And Extend The Partition”
February 11th, 2008 at 9:48 pm
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.
February 11th, 2008 at 10:17 pm
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: ??
February 23rd, 2008 at 10:42 am
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
February 23rd, 2008 at 10:44 am
Hi,
I try also using XP as my OS of the VPC.
but still without success …
I’ll be glad for help ..
Thanks
February 25th, 2008 at 9:10 pm
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.
February 27th, 2008 at 6:55 am
I need to run a bootrec.exe /FixMbr later to recovery windows.
March 1st, 2008 at 11:44 pm
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.
March 5th, 2008 at 8:57 pm
Thanks for the blog and Ken’s comment as well.
It solved my problem.
Thanks again.
April 21st, 2008 at 11:26 am
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.
November 21st, 2008 at 10:56 am
Worked for me. Thank you!
December 11th, 2008 at 10:31 pm
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
December 18th, 2008 at 7:16 pm
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.
December 31st, 2008 at 8:31 am
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