0

I am using WSL2 on my Windows 10 Home. I noticed Windows is reporting that vhdx ext4 partition is 105GB on my disk. But I also have wsl2 added as network drive - and there it is reported just as 89 GB. I already tried running diskpart and compact vhdx space there, it freed a bunch of GBs but I am wondering if I can do something more? Where this size difference is coming from?

2
  • 1
    Does it compact anything more after running fstrim -av within the VM? Commented Mar 16, 2023 at 12:01
  • Thank,s that helped, add it as comment so I can mark it as answer :)
    – Juri
    Commented Mar 17, 2023 at 12:06

1 Answer 1

1

The "Compact" operation can only remove unused areas at disk level (i.e. where the VHDX knows that the specific sectors of the virtual disk are unused). For this to work, the guest OS must inform the (virtual) disk about which sectors are in fact unused by the filesystem, as the disk itself doesn't understand the filesystem that it holds – otherwise if you delete several GB worth of files inside the VM, that space will still be seen as "occupied" from the outside.

The "discard" mechanism used by Hyper-V VHDs is exactly the same TRIM/UNMAP command as with SSDs – for Linux, the guest needs to run fstrim periodically (e.g. using fstrim.timer) or the filesystem needs to have the discard mount option specified.

# sudo fstrim -av
/: 19.9 GiB (21382381568 bytes) trimmed on /dev/sda1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .