WSL 2 makes it easy to forget that your Linux filesystem is backed by a virtual disk file on Windows.
That is usually fine until the disk keeps growing and you realize deleting files inside Linux does not automatically shrink the .vhdx on the Windows side.
The Goal
The goal here was to compact the backing disk for a WSL 2 distribution after cleanup.
1. Confirm the Distribution
Start by checking the installed WSL environments:
| |
Example output:
| |
2. Stop the Distribution
Before compacting the disk, terminate the running distro:
| |
3. Compact the Virtual Disk
Open diskpart, select the correct .vhdx, and compact it:
| |
Inside diskpart:
| |
Why This Is Worth Recording
This is the sort of systems task that is easy to half-remember. You know the disk exists somewhere, and you know there is a Windows tool involved, but the exact sequence tends to disappear from memory fast.
That is why I like turning short notes like this into posts. They are not dramatic, but they are useful.