Compacte de forma segura el tamaño de las imágenes WSL VHDX en constante crecimiento.
(¿Te gusta esta utilidad? Dale un y compártelo)
El subsistema de Windows para Linux (WSL) utiliza archivos de imagen VHDX para almacenar el sistema de archivos EXT4, pero carece de una forma efectiva de reducir la imagen cuando se eliminan los archivos. Esta utilidad no requiere credenciales elevadas, compactando las unidades virtuales VHDX de las distribuciones WSL2 y logrando el tamaño mínimo posible. De manera predeterminada, se realizará en modo de información, sin acción en las imágenes, proporcionando la siguiente información para todas las distribuciones instaladas:
Si no se especifica ninguna distribución, se dirigirá a todas las imágenes instaladas secuencialmente. Funciona en modo seguro durante el proceso compacto, evitando cualquier efecto secundario no deseado en caso de falla. Este es un caso de uso típico: compactación de la imagen de Ubuntu con confirmación:
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
Antes de instalar WSLCompact, asegúrese de que su instalación de WSL esté actualizada. Puede hacerlo escribiendo wsl --update en PowerShell. WSLCompact requiere al menos WSL versión 1.0.0.
Hay dos formas de instalar WSLCompact, elija su favorito:
Requiere una configuración especial para ejecutar un script remoto. Si lo ha configurado en el pasado, entonces ya no lo necesita. Si no está seguro, en PowerShell solo escriba:
Set-ExecutionPolicy RemoteSigned - Scope CurrentUserPara instalar o actualizar la utilidad, cierre todas sus instancias de PowerShell, abra una nueva y escriba:
iwr - useb https: // raw.githubusercontent.com / okibcn / wslcompact / main / setup | iexPara eliminar la utilidad, cierre todas sus instancias de PowerShell, abra una nueva y escriba:
Remove-Item " $ ( $ env: PSModulePath .split ( ' ; ' )[ 0 ] ) /WslCompact " - Recurse - ForceSi usa SCOOP Package Manager , puede agregar la utilidad WSLCompact directamente desde su cubo. Escriba PowerShell estas dos líneas:
scoop bucket add .oki https: // github.com / okibcn / Bucket
scoop install wslcompactPara actualizar la aplicación, simplemente escriba:
scoop update wslcompactPara eliminar la aplicación, solo escriba:
scoop uninstall wslcompactDespués de la instalación, el uso es sencillo:
wslcompact sin argumentos enumera todas las imágenes e información de WSL. No se realizará ninguna acción sobre imágenes.wslcompact Ubuntu .-c , WSLCompact modificará las imágenes después de la confirmación.-d permite el compacto de particiones de datos. La utilidad garantiza un tamaño mínimo y termina con archivos contiguos para un acceso más rápido en sistemas antiguos basados en HD. Si necesita la lista de nombres de sus distribuciones, se puede acceder escribiendo 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
Si su C: Drive no tiene suficiente espacio libre temporal, el programa no compacta esa distribución. Simplemente cambie la carpeta TEMP antes de llamar a la función. Entonces, en lugar de un simple wslcompact , solo haga:
$ env: TEMP = " Z:your tempfolder "
wslcompactLa nueva carpeta TEMP estará activa solo para esa sesión de terminal de PowerShell, por lo que no hay problema para el resto del sistema y no dejará basura.
Una operación típica sería:
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.
Compactando la imagen de Ubuntu con confirmación:
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