Skip to content

Windows Subsystem for Linux

Stuart Hicks edited this page Jul 4, 2022 · 4 revisions

WSL integration

GUI Environments

These snippets only work in WSL2.

X410

https://x410.dev/ (This should also work for any other third-party X server)

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0

WSLg (Wayland)

https://github.com/microsoft/wslg

export DISPLAY=:0

Default browser

This makes the default browser in Windows, the default browser in WSL.

export BROWSER="powershell.exe /C start"

Maintenance

Shrinking Disk Space

This is only really useful if you free up a load of space within WSL, and then want to shrink the volume to make more space available to Windows. Make a copy of this script, and update the path to the WSL virtual disk depending on your system:

select vdisk file="C:\Users\stuar\AppData\Local\Packages\WhitewaterFoundryLtd.Co.16571368D6CFF_kd1vv0z0vy70w\LocalState\ext4.vhdx"  
compact vdisk
  1. Shut down WSL using wsl --shutdown in Windows.
  2. Open a PowerShell prompt with elevated permissions.
  3. Launch diskpart with the path to the script, eg: diskpart /s C:\Users\stuar\Documents\shrink_wsl.txt
  4. If it fails, reboot and try again (likely something keeping a file handle open on the vhdx file).
Clone this wiki locally