Compacting Hyper-V VHDX Files of Ubuntu Linux VMs

Note: if your guest OS supports the trim command you can use the faster method described in this article.
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. Eventually this becomes a problem either directly because of increased storage requirements or indirectly because backups take longer. Compacting VHDX files is possible but more complicated than I feel it should be. I have described the process for Windows VMs here. This article shows how to do it for Ubuntu Linux VMs.
Virtualization & Containers




















