Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
toml12953 opened this issue Jun 13, 2019 · 140 comments
Closed

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

toml12953 opened this issue Jun 13, 2019 · 140 comments
Labels
wsl2 Issue/feature applies to WSL 2

Comments

@toml12953
Copy link

toml12953 commented Jun 13, 2019

  • Your Windows build number: (Type ver at a Windows Command Prompt)
    Microsoft Windows [Version 10.0.18917.1000] with Ubuntu 18.04, WSL 2.
    VcXsrv X Server Version 1.20.1.4

  • What you're doing and what's happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)

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

  • What's wrong / what should be happening instead:
    A picture of an IMSAI computer should appear in a separate window.

  • Strace of the failing command, if applicable: (If some_command is failing, then run strace -o some_command.strace -f some_command some_args, and link the contents of some_command.strace in a gist here).

tom@TOM-HOME-PC:~/z80pack/imsaisim$ strace ./cpm22
execve("./cpm22", ["./cpm22"], 0x7ffd01082fd0 /* 23 vars */) = 0
brk(NULL)                               = 0x55675a8f8000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/tls/x86_64/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/tls/x86_64/x86_64", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/tls/x86_64", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/tls/x86_64", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/tls", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/x86_64/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/x86_64/x86_64", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/x86_64", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel/x86_64", 0x7ffe267a5690) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/tom/z80pack/frontpanel/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/tom/z80pack/frontpanel", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
openat(AT_FDCWD, "tls/x86_64/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "tls/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "tls/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "x86_64/x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "x86_64/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=63323, ...}) = 0
mmap(NULL, 63323, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd3e1cea000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\34\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2030544, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd3e1ce8000
mmap(NULL, 4131552, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fd3e16e2000
mprotect(0x7fd3e18c9000, 2097152, PROT_NONE) = 0
mmap(0x7fd3e1ac9000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7fd3e1ac9000
mmap(0x7fd3e1acf000, 15072, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fd3e1acf000
close(3)                                = 0
arch_prctl(ARCH_SET_FS, 0x7fd3e1ce9540) = 0
mprotect(0x7fd3e1ac9000, 16384, PROT_READ) = 0
mprotect(0x55675a19a000, 8192, PROT_READ) = 0
mprotect(0x7fd3e1cfa000, 4096, PROT_READ) = 0
munmap(0x7fd3e1cea000, 63323)           = 0
getuid()                                = 1000
getgid()                                = 1000
getpid()                                = 33
rt_sigaction(SIGCHLD, {sa_handler=0x556759f91200, sa_mask=~[RTMIN RT_1], sa_flags=SA_RESTORER, sa_restorer=0x7fd3e1720f20}, NULL, 8) = 0
geteuid()                               = 1000
brk(NULL)                               = 0x55675a8f8000
brk(0x55675a919000)                     = 0x55675a919000
getppid()                               = 31
stat("/home/tom/z80pack/imsaisim", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
openat(AT_FDCWD, "./cpm22", O_RDONLY)   = 3
fcntl(3, F_DUPFD, 10)                   = 10
close(3)                                = 0
fcntl(10, F_SETFD, FD_CLOEXEC)          = 0
geteuid()                               = 1000
getegid()                               = 1000
rt_sigaction(SIGINT, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGINT, {sa_handler=0x556759f91200, sa_mask=~[RTMIN RT_1], sa_flags=SA_RESTORER, sa_restorer=0x7fd3e1720f20}, NULL, 8) = 0
rt_sigaction(SIGQUIT, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=~[RTMIN RT_1], sa_flags=SA_RESTORER, sa_restorer=0x7fd3e1720f20}, NULL, 8) = 0
rt_sigaction(SIGTERM, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGTERM, {sa_handler=SIG_DFL, sa_mask=~[RTMIN RT_1], sa_flags=SA_RESTORER, sa_restorer=0x7fd3e1720f20}, NULL, 8) = 0
read(10, "#!/bin/sh\n\nrm -f disks/drivea.ds"..., 8192) = 108
stat("/home/tom/bin/rm", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/home/tom/bin/rm", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/rm", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/rm", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/rm", 0x7ffe267a5cd0)    = -1 ENOENT (No such file or directory)
stat("/usr/bin/rm", 0x7ffe267a5cd0)     = -1 ENOENT (No such file or directory)
stat("/sbin/rm", 0x7ffe267a5cd0)        = -1 ENOENT (No such file or directory)
stat("/bin/rm", {st_mode=S_IFREG|0755, st_size=63704, ...}) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fd3e1ce9810) = 34
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 34
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=34, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]})                 = 34
stat("/home/tom/bin/ln", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/home/tom/bin/ln", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/ln", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/ln", 0x7ffe267a5cd0) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/ln", 0x7ffe267a5cd0)    = -1 ENOENT (No such file or directory)
stat("/usr/bin/ln", 0x7ffe267a5cd0)     = -1 ENOENT (No such file or directory)
stat("/sbin/ln", 0x7ffe267a5cd0)        = -1 ENOENT (No such file or directory)
stat("/bin/ln", {st_mode=S_IFREG|0755, st_size=67808, ...}) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fd3e1ce9810) = 35
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 35
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=35, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]})                 = 35
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fd3e1ce9810) = 36
wait4(-1,
 #####    ###     #####    ###            #####    ###   #     #
#     #  #   #   #     #  #   #          #     #    #    ##   ##
#     # #     #  #     # #     #         #          #    # # # #
 #####  #     #   #####  #     #  #####   #####     #    #  #  #
#     # #     #  #     # #     #               #    #    #     #
#     #  #   #   #     #  #   #          #     #    #    #     #
 #####    ###     #####    ###            #####    ###   #     #

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
Copy link
Member

benhillis commented Jun 13, 2019

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.

@benhillis benhillis added the wsl2 Issue/feature applies to WSL 2 label Jun 13, 2019
@toml12953
Copy link
Author

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
Copy link

ameeno commented Jun 13, 2019

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
Copy link
Member

Yes in the bash shell you can run:

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

@sirredbeard
Copy link
Contributor

You could combine into:

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

@ameeno
Copy link

ameeno commented Jun 15, 2019

Thanks guys, this works.

I think vcxarv needs -ac argument to work

@sithlord2
Copy link

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
Copy link

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
Copy link

simonzhaoms commented Jun 18, 2019

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
Copy link

ameeno commented Jun 18, 2019

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

@simonzhaoms
Copy link

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
Copy link

ameeno commented Jun 18, 2019

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
Copy link

ameeno commented Jun 18, 2019

Also make sure your windows firewall is not blocking the connections

@simonzhaoms
Copy link

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
Copy link

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
Copy link

I did that an worked for me

@GittyMac
Copy link

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
Copy link

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

@sithlord2
Copy link

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
Copy link

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
Copy link

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
Copy link

for got my real name is enrique

@craigloewen-msft
Copy link
Member

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
Copy link

tcztzy commented Jul 15, 2019

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

@ahsan-a
Copy link

ahsan-a commented Nov 24, 2020

None of the solutions that I tried worked. What worked for me is to put my computer's local IP address 192.168.0.30 which can be found by typing ipconfig in powershell and getting the IP address of your network adapter. I then added DISPLAY=$192.168.0.30:0 to my .zshrc (if you're using bash instead of zsh, add this to your .bashrc or switch to zsh because it's better), set this to your local IP address. I loaded up XLaunch with My display number as 0, and "disable access control" turned on. Also make sure x11 forwarding is set to yes in your /etc/ssh/sshd_config and everything should work fine. This took me 3 days to fix and i'm annoyed the solution was so simple, but i couldn't find it anywhere :(

@iraklic
Copy link

iraklic commented Dec 2, 2020

I am glad I found this thread. VcXsrv with '-ac' option and 'export DISPLAY=:0' worked for me. BUT... here is a question. I have another machine where I installed ubuntu bash few years ago and everything simply worked (and still does) with Xming and 'export DISPLAY=localhost:0.0'. So what is really different? Why did it stop working?

@bread22
Copy link

bread22 commented Dec 3, 2020

I ended up writing a function and putting it in ~/.profile which utilizes the fact that one can call ipconfig.exe from inside WSL. From that I can extract the IPv4 of the VPN adapter. I'm sure it's a very non-optimal solution since I'm not good with grep, awk and sed, but it kinda works for me.

parse_host_ip() {
    # This will return the line number of the DNS suffix for the VPN adapter
    LINE_NUM=$(ipconfig.exe | grep -n $<DNS suffix value> | cut -d ":" -f1)
    # The IPv4 is on the line below the DNS suffix
    LINE_NUM=$(($LINE_NUM+1))
    # Next extract the IPv4 from the ipconfig output
    HOST_IP=$(ipconfig.exe | sed -n "${LINE_NUM} p" | cut -d ":" -f2 | awk '{$1=$1};1')
    # This will be Windows output with CR-LF line endings. Remove the CR characters
    echo "${HOST_IP/$'\r'/}"
}

export DISPLAY=$(parse_host_ip):0

I haven't found any way to make it work without being connected to my VPN.

I am having the exact same issue with coporate VPN, and this works for me.
Thank you so much!

@srirambm
Copy link

srirambm commented Dec 6, 2020

I am on WSL2 and Ubuntu 20.4
same problem continues in my own way i guess
DISPLAY variable set to the nameserver thing which matches the system info IP address for WSL Network Adapter in .bashrc
Fiddled with windows defender and inally got the VcXSrv to be permitted
I still get the annoying Error: Cannot Open display:192.168.25.97:0
when I try to run xeyes
:-(

@Neznakomec
Copy link

Neznakomec commented Jan 5, 2021

I'm mostly overcomed all that problems, but can't make an auto launch
of xfce4 window with VBS script.

In WSL version 1 that worked fine:
WScript.CreateObject("Shell.Application").ShellExecute "wsl", "cd /home/ershov; DISPLAY=:0 LANG=ru_RU.UTF-8 su ershov -c xfce4-session", "", "open", 0

But now in WSL2 I can't launch the same:
WScript.CreateObject("Shell.Application").ShellExecute "wsl", "cd /home/ershov; LANG=ru_RU.UTF-8 su ershov -c xfce4-session", "", "open", 0

Although manual typing works:

  1. open cmd
  2. type 'wsl'
  3. then type cd /home/ershov
  4. then type 'LANG=ru_RU.UTF-8 su ershov -c xfce4-session'

What i'm doing wrong?

*my user 'ershov' haven't any password

@Shadowhawk100
Copy link

Shadowhawk100 commented Feb 17, 2021

None of these solutions really worked for me on WSL 2 - fedora (which is not officially supported I guess since it's not in the windows store).

The hint I needed that I don't really see anywhere here is that /etc/resolv.conf should have the nameserver [ipaddress] of your vEthernet (WSL) network adapter. Once that is set properly, export DISPLAY as described above with that same [ipaddress]:0 ...

My WSL environment was working mostly fine with different nameserver values (IE, my actual dns server or physical host IP), it was just X windows that needed the explicit WSL adapter IP.

@shortpoet
Copy link

New solution I found after working on this for hours 😀

https://stackoverflow.com/questions/61860208/wsl-2-run-graphical-linux-desktop-applications-from-windows-10-bash-shell-erro/66398613#66398613

However, I had problems using this solution, probably because I use my notebook with a WiFi connection and multiple virtual networks. Instead of the previous solution, I determine the Windows IP address using route.exe and checking the interface used in the default gateway.

export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0

@pauljohn32
Copy link

pauljohn32 commented Mar 29, 2021

Activating Cisco VPN broke both ethernet access to the world and the X11 server in WSL2 for me. I tried many fixes, all failed. Make sure that your ethernet and X11 work before turning on the VPN, then consider these ideas. Leave WSL closed for a moment.

About VPN. Problem is Linux has wrong IP for DNS. In Windows, connect with Cisco VPN. In Windows, the Cisco VPN client is running and if you click the VPN icon in the tray, you'll see a menu pop up and there's a "hamburger menu" where you'll see the IPV4 address info. The VPN changes both your IP and the nameserver. That will be same IP as you see in PowerShell running

ipconfig /a

look under the stanza that says Description... Cisco AnyConnect Secure Mobility Client. Should see same IPV4 address.

After you start WSL2, you'll see that the value of nameserver in /etc/resolv.conf is probably wrong and you will not have ethernet access nor will X11 apps work. To fix the X11 apps, run export DISPLAY=xxx.xxx.xxx.xxx:0.0, where xxx is the IPV4 address you see for the Cisco AnyConnect Device. If your X11 worked without VPN, it will work now.

It is harder to understand is fixing internet access. The problem is that the DNS server name is wrong. In my case, I have to manually edit /etc/resolv.conf EVERY TIME WSL2 starts, adding the nameservers at the end of the file. The Name servers are the "DNS Servers..." from the ipconfig output in windows. Appears now that reconfiguring /etc/wsl.conf to stop resolv.conf from resetting has no effect, must fix resolv.conf manually.

You may need to liberalize your firewall setting. In either X410 or VcxSrv, there's an option to allow public access.

If you still have network trouble, you may hit a problem that I hit at my company. The Cisco VPN not only restricts access but also does a sort of SSL-certificate manipulation. They installed a non-standard company certificate in Windows. I had to get the Windows certificate for my company and copy into WSL /usr/local/share/ca-certificate and run a re-configurator.

The big idea is to pull the certificate from the installed Windows system and use
it in the Linux side.

EXTRACT THE CERTIFICATE

In Windows, run the program called "mmc" (type that after clicking on the Start button).

In MMC, You see "Console1".

File > add Snapin > Certificates. Click OK.

Expand the left menu to show all of the Certificates.

In the left, under "Trusted Root Certification Authorities", click "Certificates". In the Right panel, scroll down to the special "root certificate for your company". If you can't find one, it probably means you don't need to bother with this.

Select the "Your Company Root Certificate Authority".

Right click > All Tasks >  Export

You are greeted by a Wizard.

There are 3 choices, choose #2.

1. DER encoded binary X.509 (.CER)
2. Base-64 encoded X.509 (.CER)
3. Cryptographic Message Syntax - PKCS #7 Certificate (.P7B)

On the WSL Ubuntu side

  1. Create a target folder, as root,
$ sudo mkdir /usr/local/share/ca-certificates
  1. Copy the cer file into target folder, cd into that folder

  2. Run following to convert the .cer file to .crt.

$ sudo openssl x509 -inform PEM -in Your_company_Root_Certificate.cer -out Your_Company.crt

That creates a new ".crt" file. The evidence of victory is in the output from the next step

  1. Finish.
$ sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
1 added, 0 removed; done.

If you don't see a cert added, then this failed.

@fengmao31
Copy link

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

image
image
???

@efa
Copy link

efa commented Apr 6, 2021

you can't expect google DNS to accept your X connections.
Fix your /etc/resolv.conf if you want that command work.
The content should report a private address class after "nameserver", not a public one like 8.x.x.x

@tukiyo
Copy link

tukiyo commented Apr 29, 2021

echo "export DISPLAY=\$(awk '/^nameserver/ {print \$2; exit}' /etc/resolv.conf):0" \
  >> ~/.profile

@kvnptl
Copy link

kvnptl commented Jul 8, 2021

thanks a lot, @shortpoet.

It took my whole day to make GUI working on WSL2+Ubuntu. Tried so many answers but no luck. Finally, @shortpoet answer worked for me.

Steps, I followed (Assuming, installed WSL2 + Ubuntu)

  1. Install vcxsrv on Windows

  2. Start XLaunch on Windows

    • Select Multiple Windows (default)
    • Select Start no client (default)
    • Check✅ Disable access control
    • Uncheck ☐ Native opengl
    • Save configuration on startup folder, location C:\Users\"YOUR_USERNAME"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup (don't forget to place YOUR_USERNAME)
    • Do this for safe side
  3. Open Ubuntu app, run command export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0 (as mentioend by @shortpoet ), also put the command in ~/.bashrc

  4. run sudo apt install x11-apps -y

  5. run xeyes

Voila!

I hope your GUI applications are running fine now.

PS: I am able run ROS Neotic (Gazebo and Rviz GUIs) on WSL2+Ubuntu 20.04.

Thanks,
K

@tjmoore
Copy link

tjmoore commented Jul 13, 2021

As a side note, this may be resolved for some with upcoming WSLg, now in preview. This adds GUI support to WSL. Appears to use a companion hidden distro with an X server and other GUI and some audio bits, running supposedly seamlessly. I haven't tried it yet.

https://devblogs.microsoft.com/commandline/the-initial-preview-of-gui-app-support-is-now-available-for-the-windows-subsystem-for-linux-2/

@boxdox
Copy link

boxdox commented Sep 12, 2021

thanks a lot, @shortpoet.

It took my whole day to make GUI working on WSL2+Ubuntu. Tried so many answers but no luck. Finally, @shortpoet answer worked for me.

Steps, I followed (Assuming, installed WSL2 + Ubuntu)

  1. Install vcxsrv on Windows

  2. Start XLaunch on Windows

    • Select Multiple Windows (default)
    • Select Start no client (default)
    • Check✅ Disable access control
    • Uncheck ☐ Native opengl
    • Save configuration on startup folder, location C:\Users\"YOUR_USERNAME"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup (don't forget to place YOUR_USERNAME)
    • Do this for safe side
  3. Open Ubuntu app, run command export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0 (as mentioend by @shortpoet ), also put the command in ~/.bashrc

  4. run sudo apt install x11-apps -y

  5. run xeyes

Voila!

I hope your GUI applications are running fine now.

PS: I am able run ROS Neotic (Gazebo and Rviz GUIs) on WSL2+Ubuntu 20.04.

Thanks,
K

If you are still not able to run, try opening vcxsrv and have a look at the titlebar, it should mention where the Display server is listening on. For me, it was running as my system name (forgot what this is called).

image

then inside wsl, I did: export DISPLAY=ASUS-TUF-F15:0.0 and it started working.

@Tapuzi
Copy link

Tapuzi commented Oct 14, 2021

Xming users: Run Xlaunch, check under "Specify parameter settings" the "No Access Control" box.

Don't thank me, thank Microsoft

@efa
Copy link

efa commented Oct 14, 2021

we should thanks Microsoft, as we do not depend anymore on the outdated Xming public domain 2007, see WSLg:
https://github.com/microsoft/wslg

@jarom-nelson
Copy link

It had been working great for me to run my WSL GUI applications using a launch script (first argument is the distro name, second argument is the Linux application):

@echo on
for /f "tokens=3 delims=: " %%I in ('netsh interface IPv4 show addresses "vEthernet (WSL)" ^| findstr /C:"IP Address"') do set ip==%%I
set ipAddress=%ip:~1%
Powershell.exe wsl -d %1 "DISPLAY='%ipAddress%':0" %2

But then sometime in October 2021, the above stopped working on one of my computers. Haven't figured out what's different, but after digging around, I think I stumbled upon the solution: use the IP of the host interface, whichever one has a Default Gateway, which in my case was "Ethernet 2". You may have to experiment a bit to figure out which one works.

@echo on
for /f "tokens=3 delims=: " %%I in ('netsh interface IPv4 show addresses "Ethernet 2" ^| findstr /C:"IP Address"') do set ip==%%I
set ipAddress=%ip:~1%
Powershell.exe wsl -d %1 "DISPLAY='%ipAddress%':0" %2

@skoshy
Copy link

skoshy commented Dec 7, 2021

thanks a lot, @shortpoet.
It took my whole day to make GUI working on WSL2+Ubuntu. Tried so many answers but no luck. Finally, @shortpoet answer worked for me.
Steps, I followed (Assuming, installed WSL2 + Ubuntu)

  1. Install vcxsrv on Windows

  2. Start XLaunch on Windows

    • Select Multiple Windows (default)
    • Select Start no client (default)
    • Check✅ Disable access control
    • Uncheck ☐ Native opengl
    • Save configuration on startup folder, location C:\Users\"YOUR_USERNAME"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup (don't forget to place YOUR_USERNAME)
    • Do this for safe side
  3. Open Ubuntu app, run command export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0 (as mentioend by @shortpoet ), also put the command in ~/.bashrc

  4. run sudo apt install x11-apps -y

  5. run xeyes

Voila!
I hope your GUI applications are running fine now.
PS: I am able run ROS Neotic (Gazebo and Rviz GUIs) on WSL2+Ubuntu 20.04.
Thanks,
K

If you are still not able to run, try opening vcxsrv and have a look at the titlebar, it should mention where the Display server is listening on. For me, it was running as my system name (forgot what this is called).

image

then inside wsl, I did: export DISPLAY=ASUS-TUF-F15:0.0 and it started working.

This helped out a lot for me, but I had to make a slight change to make calling route.exe work. I was getting this error at first:

/mnt/c/Windows/system32/route.exe: Invalid argument

If you are too, change the command to

export DISPLAY=$((cd /mnt/c && route.exe) print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0

For some reason I needed to cd into the C:\ drive for route.exe to work

@zhmlcg
Copy link

zhmlcg commented Dec 25, 2021

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.

@benhillis:
I use your method to open the display and run GUI apps in WSL 2 correctly. In the quoted text you said this will be improved soon in an update. But it is 2021 now and a couple of days into 2022, I still have to use IP to specify a display. Is this area that hard to improve? When will we not need to add IP to specify a display?

@phreed
Copy link

phreed commented May 3, 2022

You might try using the following command to set the firewall rule.

New-NetFirewallRule -DisplayName "WSL2" -Direction Inbound  -InterfaceAlias "vEthernet (WSL)"  -Action Allow

@VenkyDevHub
Copy link

thanks a lot, @shortpoet.

It took my whole day to make GUI working on WSL2+Ubuntu. Tried so many answers but no luck. Finally, @shortpoet answer worked for me.

Steps, I followed (Assuming, installed WSL2 + Ubuntu)

  1. Install vcxsrv on Windows

  2. Start XLaunch on Windows

    • Select Multiple Windows (default)
    • Select Start no client (default)
    • Check✅ Disable access control
    • Uncheck ☐ Native opengl
    • Save configuration on startup folder, location C:\Users\"YOUR_USERNAME"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup (don't forget to place YOUR_USERNAME)
    • Do this for safe side
  3. Open Ubuntu app, run command export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0 (as mentioend by @shortpoet ), also put the command in ~/.bashrc

  4. run sudo apt install x11-apps -y

  5. run xeyes

Voila!

I hope your GUI applications are running fine now.

PS: I am able run ROS Neotic (Gazebo and Rviz GUIs) on WSL2+Ubuntu 20.04.

Thanks, K

Not working on my machine although I followed the exact procedure prescribed.

@iraklic
Copy link

iraklic commented Dec 22, 2023

Actually with the latest updates and on Win11 a separate Xserver is not required anymore. It is still needed if you ssh somewhere, but for WSL2 it is not needed. In addition now one can go back to usin xming with default setup, the special settings are not needed anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wsl2 Issue/feature applies to WSL 2
Projects
None yet
Development

No branches or pull requests