I have installed Ubuntu 18.04 LTS on a Hyper-V VM, everything was fine until I noticed that the VHDX file takes up unusually enormous amount of disk space. From within the VM, you can see that the system only takes less than 10GB of space
However on the windows host the VHDX file takes up more than 20GB of disk space!
And this is after I have run a disk compaction with the following steps:
- within the VM, run
sudo fstrim /
- shutdown the VM, start a PowerShell console with administrator rights
- mount the VHDX with
Mount-VHD '.\ubuntu 18.04 lts.vhdx' -ReadOnly
- compact the VHDX with
Optimize-VHD '.\ubuntu 18.04 lts.vhdx' -Mode Full
- unmount the VHDX with
Dismount-VHD '.\ubuntu 18.04 lts.vhdx'
It sorta works as the size of the VHDX was reduced from 23GB before to 21GB now, but considering inside the VM it shows only less than 10GB of space is currently being used, this is hardly much compaction in size.
I've also tried running the Disk Compact function from the Hyper-V administration UI but to no effect. So any idea what might be the cause of this enormous VHDX size and how may I properly compact it? Thanks.
fstrim -a -v
and remove all VM checkpoints (snapshots)