Cover image for WSL Space Compression

WSL Space Compression

Words 241
Views
Visitors

Timeline

Timeline

2025-12-29

init

This article introduces methods for compressing WSL (Windows Subsystem for Linux) space. It first explains how to locate the virtual disk file path of a WSL distribution, then emphasizes that WSL must be shut down before compression, and then uses the diskpart tool to perform the compression operation, providing specific command steps.

.vhdxDisk path of the file

Replace distribution-name with thewsl -l -vname of the distribution you see

123456
wsl -l -v(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq '<distribution-name>' }).GetValue("BasePath") + "\ext4.vhdx"# Take Arch Linux as an example(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq 'archlinux' }).GetValue("BasePath") + "\ext4.vhdx"

Compress the disk

Shut down WSL before compressing

1
wsl --shutdown

Then type diskpart

1
diskpart

A new command-line window will pop up. Enter the following in order, replacing the value of file with the path obtained in the previous step.

12345678910
# Select the target disk fileselect vdisk file="/path/to/your/.vhdx"# Attach the virtual disk file in read-only modeattach vdisk readonly# Compact the virtual disk filecompact vdisk# Detach the virtual disk filedetach vdisk# Exitexit

References

Loading comments…