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

Kocsis, Szilard Gyorgy 5 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 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,617 questions
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,409 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Ian Xue 37,106 Reputation points Microsoft Vendor
    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.