6

Following the advice on How do I get back unused disk space from Ubuntu on WSL2? I set my WSL disk image to sparse with wsl --manage <distro> --set-sparse true. But the ext4.vhd file is still very large (~70 GB) while running du inside WSL reports only about 10 GB.

Will the disk size be reduced dynamically as I use my C:/ drive or do I have to manually reduce it? If I can, I'd like to force update the now sparse disk so that I know how much free space I actually have left on my drive.

2
  • Assuming you're linking because of the accepted answer, this part of the "older answer" still holds true: shrinking it to reclaim unused space is something that must currently be done manually. Commented Jan 29 at 16:51
  • 1
    This older method should work : "Exporting the WSL distro and re-importing it into a new WSL instance".
    – harrymc
    Commented Jan 29 at 21:00

2 Answers 2

6

You can revert the sparse mode, run the optimize-vhd command, and then set it back to sparse. something along this lines. not sure what's the implication of this, at least it works in my case.

  1. Revert sparse mode

wsl --manage <distro> --set-sparse false

  1. Optimize the disk

optimize-vhd -Path <path-to-your-vhdx>.vhdx -Mode full

  1. Set it back to sparse mode

wsl --manage <distro> --set-sparse true

2
1
  1. Where did you get the data of 70GB? If it’s the file size displayed by Windows, then this data is likely to be unreal;
  2. The real size should be its occupied space, you should check its occupied space in the file properties instead of size (Windows explorer only displays file size on the surface, occupied space will only be displayed in properties);
  3. After setting to sparse using wsl --manage <distro> -s true. Although the file size displayed by Windows explorer does not decrease with the deletion of files, its actual size (occupied space) is indeed decreasing.

You must log in to answer this question.

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