os/windows/ WindowsSubsystemForLinux


Wsl Versions

To set version 2 (Hyper-V):

PS> wsl --list
Ubuntu-20.04 (Default)
PS> wsl --set-default-version 2
(may tell you to update kernel version)
PS> wsl --set-version Ubuntu-20.04 2
(may take some time to convert)

Renaming a Wsl instance

This currently needs to be done via the registry. See this superuser question. In short: load regedit, and go to HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss where you will find each Wsl instance named by its GUID – e.g.

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{f31d4ad5-1271-4c2c-8c29-59c825e087e2}

And in this key you will find DistributionName which you can edit. Note that you need to ensure that all Wsl instances are not running when you do this.

X11 server

Now with Ubuntu 22.04 under Windows 11, graphics works out of the box.

I use Vcxsrv (presumably short for Visual C++ X Server)

You need to run the following script inside the Linux VM

export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=1

Then with Vcxsrv you need to disable access control.

Then you need to create a hole in the Windows firewall.

If you are on a home network, this is fine. If you are somewhere where being this permissive security-wise is risky, take care.

Ssh

SshServerWsl