The virtual disk of WSL2 on Windows 11 system did not free up disk space on my D drive after file deletion. What should I do?

楚 梁 0 Reputation points
2024-01-01T06:27:04.33+00:00

I installed the ubantu system on Windows 11 and it generated a virtual disk with the path "D:\WpSystem\S-1-5-21-3500270691-3981020838-3510376652-1001\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx". After deleting a larger file in my Ubuntu system, my disk space has not been released. The file I deleted is shared with the Docker container on my Windows 11 system.

How can I free up disk space?

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-01-02T08:44:04.47+00:00

    Hi chu,

    Hope you're doing well.

    You can try the following steps to free up disk space on your WSL2 virtual disk:

    1. Check the amount of disk space available in the VHD for a Linux distribution installed with WSL 2 by using the Linux Df command. To check available disk space, open a PowerShell command line and enter this command (replacing <distribution-name> with the actual distribution name):

    "PowerShell wsl.exe --system -d <distribution-name> df -h /mnt/wslg/distro".

    The output will include the total size of the disk, the amount of space currently being used, and the amount of space left in the VHD.

    1. If you see that you are near to reaching the available amount of disk space allocated to your VHD, or have already received an error due to no disk space remaining, you can expand the maximum amount of disk space allocated to the VHD associated with your Linux distribution.
    2. If you have deleted a large file in your Ubuntu system and the disk space has not been released, you can try to compact the VHDX file to reclaim disk space. You can use the "diskpart" tool to compact a VHDX file. This allows you to shrink a WSL2 virtual disk file, reclaiming disk space.

    I hope this helps you resolve the issue. Let me know if you have any further questions.

    Here are the relevant documents for your reference:

    How to manage WSL disk space | Microsoft Learn

    How to Shrink a WSL2 Virtual Disk – Stephen Rees-Carter (stephenreescarter.net)

    windows 10 - How do I get back unused disk space from Ubuntu on WSL2? - Super User

    wsl 2 - How to properly resize disk usage in docker desktop WSL2? - Stack Overflow

    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.

    0 comments No comments

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.