WSL Notes

Page Contents

Windows WSL CLI Reference

# List all distros
wsl --list --verbose

# Run a specific distro with specific user
wsl -d distro-name --user user-name

# Convert distro to WSL 1 or 2
wsl --set-version DISTRO_NAME 2

# Set default version
wsl --set-default-version 2

What Version Of WSL Am I Running On?

To find out your version use:

cat /proc/version

The differences between the versions can be found here.

Use GUI Apps

The networking subsystem in WSL2 is different than the used in WSL1...

  • In WSL1, Linux uses the same IP addresses than the Windows host, then, you can access the applications using localhost or
  • In WSL2, Linux runs on a lightweight virtual machine and has a different IP address. To access networking apps running on the Windows Host you must use the Windows IP address.


Just run XMing, VcXsrv, or some other app on Windows and in WSL bash:

export DISPLAY=

As a side note, for kdiff3 on Ubuntu 20 on WSL1, had to do:

sudo strip --remove-section=.note.ABI-tag /usr/lib/x86_64-linux-gnu/

No idea why but it fixed the issue!


"Just" run XMing, VcXsrv, or some other app on Windows and in WSL bash:

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

This didn't work for me... the app seemed to "run" but just hung with no GUI being displayed. Used WSL1 instead :/

Generic Script

# set DISPLAY to use X terminal in WSL
# in WSL2 the localhost and network interfaces are not the same than windows
if grep -q WSL2 /proc/version; then
    # execute route.exe in the windows to determine its IP address
    DISPLAY=$(route.exe print | grep | head -1 | awk '{print $4}'):0.0

    # In WSL1 the DISPLAY can be the localhost address
    if grep -q icrosoft /proc/version; then


Connect USB Devices WSL2

Microsoft article link. Install the latest usbipd.exe from here.


  1. Download the latest version of USBIPD-WIN and install.
  2. Then in WSL2 prompt:
    sudo apt install linux-tools-generic hwdata
    sudo update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/*-generic/usbip 20
  3. To attach device make sure WSL command line is open.
    From PowerShell:
    1. [POWERSHELL] usbipd wsl list # List all of the USB devices connected to Windows
      Or ((usbipd wsl list | findstr -i st-link) -Split " +")[0]
    2. [POWERSHELL] usbipd wsl attach --busid <busid> # Select the bus ID of the device you’d like to attach to WSL
      Better: usbipd wsl attach --busid ((usbipd wsl list | findstr -i st-link) -Split " +")[0]
    3. [WSL] lsusb
    4. [POWERSHELL] usbipd wsl dettach --busid <busid> # Once you are done using the device in WSL, you can either physically disconnect the USB device or run this command

NOTE the above is now OUTDATED. The command is now isbipd attach --wsl --busid xxx.


URG! When upgrading, this service could not be stopped by the MSI installed on my PC. Use sc command on command prompy (not powershell) as follows:

sc query VBoxUsbMon

It was, for some reason stopping the install even though it appeared to be stopped. Tried:

sc delete VBoxUSBMon

This allowed the upgrade to proceed, BUT broke the install with the message "usbipd: error: The VBoxUsbMon driver is not correctly installed;...". To fix this, had to repair the install by doing:

sc create VBoxUsbMon type=kernel binPath= "C:\Windows\System32\drivers\VBoxUSBMon.sys"

Service Not Running

Saw the following error:

usbipd: error: The service is currently not running; a reboot should fix that.

Fixed using:

sc start usbipd