Skip to content

Instantly share code, notes, and snippets.

@573
Last active April 17, 2025 10:01
Show Gist options
  • Save 573/e7e8ec1d43d588d828141b3e0952425a to your computer and use it in GitHub Desktop.
Save 573/e7e8ec1d43d588d828141b3e0952425a to your computer and use it in GitHub Desktop.
Shrink size of NixOS disk wsl diskpart resize

https://learn.microsoft.com/en-us/windows/wsl/disk-space#how-to-locate-the-vhdx-file-and-disk-path-for-your-linux-distribution

https://stephenreescarter.net/how-to-shrink-a-wsl2-virtual-disk/

wsl --shutdown
wsl --manage NixOS-Groundtruth -s false
(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq 'NixOS-Groundtruth' }).GetValue("BasePath") + "\ext4.vhdx" | Set-Clipboard
diskpart
> select vdisk file="\\?\C:\Users\dkahlenberg\NixOS\ext4.vhdx"
> compact vdisk
> exit
wsl --manage NixOS-Groundtruth -s true

Alternative:
https://superuser.com/questions/1606213/how-do-i-get-back-unused-disk-space-from-ubuntu-on-wsl2

Also:

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