yuk7 / ArchWSL

ArchLinux based WSL Distribution. Supports multiple install.
https://git.io/archwsl
MIT License
6.91k stars 201 forks source link

Disk file `ext4.vhdx` takes too much space #372

Closed FoliageOwO closed 2 months ago

FoliageOwO commented 4 months ago

Hi. I'm new to playing with a WSL. I've used the ArchWSL for a while, but I found my disk almost full when installing stuff.

After running gdu -i /mnt in the ArchWSL, it told me the WSL only used 18.4 GiB:

image

But the disk file occupies 50+ GiB:

image

Environment:

Additional context Seemed to have a connection with this issue WSL#8226, for which I did Optimize-Vhd /path/to/the/ext4.vhdx on my PowerShell, and it threw me an error:

Optimize-VHD: Failed to compact the virtual disk.

Failed to open attachment '/path/to/the/ext4.vhdx'. Error: 'The requested operation could not be completed due to a virtual disk system limitation.  Virtual hard disk files must be uncompressed and unencrypted and must not be sparse.'.

I followed the instructions of the reply on the issue WSL#4103, which did nothing.

Is the space the disk file takes normal, or my settings for ArchWSL is wrong?

lucasacoutinho commented 2 months ago

Hi @FoliageOwO, I’m not sure if you still need help, but I recently faced the same issue, so I thought I'd share my solution for anyone else encountering it.

My distro was set to sparse for a while, which caused some complications. I resolved it by running:

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

After doing this, I was able to use optimize-vhd without any issues. Once you're done, you can re-enable sparse mode if you like, but I recommend running this process periodically—especially if you notice an unusually large disk usage.

For reference, I’m using the default Ubuntu distro, but this solution should also work for ArchWSL and others.

FoliageOwO commented 2 months ago

@lucasacoutinho Thanks, this really does work! :)