CompactVHD Overview
When using a thin provisioned virtual hard disk (VHDX), the size of the virtual disk is allowed to expand as needed. Initially, the underlying VHDX file on physical storage starts out small and grows as data is added to the disk. However, while thin provisioned VHDXs automatically expand, they do not automatically shrink when data is deleted. With use over time, the used space of the VHDX on physical storage might not match the size of the corresponding VHDX file. For example, the used space inside the disk on storage might only be 1 GB while the VHDX file size is 10 GB. This discrepancy is caused by deleted data not being purged. When you delete data on an NTFS file system, the data is never really removed from the disk. NTFS will continue to write deleted data until the VHDX file is expanded to its full size.
To help mitigate this problem, directories that are no longer needed can be moved outside the VHDX. But over time, it is impossible to fully mitigate. A process that can shrink the VHDX file to as close as possible to the original state size is needed. This process also has to be scalable as there might be thousands of VHDXs in the environment that need to be compacted. The ultimate benefit of this process is the potential savings in storage where hundreds of gigabytes or even terabytes of space could be reclaimed.
To address these challenges, Liquidware has created a compacting tool called CompactVHD that can be scheduled to run and compact your disks on a regular basis. The process has been tuned to recover the most amount of space possible as compared to alternative results you might get from using PowerShell scripts. CompactVHD can either compact a single file or all VHDX files in a given directory.
