To shrink VHD file occupied by virtual Windows OS you need to shrink the volume (i.e. disk C:) inside virtual machine and physical VHD file on host machine. It works fine when you don’t use differential VHDs.
Inside virtual Windows OS run command prompt:
1 2 3 4 5 |
diskpart list volume select volume # shrink desired=size_in_megabytes_to_get_from_OS exit |
Then shut down virtual machine.
On host Windows OS run command prompt:
1 2 3 4 5 6 |
diskpart select vdisk file="path_to_vhd" attach vdisk readonly compact vdisk detach vdisk exit |