Uninstalling Ubuntu from WSL2 does not automatically delete the underlying virtual hard disk file, leaving your Windows partition filled with gigabytes of unused data. To fully recover this space, you must manually locate and delete the ext4.vhdx file associated with the distribution. This process requires stopping the WSL service, identifying the correct file path, and removing it via File Explorer or PowerShell.
Why Disk Space Is Not Automatically Freed
When you remove an application like Ubuntu from the Microsoft Store or through the Windows Settings app, Windows only removes the shortcut and the registration metadata for that specific distribution. It does not touch the actual storage backend where the Linux filesystem resides. WSL2 uses a dynamically expanding virtual hard disk (VHDX) to store all Linux files, packages, and configurations. Even after the distribution is uninstalled, this VHDX file remains on your NTFS volume to prevent accidental data loss during potential reinstallation attempts. Consequently, your available disk space on Windows does not increase until this file is explicitly deleted.Step 1: Stop All WSL Instances
Before deleting the disk file, you must ensure that no background processes are holding locks on it. The primary consumer of resources in WSL2 is thevmmem process, which represents the Linux VM. Simply closing terminal windows is often insufficient because the WSL daemon continues running in the background.
Open PowerShell or Command Prompt as Administrator and execute the following command to shut down all active distributions:
wsl --shutdown
If you notice that vmmem is still consuming significant RAM or CPU in Task Manager after running this command, you may need to force-kill the process. Open Task Manager, find vmmem, right-click it, and select End Task. This ensures the virtual machine is completely powered off and releases any file handles attached to the VHDX.
Ubuntu WSL Install Location: Where to Find It? provides additional context on how WSL manages its internal storage paths if you need further clarification on the architecture.
Step 2: Locate the VHDX File
The virtual disk file is typically stored in your user profile directory. The default location for WSL2 distributions is:%LOCALAPPDATA%\Packages\CanonicalGroupLimited.Ubuntu...\LocalState\ext4.vhdx
However, exact folder names can vary depending on the specific version of Ubuntu you installed (e.g., Ubuntu 22.04 vs Ubuntu 24.04). To find the precise path:
1. Open File Explorer and navigate to C:\Users\\AppData\Local\Packages .
2. Look for a folder starting with CanonicalGroupLimited.
3. Inside that folder, look for subfolders named after the distribution, such as 57968XGFBPBLK_... for Ubuntu.
4. Enter the LocalState folder within that distribution-specific folder.
5. You should see a file named ext4.vhdx. This is the file consuming your disk space.
Note that the AppData folder is hidden by default. You can reveal it by clicking View > Show > Hidden items in File Explorer, or by typing %LOCALAPPDATA% directly into the address bar.
Step 3: Delete the Virtual Disk File
Once you have located theext4.vhdx file, you can delete it to reclaim the space. Since you have already run wsl --shutdown, the file should not be in use.
Right-click the ext4.vhdx file and select Delete. Move it to the Recycle Bin first to verify that your system is stable. If you do not encounter any errors, you can then empty the Recycle Bin. Alternatively, you can use PowerShell to delete it permanently:
Remove-Item "C:\Users\\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu...\LocalState\ext4.vhdx"
Replace the path with the actual path you identified in the previous step. After deletion, check your disk properties to confirm that the free space has been restored.
Preventing Future Accumulation
If you frequently experiment with different Linux distributions, consider using thewsl --unregister <DistroName> command before uninstalling via the Store. This command specifically targets the distribution's data and removes the associated VHDX file automatically. For example:
wsl --unregister Ubuntu
This approach is cleaner than manual deletion and reduces the risk of leaving orphaned files behind. It effectively wipes the state of the distribution, making it ready for a fresh install without carrying over old configurations or cached data.
Common Issues and Troubleshooting
Sometimes, users report that the space is not freed even after deletion. This can happen if the file was locked due to a lingering WSL process. Ensure thatwsl --shutdown was successful and that no vmmem processes remain. Additionally, verify that you are deleting the correct file; some users confuse the rootfs.vhdx with other configuration files. Only ext4.vhdx contains the bulk of the data.
Connecting to Ubuntu using ssh over Ethernet might be relevant if you plan to reinstall Ubuntu later and wish to access it remotely immediately after setup.
Frequently Asked Questions
Does deleting the VHDX file delete my Windows files?
No, theext4.vhdx file is isolated within the WSL package directory and contains only Linux data. Deleting it will not affect your Windows operating system, personal documents, or other applications installed on your PC.
Can I shrink the VHDX file instead of deleting it?
Yes, if you want to keep the distribution but reduce its size, you can use theOptimize-VHD PowerShell cmdlet. However, this only shrinks the file if the guest OS has marked blocks as free. Manual deletion is more effective for complete recovery.
Why is vmmem still running after wsl shutdown?
Sometimes the WSL service hangs or fails to terminate cleanly. In such cases, restarting theHyper-V Virtual Machine Management service via Services.msc or forcing a reboot of Windows will clear the stuck process and release the file lock.
Will reinstalling Ubuntu restore the deleted VHDX?
Reinstalling Ubuntu will create a new, freshext4.vhdx file. It will not restore the data from the previously deleted file. Your Linux environment will start from scratch with default settings and no previous packages or configurations.
How do I find the exact path if Canonical folders are missing?
If you used a custom installation method or a different provider, the path may differ. Use thewsl --list --verbose command to see registered distributions, and then check the registry under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss for the specific installation path associated with each GUID.