microsoft / wslg

Enabling the Windows Subsystem for Linux to include support for Wayland and X server related scenarios
MIT License
10.15k stars 303 forks source link

Unable to init server: Could not connect: Connection refused (gedit:1859): Gtk-WARNING : cannot open display:) #522

Closed neuberfran closed 2 years ago

neuberfran commented 2 years ago

Can anyone help-me with this issue: **Unable to init server: Could not connect: Connection refused (gedit:1859): Gtk-WARNING : 18:14:00.048: cannot open display:

wsl --update Checking for updates... There are no updates available. Versão do kernel: 5.10.60.1

wsl -l -v

NAME                            STATE           VERSION
* Ubuntu                        Running          2
 docker-desktop            Running          2
 docker-desktop-data    Running          2

in PowerShell 7 I have this result When I try found CBL Mariner PS C:\Users\neuberfran> wsl --system There is no distribution with the given name.

wslG-ubuntu2004-ISSUE

I tried this:

https://stackoverflow.com/questions/60284542/wsl-gedit-unable-to-init-server-could-not-connect-connection-refused

But not solved

meyayl commented 2 years ago

Have you checked https://github.com/microsoft/wslg/wiki/Diagnosing-%22cannot-open-display%22-type-issues-with-WSLg?

Most likely either /tmp/.x11-daemon is a directory instead of a symlink to /mnt/wslg/.X11-unix and/or the required environment variables are missing.

neuberfran commented 2 years ago

@meyayl tks for a while. I don't have wslg folder in /mnt directory. Can you help-me more

 ls -la /tmp/.X11-unix total 8 drwxrwxrwt 2 root root 4096 Oct 15 17:39 . drwxrwxrwt 9 root root 4096 Oct 16 22:44 .. srwxrwxrwx 1 neuberfran neuberfran 0 Oct 15 17:39 X10  neuberfran  /  tmp  cd .X11-unix/  neuberfran  /  tmp  .X11-unix  ls X10  neuberfran  /  tmp  .X11-unix  cd /mnt  neuberfran  /  mnt  cd wslg -bash: cd: wslg: No such file or directory  neuberfran  /  mnt  ls c d e neubao neubao2 wsl

issuewslG

meyayl commented 2 years ago

The output of ls -la /tmp would've been helpful. In all my wslg instances it is always x0, not x10. The non existing /tmp/wslg folder is odd.

Just to be sure: you performed wsl --update and wsl --shutdown to actualy replace the updated system distro?

Note: I am running Win11 final (build 22000).

neuberfran commented 2 years ago

@meyayl When I put  export DISPLAY=10:10 and not  export DISPLAY=0:0 I don't have more issue (When I try gedit command) but still can't see anything on xlaunch. Maybe it's some necessary settings in xlaunch. Or not.

you said "The non existing /tmp/wslg folder is odd." I don't have wslg in /mnt and in /tmp

I do wsl --update and wsl --shutdown in powershell 7 and powershell 5.1 with and without admin. wsl --update Checking for updates... There are no updates available. Versão do kernel: 5.10.60.1

Below is my w11 information. Remembering that my computer does not have tpm2.0 or 1.2 and my processor is not w11 compatible. My insider program comes from w10 home and not possible in w11:

issuewslg2

Masamune3210 commented 2 years ago

TPM and Proc version are unrelated, as both are not required for WSLg other than Virtualization support

meyayl commented 2 years ago

Can't realy help you. Your installation looks way different then mine.

I spend a good share of the weekend to understand how to make wslg work in my custom wsl distro . Though, what was the solution there, seem not to be the solution for you.

neuberfran commented 2 years ago

@meyayl What are you trying to say with my custom wsl distro?

Unfortunately the real solution here might be to reinstall wsl2/ubuntu. But I have several things in it that will need to be reinstalled.

meyayl commented 2 years ago

@meyayl What are you trying to say with my custom wsl distro?

Nothing. Just that I spend a lot of time to research how the wsgl integration is done - and your case looks completly different.

I am not sure if reinstalling ubuntu will heal the problems with the system distribution. With wslg each user distribution has a sibling system distribution (see https://www.youtube.com/watch?v=EkNBsBx501Q&t=2105s in case of questions) - in your case the system distribution doesn't seem to work as it should, otherwise /mnt/wslg would exist.

Good luck!

neuberfran commented 2 years ago

@meyayl I have final questions to take advantage of your knowledge:

1) Why did export DISPLAY=10:10 work?

2) I know it's not the right thing to do, but how to use xlaunch and/or Xming to solve my issue based on the link below:

https://stackoverflow.com/questions/60284542/wsl-gedit-unable-to-init-server-could-not-connect-connection-refused

neuberfran commented 2 years ago

I reinstalled wsl2/ubuntu 20.04 via microsoft store and installed Debian via wsl --install -d Debian and deleted the /tmp/.X11-unix folder. I had no evolution. I no longer have the X10.

onomatopellan commented 2 years ago

@neuberfran I would try installing the new WSL2 from the store. That contains WSLg already integrated and it takes preference to your present setup that for some reason fails to load the system distro. https://aka.ms/wslstorepage

Remember to run wsl.exe --shutdown first before installing it.

neuberfran commented 2 years ago

@onomatopellan issuewsl2store

I found the XServer - GWSL(Opticos Studios) app in MS Store I just tried it and I liked it. But I prefer use app directly from the command line of wsl2/ubuntu

neuberfran commented 2 years ago

I Solved (to gedit Only) with XLaunch: https://por.faithcov.org/293259-wsl-2-run-graphical-linux-FGVYKE

XLaunch/VcXsrv or Win+R and "C:\Program Files\VcXsrv\vcxsrv.exe": 0 -multiwindow -clipboard -wgl -ac"

1) Multiple windows 2) Start a program 3) Start program on this computer 4) select option Disable access control 5) in wsl2/ubuntu 20.04/Shell prompt 5.1) sudo apt-get install vim-gtk 5.2) export DISPLAY_NUMBER='0.0' export DISPLAY=$(grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}'):$DISPLAY_NUMBER export LIBGL_ALWAYS_INDIRECT=1 # OPTIONAL Set the keyboard layout to US setxkbmap -layout us setsid emacs exit

But not worked yet to Gimp. Don't close this issue. Please

neuberfran commented 2 years ago

@onomatopellan why I can't run wsl2 MS Store in my win11 pc

onomatopellan commented 2 years ago

@neuberfran what it shows when you run wsl.exe --version ? and wsl.exe -l -v ?

neuberfran commented 2 years ago

@onomatopellan

PS C:\Users\neuberfran> wsl --status Default Distribution: docker-desktop-data Default Version: 2 Versão do WSL: 0.48.2.0 Versão do kernel: 5.10.60.1 Versão do WSLg: 1.0.29 Versão do Windows: 10.0.22478.1012 PS C:\Users\neuberfran> wsl --version Versão do WSL: 0.48.2.0 Versão do kernel: 5.10.60.1 Versão do WSLg: 1.0.29 Versão do Windows: 10.0.22478.1012 PS C:\Users\neuberfran> wsl -l -v

NAME                   STATE           VERSION
* docker-desktop-data    Running         2
  docker-desktop           Running         2
  Debian                  Stopped         2
  Ubuntu-20.04            Stopped         2

PS C:\Users\neuberfran> wsl -l -v

NAME                   STATE           VERSION
* docker-desktop-data    Running         2
  docker-desktop           Running         2
  Debian                  Stopped         2
  Ubuntu-20.04            Running         2

issueanswers

onomatopellan commented 2 years ago

@neuberfran You are already running the WSL2 from the store but your default is pointing to the wrong distro. Run wsl.exe --set-default Ubuntu-20.04 for example and after that try wsl.exe --system again and see if the system distro is accessible.

neuberfran commented 2 years ago

@onomatopellan issue in wsl.exe --system command:

issuewslEXEsystemcommand

onomatopellan commented 2 years ago

@neuberfran Is that true? From powershell run notepad $env:USERPROFILE/.wslconfig. Does it show something?

neuberfran commented 2 years ago

@onomatopellan notepad $env:USERPROFILE/.wslconfig In PowerShell show ok.

Show in .wslconfig this: [wsl2] guiapplications=false

onomatopellan commented 2 years ago

@neuberfran Then that's the problem. Put a # in front of the last line like this

[wsl2]
#guiApplications=false

and save the file. After running wsl.exe --shutdown and running wsl again then gedit should work.

neuberfran commented 2 years ago

@onomatopellan works tks :smile:

spronovo commented 2 years ago

Hello @neuberfran,

Is your issue fully resolved? From the thread it looks like you had disabled GUI application in .wslconfig, which will disable our system distro and our X server. Our X Server publish itself on export DISPLAY=:0 (/mnt/wslg/.X11-unix/X0) and you need a symlink from /tmp/.X11-unix -> /mnt/wslg/.X11-unix for it to operate properly.

It also looks like you were trying to run multiple X server simultaneously. /tmp/.X11-unix/X10 you were asking about earlier in the thread is the socket created by VcXsrv. You can connect to that X Server by settings export DISPLAY=:10. Doing so will send output of X11 application to VcXsrv and not WSLg. While it is possible to run multiple X server on different socket and use the DISPLAY environment variable to select which one application should connect to (e.g. :0 vs :10), it is probably best to run only one at a time unless you are quite comfortable with X servers... also other X servers have a tendency to install script that break the symlink above and thus break WSLg, so something to watch for.

neuberfran commented 2 years ago

@spronovo When I commented out the guiApplications=false line in the .wslconfig file gedit and gimp (which didn't work on XLaunch using export DISPLAY_NUMBER = '0.0' export DISPLAY = $ (grep -m 1 nameserver /etc/resolv.conf | awk '{ print $2} '): $ DISPLAY_NUMBER export LIBGL_ALWAYS_INDIRECT = 1 # OPTIONAL Set keyboard layout to US setxkbmap -layout us setsid emacs exit) will work fine.

From then on the wslg folder inside /mnt appeared. I don't know if I need to command symbolic link. Everything seems to work now

spronovo commented 2 years ago

Sounds good, thanks @neuberfran. When you set guiApplications=false in .wslconfig, that prevent our system distro from starting, so there won't be a /mnt/wslg directory. That directory only exist when the system distro with WSLg is running.

Typically the most tricky part of running multiple X server is accidentally breaking the /tmp/.X11-unix mapping to /mnt/wslg/.X11-unix, so always a good thing to watch for. We have some more guidance here if you hit a snag again in the future. Diagnosing cannot-open-display type issues.

afcruzs commented 2 years ago

@spronovo thanks for that wiki link! that worked for me to realize the symlink of the socket wasn't created. I think is worth to put it on the main README.