Compact/Shrink an Expandable/Dynamic VHD to fully recover space

7,701

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:
7,701

Related videos on Youtube

nishil bhave
Author by

nishil bhave

Updated on September 18, 2022

Comments

  • nishil bhave
    nishil bhave over 1 year

    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.

  • longneck
    longneck over 11 years
    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.
  • Money Singh
    Money Singh over 9 years
    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...).