WSL2 works like a virtual machine; the guest OS doesn't directly store individual files in your host filesystem – it has a dedicated virtual "disk" that is stored in a single large .vhdx file as seen by Windows.
This file grows dynamically as the guest OS writes data to new "disk" areas, but does not shrink when those areas are no longer used. For example, if the virtual disk had sectors 10000-20000 in use by a large file and you removed it, the space for those sectors (and their data, too) is still consumed by the VHDX file.
So over time, as Ubuntu places new files all over the disk area, the VHDX will continue growing until it eventually reaches the complete "disk size" that was given to the VM.
Automatic compaction of the VHD used by WSL2 was actually added earlier this week.
If this were a dedicated Hyper-V VM, it would need to run periodic fstrim to inform the host OS of which VHD areas may be considered "free" (the same as what you'd use with SSDs); I suspect the new WSL2 feature works the same way, only performing the trim from its "system distro".
wsl --manage Ubuntu-22.04 --set-sparse trueit returnsInvalid command line argument: --manage– TommoM Sep 21 '23 at 05:37wsl --updateto install any updates that maybe had not installed. Apparently everything is up to date, but the above command gives the same output. – TommoM Sep 21 '23 at 06:02wsl --update --pre-release. After doing that I was able to run the above command successfully. – TommoM Sep 21 '23 at 07:38fstrim -avon your WSL2 (after fully restarting it). From the terminology ("sparse" VHDX as opposed to compaction), it sounds like the VHDX file will only reduce its physical size ("Size on Disk" in the Properties dialog) but will still show the same logical size, so while it will indeed free up space, I'm not entirely sure whether the Settings app will correctly report that. – u1686_grawity Sep 21 '23 at 07:49