microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.54k stars 823 forks source link

Can't use X-Server in WSL 2 #4106

Closed toml12953 closed 5 years ago

toml12953 commented 5 years ago

Trying to run z80pack, a Z-80 CPU simulator. Before update to WSL 2, z80pack would open a graphical representation of an IMSAI computer. Now, I get the following error: FrontPanel Simulator v2.1 Copyright (C) 2007-2015 by John Kichury Can't connect to display ":0" Segmentation fault

Release 1.36, Copyright (C) 1987-2017 by Udo Munk IMSAI 8080 Simulation Release 1.17, Copyright (C) 2008-2017 by Udo Munk

CPU speed is 2 MHz RAM size is 54 KB

Loader statistics for file bootrom.hex: START : d800H END : df7fH LOADED: 0780H (1920)

FrontPanel Simulator v2.1 Copyright (C) 2007-2015 by John Kichury Can't connect to display ":0" [{WIFSIGNALED(s) && WTERMSIG(s) == SIGSEGV}], 0, NULL) = 36 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=36, si_uid=1000, si_status=SIGSEGV, si_utime=3, si_stime=0} --- rt_sigreturn({mask=[]}) = 36 write(2, "Segmentation fault\n", 19Segmentation fault ) = 19 read(10, "", 8192) = 0 exit_group(139) = ? +++ exited with 139 +++

benhillis commented 5 years ago

How are you seeing your DISPLAY variable in your Linux environment? Currently you will need to specify the IP address of the host, you can easily find this by looking at your /etc/resolv.conf file:

root@BENHILL-DELL:/mnt/c/Users/benhill# cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 192.168.110.177

Then you'll run:

export DISPLAY=192.168.110.117:0

You may also need to launch vcxsrv with the -ac argument.

This is an area that we are working on improving in an update soon.

toml12953 commented 5 years ago

Thank you! I added -ac to the vcxsrv command line and changed the export statement to use the IP address and now I can run GUI programs again.

ameeno commented 5 years ago

is there a command i can use to return this IP address only? (not the comments or the word nameserver, jus tthe IP itself

craigloewen-msft commented 5 years ago

Yes in the bash shell you can run:

cat /etc/resolv.conf | grep nameserver | awk '{print $2}' 
sirredbeard commented 5 years ago

You could combine into:

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
ameeno commented 5 years ago

Thanks guys, this works.

I think vcxarv needs -ac argument to work

sithlord2 commented 5 years ago

i have the same issue, I tried to do what you are saying guys but no luck I cant launch any GUI with wsl2 in my X Server

sithlord2 commented 5 years ago

and I forgot , the only thing I didn't tried is to launch vcxsrv with -ac argument if you can explain beter how to do it, that will be helpful cause I cant with export DISPLAY=my host ip:0 I got the message that xfce4-session cant display

simonzhaoms commented 5 years ago

I have the same issue as @sithlord2 . Below is my configuration of VcXsrv: 01

02

03

When I tried to launch gedit by DISPLAY=172.17.104.241:0.0 gedit, the command got stuck:

PS C:\Users\simon> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu          Stopped         2
  Ubuntu-18.04    Stopped         1
PS C:\Users\simon> wsl
simon@QGHRP0C:/mnt/c/Users/simon$ cd
simon@QGHRP0C:~$ sudo apt install gedit
simon@QGHRP0C:~$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.17.104.241
simon@QGHRP0C:~$ ifconfig | grep 'inet '
        inet 172.17.104.249  netmask 255.255.0.0  broadcast 172.17.255.255
        inet 127.0.0.1  netmask 255.0.0.0
simon@QGHRP0C:~$ DISPLAY=172.17.104.241:0.0 gedit

My systeminfo is:

PS C:\Users\simon> systeminfo

Host Name:                 QGHRP0C
OS Name:                   Microsoft Windows 10 Enterprise Insider Preview
OS Version:                10.0.18922 N/A Build 18922
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Multiprocessor Free
Original Install Date:     6/17/2019, 5:59:54 AM
System Boot Time:          6/18/2019, 1:39:58 AM
System Manufacturer:       HP
System Model:              HP Z4 G4 Workstation
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 85 Stepping 4 GenuineIntel ~3600 Mhz
BIOS Version:              HP P61 v01.76, 4/22/2019
Windows Directory:         C:\WINDOWS
System Directory:          C:\WINDOWS\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Total Physical Memory:     32,488 MB
Available Physical Memory: 24,802 MB
Virtual Memory: Max Size:  37,608 MB
Virtual Memory: Available: 27,712 MB
Virtual Memory: In Use:    9,896 MB
Page File Location(s):     C:\pagefile.sys
Hotfix(s):                 N/A
Network Card(s):           6 NIC(s) Installed.
                           [01]: Intel(R) Ethernet Connection (2) I219-LM
                                 Connection Name: Ethernet
                                 Status:          Media disconnected
                           [02]: PANGP Virtual Ethernet Adapter
                                 Connection Name: Ethernet 8
                                 Status:          Media disconnected
                           [03]: Intel(R) I210 Gigabit Network Connection
                                 Connection Name: Ethernet 2
                                 DHCP Enabled:    Yes
                                 DHCP Server:     N/A
                                 IP address(es)
                           [04]: Hyper-V Virtual Ethernet Adapter
                                 Connection Name: vEthernet (Default Switch)
                                 DHCP Enabled:    No
                                 IP address(es)
                                 [01]: 172.17.41.241
                                 [02]: fe80::44dc:a5ae:5762:d831
                           [05]: Hyper-V Virtual Ethernet Adapter
                                 Connection Name: vEthernet (New Virtual Switch)
                                 DHCP Enabled:    Yes
                                 DHCP Server:     10.222.220.4
                                 IP address(es)
                                 [01]: 10.168.2.39
                                 [02]: fe40::f496:a4cd:e4dc:4f0a
                                 [03]: 2444:f501:58:45c:f576:b551:b5f8:35b8
                                 [04]: 2464:f861:46:46c:f696:a16d:e6dc:a60a
                           [06]: Hyper-V Virtual Ethernet Adapter
                                 Connection Name: vEthernet (WSL)
                                 DHCP Enabled:    No
                                 IP address(es)
                                 [01]: 172.17.104.241
                                 [02]: fe90::692b:f95c:9bcd:690
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.
ameeno commented 5 years ago

-ac is most important because it allows public access. Wsl2 is a VM with a different IP address

simonzhaoms commented 5 years ago

Hi @ameeno, is -ac equivalent to checking 'Disable access control' in the configuration above? If yes, I still cannot make GUI apps shown in Windows. If not, then where should I put -ac?

ameeno commented 5 years ago

I think -ac is equivalent but best to try the flag. Right click on the shortcut to the application and select properties. On the box where it is the path to the app, append -ac.

Make sure you have closed the app and exited from the taskbar icon.

And launch using the shortcut you just edited

ameeno commented 5 years ago

Also make sure your windows firewall is not blocking the connections

simonzhaoms commented 5 years ago

Thank you very much @ameeno. I think you are right, though I have no permission to turn off the firewall of Windows to prove it.

sithlord2 commented 5 years ago

Simonzhaoms , if you in powers hell type systeminfo at the bottom of all your gonna get an ip which is your ip address just export DISPLAY=THAT IP ADDRESS :0 AN YOU CAN LAUGH YOU APPS ON YOUR X SERVER :)

sithlord2 commented 5 years ago

I did that an worked for me

GittyMac commented 5 years ago

I've tried to do all of the instructions but now I'm just stuck at X server already running on display IP:0.

GittyMac commented 5 years ago

Oh I had the firewall set to the wrong type of network. I apologise.

sithlord2 commented 5 years ago

is any body here that ,have the problem of getting DC of the internet every 5 o 15 minutes after launching xserver since i download and install the 18917 and yesterday 18922 that says ,it fixes bugs and other staff but still getting DC is because the linux kernel on the subsystem is stiil as test kernel or both the NT kernel and the linux kernel are run by hyper-v , cause since i upgrade and register in windows insider ,i'm having that problem of DC my internet ,before that i didnt have any of that problem.

sithlord2 commented 5 years ago

is any body here that ,have the problem of getting DC of the internet every 5 o 15 minutes after launching xserver since i download and install the 18917 and yesterday 18922 that says ,it fixes bugs and other staff but still getting DC is because the linux kernel on the subsystem is stiil as test kernel or both the NT kernel and the linux kernel are run by hyper-v , cause since i upgrade and register in windows insider ,i'm having that problem of DC my internet ,before that i didnt have any of that problem, and im really getting tired of it.

sithlord2 commented 5 years ago

i hope mscraiglowen can answer me, if not a problem ,with my post above this, cause that problem started when i change from wsl1 to wsl2 een before making work now my x-server i started getting Disconnected from internet ,i ask cause before changing to wsl2 i havent had that problem, thats why i asked about if both kernels are run by hyper-v , i mean the NT kernel and theNew wsl linux kernel or only the windows subsystem kernel.

sithlord2 commented 5 years ago

for got my real name is enrique

craigloewen-msft commented 5 years ago

Hi @sithlord2 , if you're getting disconnected every 5 to 15 minutes when running an X server please open up a new issue describing that problem, this issue is already resolved as it's focused on how to connect to an X server in the first place.

As far as your questions about kernels, WSL 2 doesn't have a test kernel, and I would be hard pressed to get why the kernel might be affecting your X server connection.

Again, please open up a new issue on this repo describing your problem with steps for us on how we can reproduce it and we will gladly take a look! Thank you.

tcztzy commented 5 years ago

Yes in the bash shell you can run:

cat /etc/resolv.conf | grep nameserver | awk '{print $2}' 

grep can get the FILE parameter, cat is useless.

grep nameserver /etc/resolv.conf | awk '{print $2}'

And even simpler

grep -oP "(?<=nameserver ).+" /etc/resolv.conf
seb128 commented 5 years ago

That's something I had some issues to get working recently but finally managed to work out, I put some notes what I did on my Ubuntu 18.04 WSL2 installation, in case it's useful to others https://community.ubuntu.com/t/getting-graphical-applications-to-work-on-wsl2/11868

Note that I had to disable the firewall to get those to work which is not a recommended solution, I would welcome help in figuring out what rules are required and how to set them up in the windows defender config if someone has a clue about that.

DrDinosaur commented 5 years ago

I got this working, but I also had to allow the process through the Windows Firewall and my screen number or whatever it's called was a different number than 0, so my display value was IP:XXX.0 (where XXX was my screen number). I saw this value in the server log and it also shows if you hover over the icon in the tray.

L1ghtman2k commented 5 years ago

Agree with @seb128, would be good to know the firewall rules that have to be in place since disabling firewall is just a horrible idea

awilts commented 5 years ago

@L1ghtman2k For me it is working just fine without any custom firewall rules. However I can see vcxserv in the list of allowed apps in my firewall configuration. That entry was added automatically by the installation. No further firewall configuration was required.

Update: Ok, the above is not true at all. The installation creates an active vcxserv rule for private networks. But network interface over which WSL2 accesses the host is regarded as a public network! So the existing rule needs to be enabled for public networks as well.

L1ghtman2k commented 5 years ago

Hey @AlexWil, it seems like I did have following rule for vcxsrv.exe: image I have also added xlaunch.exe for exceptions image, however, that still did not resolve the issue :(

UPD: One of the 2 things fixed this for me:

teglia commented 5 years ago

So, then you can basically just use

export DISPLAY=`grep -oP "(?<=nameserver ).+" /etc/resolv.conf`:0

in your .bashrc?

That's working for me, btw. I also am just checking the box to disable access control, I can't figure out where you all are putting the -ac bit that actually works.

rob-solana commented 5 years ago

my firewall rules for Public networks: image image the above, plus "disable access control" in my config.xlaunch image plus the "nameserver" trick

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

Has me launching xterms from a Windows desktop icon that connect to vcxsrv.

It works, but sucks because if I ever end up on a 172.16-172.31 public network, my xserver is likely gonna be exposed.

it'd be nice if the 'localhost' hack worked both ways...

lwinch commented 5 years ago

my /etc/resolv.conf did not have the correct IP address. I used the ipconfig command in powershell to show my correct local IP address. It is located under the "Ethernet adapter vEthernet (WSL)" section

ericblade commented 5 years ago

should you happen to have the docker desktop with wsl2 support up, it looks like you can

cat /etc/hosts | grep host.docker.internal | awk '{print $1}'    
JelteF commented 5 years ago

It works, but sucks because if I ever end up on a 172.16-172.31 public network, my xserver is likely gonna be exposed.

@rob-solana My current solution is to disable the firewall on the WSL interface. That makes sure that xserver won't be exposed on your actual interface no matter its IPs. image

The downside of this is that windows will complain that your firewall settings are "insecure". It really is a shame that you cannot limit a specific rule to an interface.

rob-solana commented 5 years ago

It works, but sucks because if I ever end up on a 172.16-172.31 public network, my xserver is likely gonna be exposed.

@rob-solana My current solution is to disable the firewall on the WSL interface. That makes sure that xserver won't be exposed on your actual interface no matter its IPs. image

The downside of this is that windows will complain that your firewall settings are "insecure". It really is a shame that you cannot limit a specific rule to an interface.

nice!

but this leaves us with image

garg10may commented 5 years ago

For me I had to enable all 4 options only then it is working.

  1. put the "-ac" option
  2. select "Disable access control"
  3. vi ~/.bashrc export DISPLAY=cat /etc/resolv.conf | grep nameserver | awk '{print $2}':0
  4. disable "firewall" (was using Nod32 firewall), switched to windows firewall and it by self asks whether to allow this application over the firewall and just select 'yes' for that.
garg10may commented 5 years ago

I had Vcxsrv working for few apps like sublime text, eclipse. However, if I try to open "firefox", "VcXsrv" icon in the tray is hanged/freezed and now previously working apps also do nothing. How can I resolve the same?

erkens commented 5 years ago

With my setup, the nameserver is different, I ended up by using the default gateway:

export DISPLAY=$(ip r l default | cut -d\ -f3):0

hugobuddel commented 5 years ago

FWIW, I didn't like to give everyone permission to my display with vcxsrv. Turns out that MobaXterm has a build-in X-server that asks permission every time a WSL app tries to open a window. I like that better than vcxsrv's open-for-all model (which seems to be equivalent to xhost -).

XavierGeerinck commented 5 years ago

Just wanted to share how I got this working:

  1. Install Xming https://sourceforge.net/projects/xming/
  2. Insecure mode: edit the desktop shortcut and add the option -ac to the end OR Secure mode: go to the installation directory and add the WSL ip in X0.hosts
  3. Run export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0 in WSL
Uzume commented 4 years ago

This type of code: export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0 can be shortened considerably to just: export DISPLAY=$(/etc/resolv.conf < awk '/nameserver/ {print $2}'):0 I am not sure how big of an optimization that is (it depends on how often that is executed), however, now only the shell and awk are forked (removing the need to fork cat and grep). It might be possible to do the parsing directly in the shell reducing the need to fork at all (but shell parsing is sort of painful). Of course @tcztzy also mentioned using: export DISPLAY=$(grep -oP "(?<=nameserver ).+" /etc/resolv.conf):0 but methinks awk is cleaner.

Discreater commented 4 years ago

It works, but sucks because if I ever end up on a 172.16-172.31 public network, my xserver is likely gonna be exposed.

@rob-solana My current solution is to disable the firewall on the WSL interface. That makes sure that xserver won't be exposed on your actual interface no matter its IPs. image

The downside of this is that windows will complain that your firewall settings are "insecure". It really is a shame that you cannot limit a specific rule to an interface.

After I restart my Windows, this configuration will fail. In fact, after windows restart, WSL Interface will not be created untill WSL is first started. And the new WSL Interface is different from the previous. So, the firewall must be reconfigured after restarting and running WSL.

JelteF commented 4 years ago

@Discreater that's sadly the case indeed. To automate the clicks you can at least use this Powershell command (needs to be run as administrator):

Set-NetFirewallProfile -Name public -DisabledInterfaceAliases "vEthernet (WSL)"
numeric-lee commented 4 years ago

I was able to use graphic applications in WSL using XMING and Export DISPLAY=:0.0

However, once I upgraded to WSL2 and switching to Export DISPLAY = 172.28.801:0 (my host#) it failed to connect

Things tried:

downloading VcXsrv switching to another graphics application running vcxsrv -ac from bash (command not recognized) running vcxsrv -ac from powershell (command not recognized) turning firewall off My Windows 10 build: 19041.1

Here is a typical error message

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-lw' qt.qpa.screen: QXcbConnection: Authorization required, but no authorization protocol specified Could not connect to any X display.

In #4106 you advise to run "vcxsrv -ac" from the bash command line and at least one user accepted that as a solution. I downloaded vcxsrv.exe from sourceforge as an .exe outside of bash, and I see no way to execute it from bash

Many thanks

rob-solana commented 4 years ago

I made a "Run as Administrator" shortcut on my desktop for turning off the Windows firewall. The "Target:" is

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command " Set-NetFirewallProfile -DisabledInterfaceAliases 'vEthernet (WSL)'"
edburns commented 4 years ago

Why do I have to turn off the Windows firewall?

rob-solana commented 4 years ago

Linux X clients can't connect to a Windows X server unless you disable the firewall for the WSL interface

edburns commented 4 years ago

Thanks @rob-solana I see. And your script only disables it for that interface. I am observing another problem. If the network connection is interrupted for any reason, the X clients are killed. This is a terrible user experience. Why does it not work to set the DISPLAY to 127.0.0.1:0.0 ?

rob-solana commented 4 years ago

Yeah, just for that internal interface that (I hope) only Linux and Windows can see.

I'd guess that 127.0.0.1 doesn't work because the Windows' side 127.0.0.1 interface isn't route-able from the Linux side.

The loss of clients when you change networks is a well known annoyance. Dunno if there's a github issue for it.

edburns commented 4 years ago

@rob-solana Yes, there is.