New
#1
How to release unused space in VHDX disks?
Before I learned that VHDX expanding disks do not release space, many of these have swelled way beyond what is used of needed because I did a defrag. Defrag will use temporary space to store files parts being defragged. I expected defrag to make fragmented files use contiguous space and to move all of the files to the beginning of the VHDX disk. To emphasize my ignorance I expected defrag to truncate to unused space at the end of the disk.
What really happens is that defrag extends expanding VHDX disks as a temporary area to make files contiguous and as temporary space to squeeze out embedded free space. The new extensions are never released to the host physical disk. Defragging a VHDX extended space disk will result in allocating significant more unused physical space. As an example a 100gb fragmented expanding VHDX disk once defragged may end up actually expanding to over 300gb of real space.
A old version of Virtual PC came with a compactor.ISO utility that when run against a VHD, would squeeze all unused space to the end of the VHD disk. You could then truncate the trailing free space leaving your VHD file physically smaller. Microsoft provides no tool (I know of) that will accomplish the physical shrinking of VHDX disks. The problem may apply to VHD disks as well, but I am now using VHDX virtual disks.
Does anyone have the necessary expertise of PowerShell to script making VHDX disk files contiguous, squeezing all the unused space to the end of the VHDX disk, and then truncating the trailing free space to physically shrink virtual disks.