2

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.

name.disp
  • 123
  • 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. – ChanganAuto Jan 29 '24 at 16:51
  • 1
    This older method should work : "Exporting the WSL distro and re-importing it into a new WSL instance". – harrymc Jan 29 '24 at 21:00

1 Answers1

1

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