1

I had run a process on wsl that generated large files and significantly ate up the total available disk space in the hard drive that contains the disk image of my distro. I have deleted those files now, however, the available disk space in the hard drive has not decreased and the wsl disk image continues to be of the same size, i.e., the size it occupied after the generation of the large files. What should I do?

1 Answer 1

6

I think this happens because windows allocates some space to the disk image of wsl. Even after clearing deleting the files, the disk space remains occupied as it has been allocated to the disk image. You need to compactify the disk image using what has been suggested here or here. It basically boils down to doing the following in powershell-

wsl --shutdown
optimize-vhd -Path .\ext4.vhdx -Mode full

If you get an error saying that optimize-vhd is not recognised, you should do the following-

wsl --shutdown
diskpart
# open window Diskpart
select vdisk file=".\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit

Make sure you replace ./ext4.vhdx by the full path of the disk image which can be typically found at "%userprofile%\AppData\Local\Packages\CanonicalGroupLimited.<Distro>\LocalState\ext4.vhdx"

You must log in to answer this question.

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