This entry has been published on 2016-09-03 and may be out of date.
Last Updated on 2016-09-03.
[:en]It happens that VHD files get quite large, even it they are dynamically sized, for various reasons (growing logfiles, user mistakes or other scenarios where large files are deleted afterwards).
The dynamic VHD grows automatically, but does never shrink by itself. The VHD size on the hypervisor stays large by default, but you can manually let it shrink again, even if the guest’s HDD format is not NTFS.
First, make sure that the VHD is of type “dynamic” and the guest OS shows free space. The whole procedure would not make much sense otherwise.
For Linux machines (e.g. with EXT2/3/4 file system), do the following:
- Download SystemRescueCd ISO file
- Boot your VM from this image file
- Execute “zerofree /dev/sda1 -v”. (sda1 should be your VHD by default, -v shows the progress in percent)
- When finished, shut down the system and disconnect the ISO.
- Like with Windows guest VHDs, compress your VHD now via common Hyper-V harddisk compression wizard.
- Your VHD should be shrinked now.
[:]