Where Does WSL Store Its Disk Image?
Where each WSL 2 distro's ext4.vhdx lives, how to find yours when the folder name is a GUID, and how to shrink the image again.
Last updated
Every WSL 2 distribution is a single virtual hard disk file, ext4.vhdx, holding the whole Linux filesystem. It grows as you install packages and never shrinks by itself, which is why deleting files inside Linux can leave the Windows file exactly as large as it was.
The awkward part is that the folder holding it is usually a GUID rather than the distro name, so browsing %LOCALAPPDATA%\wsl tells you nothing useful. Get the real path from the registry or a recursive search, then compact the file with WSL shut down. WSL 1 distros have no vhdx at all.
Where Windows Subsystem for Linux stores this, by platform
%LOCALAPPDATA%\wsl\{GUID}\ext4.vhdx
Current WSL (installed with wsl --install) gives each distro its own GUID folder here, and wsl --install Ubuntu --location D:\WSL\Ubuntu puts that folder somewhere else from the start. Older Store installs use %LOCALAPPDATA%\Packages\[PackageFamilyName]\LocalState\ext4.vhdx instead, for example CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc. wsl -l -v lists distros and their state but not the file path; for that, query HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss and read the BasePath value of each key, or search %LOCALAPPDATA% recursively for ext4.vhdx. WSL 1 has no disk image, it keeps a rootfs folder under %LOCALAPPDATA%\Lxss.
Frequently asked questions
how do i find my wsl vhdx file
In PowerShell: Get-ChildItem -Path $env:LOCALAPPDATA -Recurse -Filter ext4.vhdx. That misses images moved with --location or --import, so the exact answer is HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss, where each BasePath points at one distro's folder.
why is my ext4.vhdx so big
The virtual disk only grows. Files you delete inside Linux leave free space inside the vhdx, not on Windows. Run fstrim inside the distro, then wsl --shutdown and compact the file from Windows to give the space back.
how do i shrink a wsl vhdx
Run wsl --shutdown first, then compact from an admin terminal: Optimize-VHD -Path [path] -Mode Full where Hyper-V is available, or diskpart with select vdisk file, attach vdisk readonly, compact vdisk, detach vdisk everywhere else.
Notice an outdated path? Let us know.