Compact a VHD file created by Disk Management?
Solution 1:
Compacting can't be completed on a VHD that is attached unless it is read-only.
To detach the disk, you need to right-click the VHD disk in Disk Management and select Detach VHD:
You can then complete the compacting using diskpart
from a Command Prompt:
- Run
diskpart
- Select the disk via its path:
select vdisk file="<path>"
- Attach it as read-only:
attach vdisk readonly
- Compact it:
compact vdisk
- Upon completion of the compact, detach it again:
detach vdisk
You can then re-attach it via Disk Management in its normal and newly compacted state.
(Reference: http://linhost.info/2011/01/windows-how-to-compact-a-dynamic-vhd/)