QMonkey / wsl-tutorial

A tutorial about how to run desktop environment inside Windows Subsystem for Linux
642 stars 60 forks source link

xrdb: Can't open display #11

Open lackovic opened 4 years ago

lackovic commented 4 years ago

Following wsl2-tutorial - using ArchLinux instead of Ubuntu - I get the following error when I try to run startxfce4:

$ startxfce4
/usr/sbin/startxfce4: X server already running on display 192.168.96.1:0
xrdb: Connection timed out
xrdb: Can't open display '192.168.96.1:0'
Failed to connect to bus: No such file or directory
dbus-update-activation-environment: error: unable to connect to D-Bus: Using X11 for dbus-daemon autolaunch was disabled at compile time, set your DBUS_SESSION_BUS_ADDRESS instead
Unable to init server: Could not connect: Connection refused
xfce4-session: Cannot open display: .
Type 'xfce4-session --help' for usage.

$ env | grep -i dbus returns an empty result.

So I run $ export $(dbus-launch) and then:

$ env | grep -i dbus
DBUS_SESSION_BUS_PID=6069
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-LGwJ05xky5,guid=5d62e22c1553514e0ab605f65ef24f39

With that I got rid of the unable to connect to D-Bus error, but then I got another one:

$ startxfce4
/usr/sbin/startxfce4: X server already running on display 192.168.96.1:0
xrdb: Connection timed out
xrdb: Can't open display '192.168.96.1:0'
Failed to import environment: Process org.freedesktop.systemd1 exited with status 1
Unable to init server: Could not connect: Connection refused
xfce4-session: Cannot open display: .
Type 'xfce4-session --help' for usage.

Some other info:

$ systemctl --user status
Failed to read server status: Process org.freedesktop.systemd1 exited with status 1

$ systemctl --user show-environment
Failed to get environment: Process org.freedesktop.systemd1 exited with status 1

$ systemctl status -l --no-pager user@$(id -u).service
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

Any idea where the problem could be and how I can fix it?

lackovic commented 4 years ago

The problem was the IP address.

On Windows I have:

> ipconfig.exe

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   IPv4 Address. . . . . . . . . . . : 192.168.96.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : lan
   IPv4 Address. . . . . . . . . . . : 192.168.1.238
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

where the former refers to the WSL instance, while the latter refers to the Windows host.

For some reason WSL resolves its own IP address as nameserver:

$ cat /etc/resolv.conf

/etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 192.168.96.1

Manually entering the IP of the Windows host has fixed the issue for me:

DISPLAY=192.168.1.238:0

I wonder whether this a problem with my specific system configuration or they changed something in WSL 2 recently that made this setup not working anymore.

Can anyone confirm whether the display server specification is still working for them?

Does anyone know another way to get the host IP address other than using resolv.conf?

Using Windows 10 Version 2004 Build 19041.330.

avan2s commented 4 years ago

Hello guys :)

had the same issue and changing the DISPLAY variable from the WSL vEthernet-Adapter to the Ethernet Adapter was working fine like you said @lackovic . In order to automate it i replaced in the ./bashrc file: export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

to (the first ipv4 Address in the command ipconfig.exe) - hacky solution i don't like it, but it did the job for me: export DISPLAY=$(ipconfig.exe | awk '/IPv4/ {sub("\r",":0"); print $NF;exit}')

Since this is a really hacky solution and i saw everyone getting the ip address from the /etc/resolv.conf file, i investigated the issue a little bit more. The /etc/resolv.conf file should hold the ipv4 address of the vEthernet (WSL) Adapter. So the DISPLAY=192.168.96.1:0 in the post above should also be fine. I wanted to give up, but after lots of investigation i figured out that the windows firewall was causing this issue. If i deactivated the the firewall for the (open profile in system settings in windows), restarting the xserver and the wsl, i was able to open my display (in my case it was intelliJ /opt/idea/bin/idea.sh ).

With this knowledge i stopped the xserver on windows, activated the windows firewall again, activated the logging (for blocking rules) in the windows firewall. But the logfile did not ouput anything useful.

After that i checked the firewall and checked all the the xserver authorization rules. It is really important that all checkboxes for the server are checked (especially the public one was causing the trouble on my side): image

Restart firewall, xserver and wsl and everything was working fine. I think i missed this to check the box when xserver was running the first time. And after that it is finally running with the (WSL vEthernet ip) in the /etc/resolv.conf :-) Hope it helps someone with the same issue.

Thanks and best regards Andy