notes

View on GitHub

WSL info

Trouble

Install

  1. Enable the Windows Subsystem for Linux (Powershell as admin):
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    
  2. Enable Virtual Machine feature (Powershell as admin):
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    
  3. Restart your machine to complete the WSL install.

  4. Download the Linux kernel update package: https://aka.ms/wsl2kernel (direct download).

  5. Set WSL 2 as your default version (as admin):
    wsl --set-default-version 2
    
  6. Goto Windows store and install your favorite (Debian) distro. (Direct download here.)

More info:

Upgrade Linux kernel

Suprise, surprise. This doesn’t happen automatically.

  1. Download the Linux kernel update package: https://aka.ms/wsl2kernel (direct download).

  2. Restart your machine, and your WSL should be running the new kernel version.

X Server and UI apps from WSL2

This is just a shit show! But here goes… (Info on VSOCK and WSL2)

Main guide: Using IntelliJ with Windows Subsystem for Linux 2.

Run the X Server with Cygwin/X

  1. Install XWin stuff with Cygwin/X as described here!

  2. Run this command:

    C:\cygwin64\bin\run.exe --quote /usr/bin/bash.exe -l -c "cd; exec /usr/bin/startxwin -- -ac -multiwindow -wgl -clipboard -noprimary -listen tcp"
    

Allow Inbound connections to C:\cygwin64\bin\xwin.exe in the Windows Firewall

  1. Launch the above command, and the first time it will ask for Firewall permissions. Only allow Private networks.
  2. This will create block rules on Public networks which needs to be removed or disabled.
  3. Create a new firewall rule:
    1. Right click on Inbound Rules
    2. Choose New Rule...
    3. Leave it at Program and choose Next >
    4. Set This program path to C:\cygwin64\bin\xwin.exe
    5. Leave it at Allow the connection and click Next >
    6. Only Public should be chosen and click Next >.
    7. Add a Name fx. xwin (WSL2) and click Finish.
    8. Open the newly created rule and go to Scope.
    9. Change Remote IP address to These IP addresses:.
    10. Click Add....
    11. Input all reserved private IPv4 network ranges. Yes it sucks! But WSL moves around from reboot to reboot!

Local IP ranges:

10.0.0.0/8
172.16.0.0/12
192.168.0.0/16

WSL Windows Toolbar Launcher has a good guide on the Firewall rules.

Set the DISPLAY ENV variable in Wsl2, preferably in the ~/.bashrc file

export WSL_HOST=$(grep ^nameserver /etc/resolv.conf | cut -d' ' -f2)
export DISPLAY=${WSL_HOST}:0.0

Vmmem using all memory and CPU?

We need to set some reasonable resource constraints on what WSL2 can actually use. Fortunately, that’s as simple as going to c:\users\*your your profile name* and creating a .wslconfig file. On my setup, a MSI Prestige 15 with a 10710u 6-core processor and 16GB of RAM, mine looks like this:

[wsl2]
memory=4GB # Limits VM memory in WSL 2 to 4 GB
processors=5 # Makes the WSL 2 VM use two virtual processors

And then, from Powershell with admin rights, restart WSL2 by typing:

Restart-Service LxssManager

Source

Launching Docker Desktop WSL2

PS C:\WINDOWS\system32> wsl -l -v
  NAME                   STATE           VERSION
* Debian                 Stopped         2
  docker-desktop-data    Stopped         2
  docker-desktop         Stopped         2
PS C:\WINDOWS\system32> wsl -l -v
  NAME                   STATE           VERSION
* Debian                 Stopped         2
  docker-desktop-data    Stopped         2
  docker-desktop         Running         2
PS C:\WINDOWS\system32> wsl -l -v
  NAME                   STATE           VERSION
* Debian                 Stopped         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2
PS C:\WINDOWS\system32> wsl -l -v
  NAME                   STATE           VERSION
* Debian                 Stopped         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2
PS C:\WINDOWS\system32> wsl -l -v
  NAME                   STATE           VERSION
* Debian                 Running         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2