If you configured your Hyper-V virtual machines with dynamically expanding virtual disks you will find that the VHDX files backing the virtual disks always grow in size, they never shrink. This article shows how to do it for Ubuntu Linux VMs.
- Faster Trimming & Compacting of Hyper-V Ubuntu VMs
Ubuntu running in a Hyper-V virtual machine has been supporting the trim command since version 14.04. The OS issues trim commands when files are deleted to tell the disk that the blocks occupied by the files can be used elsewhere. The hypervisor cannot know when blocks are ready to be reused unless the VM tells it.
# To tell the hypervisor which blocks can be reused issue the following command:
sudo