Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I create an expandable Virtual Hard Drive (VHD) with a maximum size of 50Gb, fill it with 48Gb of files, and then reduce that amount to 25Gb, what is the most efficient and sure-fire way of reducing the size of the VHD so that it is only 25Gb or thereabouts.

I'd like to do this without having to copy the contents of the VHD into a fresh one, or having to have twice the amount of space available for any reason.

I am aware that diskpart's VHD COMPACT doesn't recover all the space.

share|improve this question

Not sure if you are using Windows 7 Virtual PC or Windows Server 2008 R2 Hyper-V or Windows Server 2012 Hyper-V, but I will address each scenario to be safe.

  1. If you are using Windows 7, then you will want to mount the precompactor.iso (found in Program Files (x86)\Windows Virtual PC\Integration Components) and run precompact.exe from the mounted ISO. After this completes, you can shutdown the Virtual Machine and edit the VHD to compact the size. This should reduce the size close to the 25 GB of actual used space.

  2. If you are running Windows Server 2008 or 2008 R2 Hyper-V, I would recommend that you grab the precompactor.iso file from your Windows 7 computer and follow the same directions I provided in step 1 for Windows 7.

  3. If you are running Windows Server 2012 Hyper-V, then convert the VHD to VHDX and Windows Server 2012 Hyper-V will automatically shrink the size of the file based on actual usage.

share|improve this answer
Do you have any references to documentation that supports your claim that Hyper-V Server 2012 automatically recovers space in VHDX? I actually see complaints to the contrary when I search MS forums (e.g., Expandable VHDX Disk Remains Expanded...). – merv Aug 25 '14 at 21:05

If you're looking for absolute space efficiency, build a new VHD and copy the files from the old one into the new one, preferably with file compression enabled in the file system within the target VHD. I know that you excluded this as a potential answer. But I mention it because it is the most space efficient option.

You can approximate this level of efficiency by defragmenting the file system within the VHD before compacting. These two operations, taken together, will end up taking a whole lot longer than building a new VHD, as there will be many more I/O operations generated and probably more data copies in total.

share|improve this answer
defrag does not allow a vhd to shrink smaller. if anything it may make it larger. however, a defrag plus a utility like the precompactor May yield better results than just the precompactor, but not very much. – longneck Feb 11 '13 at 21:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.