Skip to content

Instantly share code, notes, and snippets.

@Trass3r
Last active August 3, 2023 12:47
Show Gist options
  • Save Trass3r/435b4647a721c9f52c5f8e02d0a63dac to your computer and use it in GitHub Desktop.
Save Trass3r/435b4647a721c9f52c5f8e02d0a63dac to your computer and use it in GitHub Desktop.
Reduces disk space taken by the WSL and Docker vhdx files
$ErrorActionPreference = "Stop"
$files = Get-ChildItem -Path C:\Users -Recurse -Include "ext4.vhdx" -Force -ErrorAction SilentlyContinue | Select-Object FullName, Length
wsl -u root fstrim /
foreach ($file in $files) {
echo "Compacting $file"
wsl --shutdown
Mount-VHD -Path $file.FullName -ReadOnly
Optimize-VHD -Path $file.FullName -Mode Full
Dismount-VHD $file.FullName
}
Get-ChildItem -Path C:\Users -Recurse -Include "ext4.vhdx" -Force -ErrorAction SilentlyContinue | Select-Object FullName, Length
@Trass3r
Copy link
Author

Trass3r commented Aug 3, 2023

Yeah you can install them manually even on Home editions if you search for smth like "windows home hyperv install".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment