-
-
Save MrDwarf7/6d10f3b4e09e6e90702a917a3a64fd67 to your computer and use it in GitHub Desktop.
Script to help compact WSL and vhdx.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
net session >nul 2>&1 | |
if %errorlevel% neq 0 ( | |
echo Requesting administrative privileges... | |
powershell -Command "Start-Process '%~f0' -Verb RunAs" | |
exit /b | |
) | |
wsl sudo fstrim --all; echo "Exit status: $?"; | |
wsl --shutdown | |
:: ========= Instructions ========= | |
:: Please define your list of files here. | |
set fileList=("%LOCALAPPDATA%\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx" "%LOCALAPPDATA%\Docker\wsl\data\ext4.vhdx") | |
:: Process each file in the list. | |
for %%F in %fileList% do ( | |
echo Processing %%F using diskpart compact. | |
( | |
echo select vdisk file=%%F | |
echo detach vdisk | |
echo attach vdisk readonly | |
echo compact vdisk | |
echo detach vdisk | |
) | diskpart | |
) | |
echo Finished. | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment