Resizing VHD

A person before me decided to make VHD for Hyper-V and made them with a ridiculous amount of space.  One of them is at 90GB (HD Space).  I want to resize them that one to about 20GB.  So I used VHD Resize.  It resized the HD to 19.53 GB.  Now the problem is the space that it took away is listed as unallocated space, which is still keeping the .vhd file size at 51GB.  Is there anyway for me to remove that unallocated space so I can get the .vhd file size down?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

So If I understand you correctly you used the shrink option from inside the VM to reduce its size and therefore you have the resized the "volume", and not the VHD. Well you have done half of the work, now you need to shut down the VM and use the VHDresizer tool to resize the VHD.

cmb991Author Commented:
No, I used the VHDresizer already.  I didn't do anything from inside the VM.  I just used the VHDresizer to resize the VHD.  All that did was resize the C:\ from 90GB to 20GB and now there is about 40GB of unallocated space in the Disk Management.  The .VHD file didn't change in size, only the VHD C:\ changed.  It pretty much just took 40GB from the C:\ and made it unallocated.  I want to get rid of that unallocated space now so the VHD will shrink to a smaller size.
Well, the proper way is too shrink the volume from inside the VM OS disk management. What this does is that it takes the look at the volume check and see to what extend it can shrink the volume and then gives you the option to shrink it. These leave you with a volume shrunk to the size you selected and leftover space shown as unallocated space. This makes no difference to the size of the VHD as its unaware of operation as such.

You then have you use the vhdresizer to resize the VHD. The VHDresizer will ask for a VHD and use it as a source. Once selected it takes a look at the VHD (like its type and current size). You then have to make a target VHD, and have the mix and maximum values given. The minimum value for your case should be 20 GB. you select this as the size of the new (target) VHD and click resize. It will make a new VHD and copy all the content form the source VHD.

This is a non distructive exercise, as your source VHD is untouched. Just make sure you select the correct size and type when creating the new VHD.

See if that help. Try the VHDresize again on the VHD. you don't have to do the shrink operation as you already have done that.
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

cmb991Author Commented:
The problem now is I have a 20GB Partition and 40GB of unallocated space.  So I can't resize anything in windows from the disk management because there is nothing to resize now.  And I already used VHDResizer to resize it which caused this issue.  So now what should I do?
did you try only the VHDresizer again? what is the min suggested size does it give you for the target VHD?
cmb991Author Commented:
Min is 19GB.  So your saying I should put in 20GB again?
cmb991Author Commented:
Also, the type is Dynamic by default.
what is your current default type? fixed or dynamic.
I am guessing it is fixed. Your target type should also be fixed.
If it show 19 GB the select 19 GB and resize.

What OS are you running in the VHD?
cmb991Author Commented:
Dynamic is the default on VHDResize.  Windows XP is the Target OS.  VHDResize is installed on Server 2008 Standard w/ Hyper-V which is where the .VHD files are stored.
OK.. what you are saying that you have a 51 GB dynamic VHD (total size 60 GB) with a windows XP installation on it. In the disk management inside the XP VM, you see one volume with one partition of 19.53 GB and unallocated space of 40 GB. Is this correct?
Secondly, You want to resize the VHD and make it smaller somewhere in the vicinity of 20 GB. Is this correct?
cmb991Author Commented:
I would suggest to use the vhdresizer again, this time select the target VHD type as fixed and your size to minimum allowable i.e. 19 GB. Try the resizer with these option.
Fixed size VHDs are better interms of performance and you pre-allocate all the space needed by them at once.
cmb991Author Commented:
I just set it to fix and it worked.  Now my other issue is I have another VHD that is 96GB.  I want to shrink that to 30GB.  How can I do this with the Disk Management that you were talking about earlier.  I was always under the impression that Windows XP Disk Management can't shrink volumes.  Also, when I opened VHDresizer, it says Min 96 so I have to shrink it first.
cmb991Author Commented:
Disregard.  I do remember you can shrink and extend volumes.  But when I right click on the C:, there is no shrink volume available.  
This are issue with diskpart and disk management tools in windows XP (infact any windows below Vista), you don't have the option to shrink the volumes. Thats why, I was a little baffled as to how you do got it to shrink using VHDResizer.
There are a couple of thing you can do.
If you have a Windows Vista/2008/Win7/2008 R2 VM available. You can add this VHD as a secondary disk in to the VM and then use there disk management tools to shrink you vhd you added as a secondary disk. Once you have done that you can detach the VHD from the VM and use the resizer as you did before.

If your Host is running Windows 2008 R2, then you can attach the VHD directly to the host and then use disk management to shrink the VM. Once done detach and run resizer. This attach VHD option is also available in Windows 7.
How to attach a VHD
If you don't have a Vista/2008/Win7/2008 R2 VM and you host is Windows 2008 (not R2), you can install VHDmount tool available in Virtual Server 2005 R2 SP1 setup and use it to mount the VHD and then use the disk management tools to shrink the VHD.
Mount a VHD file with VHDMount

Before performing any of the above operation I would advise to backup the VHD in question.
Hope that helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Virtual Server

From novice to tech pro — start learning today.