# 清理 WSL2 在 Windows 所佔空間 WSL2 在 Windows 中會建立虛擬硬碟 (Virtual Hard Disk, VHD),以 `ext4.vhdx` 檔案形式表示,一開始 WSL2 會先配置空間,而這些空間並非都是目前真正有使用到的。 - 以系統管理員進入 powershell - `wsl --shutdown` - `diskpart` Windows [Diskpart 指令](https://learn.microsoft.com/zh-tw/windows-server/administration/windows-commands/diskpart) - `select vdisk file="C:\Users\…\ext4.vhdx"` ext4.vhdx 路徑類似 "C:\\Users\\\<your-username>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\ext4.vhdx" ,可以用 `list vdisk` 查到路徑 - `attach vdisk readonly` - `compact vdisk` - `detach vdisk` - `exit` 結束後開啟 WSL2,如果結束遇到 *處理結束,代碼為 4294967295 (0xffffffff)* ,可以試試[關閉並重啟 Windows 功能 "Windows Subsystem For Linux"](https://blog.csdn.net/qq_38666896/article/details/113810463) > 參考連結 > [https://loesspie.com/2021/01/27/wsl2-compact-disk-win10/](https://loesspie.com/2021/01/27/wsl2-compact-disk-win10/) > [https://github.com/microsoft/WSL/issues/4699](https://github.com/microsoft/WSL/issues/4699)
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.