In the event you’ve put in WSL, Docker Desktop, or Hyper-V on Home windows, there is a good probability a single file in your drive is taking over 30, 40, and even 50 GB. You will not see it in your ordinary cleanup spots, together with the Downloads folder, the Recycle Bin, and even Storage Sense will not see it. It simply sits there, quietly rising, buried in a folder most individuals by no means open.
The file is a VHDX, the digital disk picture these instruments use to retailer every thing inside your Linux distros, containers, and VMs. The catch is that VHDX recordsdata develop as you utilize them however by no means shrink on their very own, even after you delete what’s inside. Whether or not you spin up a couple of containers, pull some pictures, or delete them per week later, the file stays the dimensions it peaked at. In the event you’ve been operating any of those instruments for some time, it is price checking these folders to liberate some significant quantity of cupboard space.
The place the bloat hides
The precise folders to test in your PC
The primary time I went in search of these recordsdata, I did not know the place to start out. The placement depends upon which device you are operating, however each drops its VHDX file in a predictable spot. For WSL, open File Explorer and paste %LOCALAPPDATApercentPackages within the deal with bar. Search for a folder that begins with CanonicalGroupLimited (for Ubuntu) or your distro’s writer identify. Contained in the LocalState subfolder, you will discover ext4.vhdx. That single file holds your complete Linux filesystem.
Docker Desktop retains its disks at %LOCALAPPDATApercentDockerwsl in a file referred to as docker_desktop.vhdx or diskdocker_data.vhdx, relying in your model. Hyper-V VMs dwell wherever you configured them, however the default isC:UsersPublicDocumentsHyper-VVirtual Onerous Disks.
The file dimension is the place issues get a bit bizarre. I’ve seen WSL present 583 GB in Apps & options whereas df -h inside Ubuntu reported solely 93 GB used. That is a 490 GB hole with nothing to point out for it. Your first guess is likely to be that /mnt/c is being counted, since Home windows mounts your C: drive inside WSL by default, nevertheless it’s not. The VHDX itself simply by no means gave the area again.
To test your personal file, right-click ext4.vhdx or docker_data.vhdx in File Explorer and have a look at the Dimension on disk worth. That is the quantity that issues, and it is often the one which takes folks without warning. If it is bigger than what you even have contained in the distro or container, the remainder of this text is for you.
Why VHDX recordsdata do not shrink on their very own
It is a deliberate design selection, not a bug
Tashreef Shareef / MakeUseOfCredit: Tashreef Shareef / MakeUseOf
This seems like a Microsoft oversight, nevertheless it’s really a deliberate selection. WSL makes use of a dynamically increasing VHDX, so you do not have to pre-allocate an enormous chunk of your drive up entrance. The disk grows as you want it, which is nice till you need that area again.
The explanation it would not shrink robotically can also be attention-grabbing. In case your workload continually hovers round a secure dimension, say a 32 GB challenge that fluctuates by a gigabyte or two, auto-shrinking would imply the disk shrinks and re-grows time and again. That sort of churn is dangerous for efficiency and worse for SSD put on. The identical logic applies to Docker containers that get spun up and torn down all through the day.
So Microsoft selected to let the file develop and keep grown, leaving guide cleanup to the person. It is the proper name for many workloads, nevertheless it does imply it is advisable know this trick exists. In any other case, you will preserve questioning why your C: drive feels full regardless of deleting issues inside WSL or pruning Docker pictures. The Linux facet studies the area as free, the Home windows facet retains holding onto it, and neither device tells you concerning the mismatch.
How one can reclaim the area
The compaction course of and its gotchas
picture credit score – self captured (Tashreef Shareef) – No Attribution Required
The cleanup is a two-step course of, and skipping step one is the place most guides go fallacious. It’s good to zero-fill the free area inside WSL earlier than compacting, as a result of a sparse VHDX can solely be shrunk the place it sees lengthy runs of zeros. In the event you skip this, Optimize-VHD runs cleanly, however the file barely modifications dimension. You observe the steps, see no change, and assume the trick would not work.
Inside your WSL distro, run dd if=/dev/zero of=/zerofile bs=1M; rm /zerofile. This writes zeros till the disk is full, then deletes the file, leaving you with clear, compact area. The command will ultimately fail with a no area left on machine error, which is strictly what you need. In the event you’re operating Docker by way of WSL2, cease Docker Desktop first and again up something essential, since some customers have reported damaged containers after compaction.
Then, in PowerShell, run wsl –shutdown, navigate to the folder containing your VHDX, and run Optimize-VHD -Path .ext4.vhdx -Mode full. This wants the Hyper-V characteristic put in, which suggests Home windows Professional or Enterprise. On the Residence version, you will hit an error. The fallback is diskpart: open it as admin, then run choose vdisk file=”C:pathtoext4.vhdx”, adopted by connect vdisk readonly, compact vdisk, and detach vdisk. It is clunkier however works with out Hyper-V.
Do not make this routine upkeep
The compaction works, and on a bloated WSL set up, you may simply reclaim 100 gigabytes or extra. However it’s price remembering why Microsoft constructed issues this fashion. Operating Optimize-VHD each week fights towards the design and provides pointless write cycles to your SSD for marginal positive aspects.
I run this after I discover my drive getting tight or after a giant cleanup inside WSL, like deleting previous Docker pictures or wiping a couple of challenge folders. The remainder of the time, I go away it alone. In the event you’re operating low on disk area throughout the board, this is without doubt one of the highest-value cleanups you are able to do. Simply do not put it on a schedule.

