I’m running Windows 11 home preview for quite some time. And since then, I’m constantly running out of disk space. I already started to exclude some folders in OneDrive – even if the data only was available online.
I found that I have a lot of docker large images (docker images) that are unused so I removed them:
$ docker system prune --all
But the effect was not noteable. Then I found the post Shrink your WSL2 Virtual Disks and Docker Images and Reclaim Disk Space by Scott Hanselman. The problem: the commandlet optimize-vhd
is not available on Windows Home edition! But I found an older post from Stephen that explains how you do it with diskpart.
So here is the combination of both posts:
- Go to
~\AppData\Local\Docker\wsl\data
and check the file size ofext4.vhdx
. Right click the file and select “Copy as path“. - Shutdown wsl and open diskpart:
$ wsl --shutdown
$ diskpart
3. Diskpart open in a new window. Select the disk and compact it:
select vdisk file=<right click to paste complete path to ext4.vhdx>
compact vdisk
That’s it. It reduced my disk size from 70GB to 7.5GB!
I spent a lot of time researching why Optomize-Vhd
is not available. So I thought I document this here for all Windows Home users with WSL2.
Just one correction: compact vdisk , not compact disk.
Thanks. Fixed it.
this is easiest one found and it works. Thanks for sharing
Thanks, Arif.