Shrink virtual disk on WSL

0 min read Tweet this post

Since last year I’m using laptop with windows OS and using WSL. Unfortunately my SSD is small and need more space to install warzone lol. After clean up everything in Ubuntu WSL, the disk space not reduced at all. After googling, I found out that I need manually shrink the virtual disk.

Open windows terminal using administrator privilege then follow these command below.

wsl --shutdown
diskpart
# open Diskpart in new window
# replace this part with your target vhdx
select vdisk file="%LOCALAPPDATA%\Docker\wsl\data\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit

If you are using ubuntu, find the *.vhdx files in %localappdata%\Packages\CanonicalGroup... which mean ... can be random string. The processing time depends on the size of virtual disk.

snippets wsl virtual machine