in WSL2 with sparse vhd the storage usage does not shrink automatically, cannot compact it anymore manually

Kocsis, Szilard Gyorgy 10 Reputation points
2024-02-06T12:52:30.3233333+00:00

I have 22H2 build 19045.3930 windows 10
WSL2 and I converted my vhd to be sparse once the feature was available to let it shrink on its own. However it does not seem to shrink when when I free up space and to make matters worse I cannot compress it manually any more either

optimize-vhd -Path ext4.vhdx -Mode full
gives
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.'.

Questions:
How to trigger sparse vhd to unclaim space as it was promised in the feature?
How to do manual shink with the sparse vhd if the above does not work?

Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-02-07T04:35:26.12+00:00

    Hi Kocsis, Szilard Gyorgy,

    Please make sure that sparseVhd is set to true in the "[experimental]" section in your .wslconfig file. If the VHD is not newly created, you can set your existing distros to be sparse by running

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

    https://devblogs.microsoft.com/commandline/windows-subsystem-for-linux-september-2023-update/

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.