安全地壓實不斷增長的WSL VHDX圖像的大小。
(您喜歡這個公用事業嗎?給它A並分享)
Linux(WSL)的Windows子系統使用VHDX圖像文件來存儲Ext4文件系統,但是當刪除文件時,它缺乏縮小圖像的有效方法。該實用程序不需要提高憑證,而是壓實WSL2發行版的VHDX虛擬驅動器,並實現最小尺寸。默認情況下,它將在信息模式下執行,無需對圖像進行操作,為已安裝的所有發行版提供以下信息:
如果未指定發行版,它將依次針對所有已安裝的圖像。它在緊湊的過程中以安全模式運行,以防止在失敗的情況下進行任何不需要的副作用。這是一個典型的用例:緊湊的Ubuntu圖像並確認:
PS> wslcompact -c Ubuntu
WSL compact, v5.0 2023.02.02 (Groundhog edition)
(C) 2023 Oscar Lopez
wslcompact -h for help. For more information visit: https://github.com/okibcn/wslcompact
Distro's name: Ubuntu
Image file: C:UsersOkiWSLUbuntuext4.vhdx
Current size: 12864 MB
Estimated size: 7700 ± 188 MB
The estimated process time using an SSD is about 2 minutes.
NOTE: You can safely cancel at any time by pressing Ctrl-C
Import in progress, this may take a few minutes.
The operation completed successfully.
New Image compacted from 12864 MB to 7728 MB
Do you want to apply changes and use the new image (y/N): y
Image replaced for distro: Ubuntu
在安裝WSLCompact之前,請確保您的WSL安裝是最新的。您可以通過在PowerShell中鍵入wsl --update來做到這一點。 WSLCompact至少需要WSL版本1.0.0。
安裝WSLCompact的方法有兩種,請選擇您的喜歡:
它需要一個特殊的設置來運行遠程腳本。如果您過去設置了它,那麼您不再需要它了。如果您不確定,PowerShell只需類型:
Set-ExecutionPolicy RemoteSigned - Scope CurrentUser要安裝或更新實用程序,請關閉所有PowerShell實例,打開一個新鮮的實例並類型:
iwr - useb https: // raw.githubusercontent.com / okibcn / wslcompact / main / setup | iex要刪除實用程序,請關閉所有PowerShell實例,打開一個新鮮的實例並類型:
Remove-Item " $ ( $ env: PSModulePath .split ( ' ; ' )[ 0 ] ) /WslCompact " - Recurse - Force如果使用SCOP軟件包管理器,則可以直接從其存儲桶中添加WSLCompact實用程序。輸入PowerShell這兩行:
scoop bucket add .oki https: // github.com / okibcn / Bucket
scoop install wslcompact要更新應用程序,只需鍵入:
scoop update wslcompact要刪除該應用程序,只需鍵入:
scoop uninstall wslcompact安裝後,用法很簡單:
wslcompact列出了所有WSL圖像和信息。不會對圖像進行動作。wslcompact Ubuntu選擇特定的發行版。-c緊湊型選項時,WSLCompact將在確認後修改圖像。-d允許數據分區的緊湊。該實用程序可確保最小的尺寸,您最終獲得了連續的文件,以便在基於HD的舊系統中更快地訪問。如果您需要發行版的名稱列表,則可以通過鍵入wsl -l訪問。
Usage: wslcompact [OPTIONS] [DISTROS]
wslcompact compacts the images of WSL distros by removing unsused space.
If no option is provided, it will default to info mode, without modifying any image.
If no distro is provided it will process all the installed images.
NOTE: WSL will be shutdown for compacting the images.
Options:
no opt. Provides name, image file path, current size, and estimated new size information.
-c Compacting mode: process the selected distros compacting the images.
-y replaces selected images without asking for confirmation.
-d Enable the processing of data images. Default is disabled.
-h Prints this help
Examples:
wslcompact
wslcompact -c -d
wslcompact -c -y Ubuntu Kali
如果您的C:驅動器沒有足夠的時間自由空間,則該程序將不會緊湊該發行版。只需在調用函數之前更改臨時文件夾。因此,而不是簡單的wslcompact ,而只是做:
$ env: TEMP = " Z:your tempfolder "
wslcompact新的Temp文件夾只能在該PowerShell終端會話中處於活動狀態,因此系統的其餘部分根本沒有問題,並且不會留下垃圾。
一個典型的操作是:
PS> wslcompact
WSL compact, v5.0 2023.02.02 (Groundhog edition)
(C) 2023 Oscar Lopez
wslcompact -h for help. For more information visit: https://github.com/okibcn/wslcompact
Distro's name: Ubuntu
Image file: C:UsersOkiWSLUbuntuext4.vhdx
Current size: 12864 MB
Estimated size: 7700 ± 188 MB
The estimated process time using an SSD is about 2 minutes.
Distro's name: Kali
Image file: C:UsersOkiWSLKaliext4.vhdx
Current size: 1579 MB
Estimated size: 723 ± 18 MB
The estimated process time using an SSD is about 1 minutes.
Distro's name: Arch
Image file: C:UsersOkiWSLArchext4.vhdx
Current size: 1075 MB
Estimated size: 860 ± 21 MB
The estimated process time using an SSD is about 1 minutes.
用確認的壓實Ubuntu圖像:
PS> wslcompact -c Ubuntu
WSL compact, v5.0 2023.02.02 (Groundhog edition)
(C) 2023 Oscar Lopez
wslcompact -h for help. For more information visit: https://github.com/okibcn/wslcompact
Distro's name: Ubuntu
Image file: C:UsersOkiWSLUbuntuext4.vhdx
Current size: 12864 MB
Estimated size: 7700 ± 188 MB
The estimated process time using an SSD is about 2 minutes.
NOTE: You can safely cancel at any time by pressing Ctrl-C
Import in progress, this may take a few minutes.
The operation completed successfully.
New Image compacted from 12864 MB to 7728 MB
Do you want to apply changes and use the new image (y/N): y
Image replaced for distro: Ubuntu