WSL 2 in Windows 10

arturfog
5 min readDec 6, 2020

What is WSL2?

WSL2 is updated version of WSL (Windows Subystem for Linux) published in May 2020 for everyone (unlike WSL that was available only for Windows Insider members), that can be used to run Linux distributions like ie. Ubuntu inside Windows 10. What’s New in WSL2?’

Configuring WSL2 in Windows 10

WSL2 is available in Windows 10 Pro version 1909 and newer. Following steps were executed on version 2004.

Version of Windows can by checked by typing in terminal

winver.exe

For further steps I recommend new Windows Terminal app that can be found in Microsoft Store

We start configuring WSL2 by following command in terminal

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

After it’s installed we need to activate ‘Virtual Machine Platform’ by following command

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

When everything is installed we need to reboot our system.

To make sure WSL is in latest version it’s good to install following update:

https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

Simply run installer after it’s downloaded and follow regular installation steps

In final step we need to setup WSL2 as our default environment for running Linux distributions with following command

wsl --set-default-version 2

Installing Linux distribution (Ubuntu)

We’ve our set-up ready, from now on we can install Linux distributions available in Microsoft Store. There are various distributions available like Ubuntu/Fedora and others.

Let’s install Ubuntu 20.04 LTS by clicking ‘Download’

After it’s downloaded it will be available in Start menu as any regular application

Now we can simply run it (during first start new user account inside Ubuntu will be create, and we will be asked to set password for that new account)

Now finally we can access Ubuntu terminal

Basic Ubuntu configuration

Installed Ubuntu instance has very limited set of software installed

It’s good to start from updating software information to latest version

sudo apt get update

And then upgrade software

sudo apt get upgrade

After that we can install software we need like compilers/docker.io or browsers.

File access WLS2 <-> Windows

It’s possible to access Linux files from Windows and Windows files from Linux

To access Windows drives just enter /mnt location on Linux

All Windows drives are available from Ubuntu
Sample content of C: drive on Windows

To access Linux files from Windows we need to enter \\wsl$ location from Windows Explorer

Running applications with GUI (like Firefox/VLC)

Currently WSL2 is not supporting applications with graphical interface, it is announced that those will be supported in future.

But there is a way to launch those apps by using one of X-servers ported to Windows. I’ve tested with vcxsrv and it was working very well.

First we need to download vcsrv from sourceforge

https://sourceforge.net/projects/vcxsrv/

Then we follow usual installation steps

After that’s done we start X-server from Start menu

Now we need to configure it by selecting few options like display settings

and client startup settings

It’s important to select ‘Disable access control’ in last step to allow X-server to accept all client connections without any authorization

After that X-server will start and we can go back to Ubuntu console to finish configuration.

Last step needed is to set DISPLAY variable for GUI applications and enable LIBGL_ALWAYS_INDIRECT option

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

Now we can check if everything is working by running some application. In example I’ve tried with Firefox and results are as below.

All is working fine, there are no glitches or visible issues.

Sound in WSL2

Similar to graphics, audio is not supported out of the box, but similar to previous solution this can be solved using port of pulse audio server.

First we download latest version of pulse server port for Windows

At the moment of writing it was http://bosmans.ch/pulseaudio/pulseaudio-1.1.zip

After downloading files need to be extracted

Next etc\pulse\default.pa config file needs to be edited as follows

Also we need to allow incoming connections from our Ubuntu

Now we can save the file and edit etc\pulse\daemon.conf to disable closing of server after 20 minutes of inactivity

Now we are ready to start pulseuadio.exe using Windows terminal

Windows firewall will ask to allow incoming connection to pulseaudio

Click Allow and pulseaudio will start

Last thing left to do is to configure IP of pulseaudio server inside our Ubuntu

export PULSE_SERVER=tcp:172.26.112.1

We are ready to test if audio plays. I’ve tested using Firefox and sample movie from YouTube and all was working fine.

--

--