Dengan aman memadatkan ukuran gambar WSL VHDX yang terus tumbuh.
(Apakah Anda menyukai utilitas ini? Berikan dan bagikan)
Subsistem Windows untuk Linux (WSL) menggunakan file gambar VHDX untuk menyimpan sistem file ext4, tetapi tidak memiliki cara yang efektif untuk mengecilkan gambar ketika file dihapus. Utilitas ini tidak memerlukan kredensial tinggi, memadatkan drive virtual VHDX dari distro WSL2, dan mencapai ukuran minimum yang mungkin. Secara default itu akan melakukan dalam mode info, tidak ada tindakan pada gambar, memberikan informasi berikut untuk semua distro yang diinstal:
Jika tidak ada distro yang ditentukan, itu akan menargetkan semua gambar yang diinstal secara berurutan. Ini beroperasi dalam mode aman selama proses kompak, mencegah efek samping yang tidak diinginkan jika terjadi kegagalan. Ini adalah kasus penggunaan yang khas: memadatkan gambar ubuntu dengan konfirmasi:
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
Sebelum menginstal WSLCompact, pastikan instalasi WSL Anda mutakhir. Anda dapat melakukannya dengan mengetikkan wsl --update di PowerShell. WSLCompact membutuhkan setidaknya WSL versi 1.0.0.
Ada dua cara untuk menginstal WSLCompact, pilih favorit Anda:
Ini membutuhkan pengaturan khusus untuk menjalankan skrip jarak jauh. Jika Anda telah mengaturnya di masa lalu, maka Anda tidak membutuhkannya lagi. Jika Anda tidak yakin, di PowerShell cukup ketik:
Set-ExecutionPolicy RemoteSigned - Scope CurrentUserUntuk menginstal atau memperbarui utilitas, tutup semua instance PowerShell Anda, buka yang segar dan ketik:
iwr - useb https: // raw.githubusercontent.com / okibcn / wslcompact / main / setup | iexUntuk menghapus utilitas, tutup semua instance PowerShell Anda, buka yang segar dan ketik:
Remove-Item " $ ( $ env: PSModulePath .split ( ' ; ' )[ 0 ] ) /WslCompact " - Recurse - ForceJika Anda menggunakan SCOOP Package Manager , maka Anda dapat menambahkan utilitas WSLCompact langsung dari embernya. Ketik PowerShell Dua baris ini:
scoop bucket add .oki https: // github.com / okibcn / Bucket
scoop install wslcompactUntuk memperbarui aplikasi, cukup ketik:
scoop update wslcompactUntuk menghapus aplikasi cukup ketik:
scoop uninstall wslcompactSetelah instalasi, penggunaannya langsung:
wslcompact tanpa argumen mencantumkan semua gambar dan informasi WSL. Tidak ada tindakan pada gambar yang akan dilakukan.wslcompact Ubuntu .-c Compact, WSLCompact akan memodifikasi gambar setelah konfirmasi.-d memungkinkan kompak partisi data. Utilitas memastikan ukuran minimal dan Anda berakhir dengan file yang berdekatan untuk akses yang lebih cepat dalam sistem berbasis HD lama. Jika Anda memerlukan daftar nama distro Anda, itu dapat diakses dengan mengetik 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
Jika C: Drive Anda tidak memiliki ruang bebas temporal yang cukup, program ini tidak akan memadatkan distro itu. Cukup ubah folder temp sebelum memanggil fungsi. Jadi, alih -alih wslcompact sederhana, lakukan saja:
$ env: TEMP = " Z:your tempfolder "
wslcompactFolder TEMP baru akan aktif hanya untuk sesi terminal PowerShell, jadi tidak ada masalah sama sekali untuk sisa sistem dan tidak akan meninggalkan sampah.
Operasi yang khas adalah:
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.
Memadatkan gambar ubuntu dengan konfirmasi:
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