Getting graphical applications to work on WSL2

I’ve been trying to get graphical applications to work on WSL2. I started following the wiki instructions but things seem currently a bit more complicated that they were on WSL and the improvement @rbalint did in this wslu upload don’t seem enough.

The problem is known upstream and has to do with the fact that WSL2 has its own network configuration which means using localhost/127.0.0.1 to contact the xserver isn’t working.

I got it to work with those steps

  • Install an Xserver, I tried those options which work

    • x410 is available in the windows store with a free trial. Once started click on the systray icon and pick “Allow Public Access”

    • VcXsrv, download from https://sourceforge.net/projects/vcxsrv/ and install/start it. Specifying the server numer to be ‘0’ on the first screen and also allow public access

  • Disable Windows Defender Firewall for Guest or public Network (a better way would be to add firewall rules to allow only what is needed but I didn’t figure out how to do that yet, help welcome if anyone knows?)

  • In WSL

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

Starting a graphical application should work then, enjoy!

2 Likes

I installed Ubuntu today, on a Windows 10 Pro inseder program OS Build 19033.1 and the command :

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

doesn’t work.
On unbuntu the resolv.conf file contains the address of the real DNS used by the Windows 10 Pro and so the dislay variable contains the wrong address to be connected to for the X server
Strange on debian it still works outputting the display on the Ethernet adapter vEthernet (WSL):
Some hint to solve the problem?

I use Xming which is a Free Software X11 server. It allows to run full screen, full screen inside a window (with or without title bar, or each application on a different window and I export the DISPLAY by computing the variable value using the HOSTNAME environment variable and concatenating :0 to the value.

Following the hints in:
[https://wiki.ubuntu.com/WSL?_ga=2.98603357.2111654010.1574607031-1690325463.1570829333#Keeping_Ubuntu_up-to-date_in_WSL]

I installed “VcXsrv” on Windows side and for what I understand it listen to the Ethernet adapter vEthernet (WSL)

When I start ubuntu it doesn’t detect the Xserver running on the Windows 10 side.
The output of the ifconfig command is :
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.163 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::8f5:53e5:62f1:4425 prefixlen 64 scopeid 0xfd<compat,link,site,host>
ether 00:0e:c6:bb:3a:70 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 1500
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0xfe<compat,link,site,host>
        loop  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

After I start the “Debian” app ( I Have Ubunto and Debian on WSL 2) I got for the ifconfig

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.163  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::8f5:53e5:62f1:4425  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 00:0e:c6:bb:3a:70  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.29.48.1  netmask 255.255.240.0  broadcast 172.29.63.255
        inet6 fe80::7cbf:5c28:6775:433c  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 00:15:5d:4b:2c:89  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 1500
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0xfe<compat,link,site,host>
        loop  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Hi,
Just installed WSL2 today have used WSL1 for a while.
The behaviour I see is that the WSL Virtual Adapter is the one that gets propagated to resolvf.conf so the scripts that use this to setup DISPLAY variable don’t work.
My solution is a quick python script that calls ipconfig.exe and tries to determine the active adapter from that.
drop it into your home folder from here https://gist.github.com/buxtonpaul/2074bc4c56f53cf37a27e3d59ca7a29b
and use it by adding
export DISPLAY=$($HOME/wsldisplay.py))

It should find the first adapter with a link-local address that is not the WSL Virtual ethernet

Nice, i try your solution, but when i start i have this message:
/bin/sh: 1: ipconfig.exe: Input/output error

So Xming run good with wsl1

Hmm, can you try running ipconfig.exe directly from bash?

Thanks for you reply, i restart the session and ipconfig.exe run good now.

But new error , that’s look like python error, maybe some symbol or front are not understand.

Traceback (most recent call last): File "/home/romain/wsldisplay.py", line 5, in <module> for line in os.popen('ipconfig.exe'): File "/usr/lib/python3.8/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x85 in position 53: invalid start byte

Ok, I think you are finding the limits of my python :slight_smile:
I think what is happening is that you are running on a system with a non utf8 character set, and my code isn’t clever enough to handle it. I think that the popen command is supposed to be able select the correct settings for your locale, however I am wondering if the problem is that you have your windows set for one locale (I assume you use windows all the time and it is setup for where you live), and your linux installation is perhaps just defaulted to something, and it is this mismatch that is the problem?
if you run locale on your linux install, does it look like it matches what you would expect?

I confess I am a little out of my depth on unicode and python.

Microsoft has some instructions (that worked for me) at:

https://techcommunity.microsoft.com/t5/windows-dev-appconsult/running-wsl-gui-apps-on-windows-10/ba-p/1493242