WSL2 wslg problem

WSL2中,默认支持WSLg,可以直接打开GUI应用。但是缩放率比较小。我的WSL不知道从什么时候起突然有了毛病,再也打不开GUI应用,安装新的distro也是一样的cannot open display,大概是动了哪里的配置吧,没有自动创建WSLg的软链接。

参考

确认Windows版本

From a Windows command prompt, type ver to verify which build you are running.

1
2
>E:\wsl>ver
>Microsoft Windows [版本 10.0.26100.4349]

You must be running on Windows build version 21364+ for WSLg to work.

This version of Windows is currently only available through the Windows Insider program. See https://insider.windows.com/en-us/ to join the insider program and help us validate pre-released version of Windows.

Windows11一般都是支持WSLg的吧。

DISPLAY环境变量

WSLg's X server is running on display 0. The DISPLAY environment variable must have the value :0 for GUI application to connect to the right display. You can verify what the value of your DISPLAY environment variable is per below.

1
2
>name@hostname:~$ echo $DISPLAY
>:0

This environment variable is initialize as part of WSL's INIT. If it is unset or has a value other than :0, than you likely have a profile script that is changing it's value that you'll want to hunt down. You can also reset that environment variable like below.

1
>export DISPLAY=:0

有些教程的说法是export主机ip,但是对我的情况没什么作用。

X11 display socket

X servers create their socket under /tmp/.X11-Unix. This directory must exist and must be linked to /mnt/wslg/.X11-Unix where WSLg built-in X server create it's socket. You can verify the mapping exist and is the expected link per below.

1
2
>name@hostname:~$ ls -la /tmp/.X11-unix
>lrwxrwxrwx 1 name name 19 Apr 21 15:28 /tmp/.X11-unix -> /mnt/wslg/.X11-unix

This link is setup during WSL's INIT. If this directory doesn't exist, something likely caused it be removed in your environment that needs to be tracked down.

You can re-create the link manually to try things out.

1
2
>sudo rm -r /tmp/.X11-unix
>ln -s /mnt/wslg/.X11-unix /tmp/.X11-unix

X11 server running?

If the X server is running, you should see an X0 socket

1
2
>name@hostname:~$ ls /tmp/.X11-unix
>X0

If you don't please open an issue and attach /mnt/wslg/weston.log to the bug.

Known issues

You can verify the version of WSLg you are running per below:

1
2
3
4
5
6
7
>name@hostname:~$ cat /mnt/wslg/versions.txt
>WSLg ( x86_64 ): 1.0.17+3.Branch.master.Sha.a526dfd5ad03d126bb2d8c528f6c3563e86a40da
>Mariner: VERSION="1.0.20210224"
>FreeRDP: e4a2fc2053bd8c5f99455fcd08ffee7e5591567a
>weston: fd961f5cd116c9358d82ce94d139c1578e21bd00
>pulseaudio: 2f0f0b8c3872780f15e275fc12899f4564f01bd5
>mesa:

Complex monitor arrangement (Fixed in WSLg 1.0.19)

There is a known issue in WSLg 1.0.17 that if you have a combination of vertically and horizontally aligned monitor, Weston may hit an invalid assert and restart. Effectively crashing and restarting the X server on every connection attempt.

You can verify if this is what you are hitting per below

1
>cat /mnt/wslg/weston.log | grep isConnected_V

if you see something like

1
>weston: ../libweston/backend-rdp/rdpdisp.c:481: disp_monitor_validate_and_compute_layout: Assertion `isConnected_V == true' failed.

Then you are hitting this problem. The workaround at the moment is to stack all of your monitor either vertically, or horizontally, but not use a mix of both.

Setting /tmp in /etc/fstab

There is a known issue at the moment (https://github.com/microsoft/wslg/issues/43) where configuring /tmp in /etc/fstab will overwrite the /tmp/.X11-unix link previously described. The workaround at the moment is to either avoid configuring /tmp, or manually recreating the link

1
>ln -s /mnt/wslg/.X11-unix /tmp/.X11-unix

Still having a problem?

Please open an issue and include the following

  • Run the following command and provide the output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
>spronovo@OFFICE:~$ cat /mnt/wslg/versions.txt
>WSLg ( x86_64 ): <current>
>Mariner: VERSION="1.0.20210224"
>FreeRDP: 5f083fa0b97d433d6204985f6047886e29c1c61e
>weston: 16de531f00aa3dfd17e0de74c8f49e9fd7cec617
>pulseaudio: 2f0f0b8c3872780f15e275fc12899f4564f01bd5
>mesa: 2ad0684038f5732f7e4bd1a391ec9d833685fb48

>spronovo@OFFICE:~$ echo $DISPLAY
>:0

>spronovo@OFFICE:~$ ls -la /tmp/.X11-unix
>lrwxrwxrwx 1 root root 19 Apr 21 12:12 /tmp/.X11-unix -> /mnt/wslg/.X11-unix

>spronovo@OFFICE:~$ ls -la /tmp/.X11-unix/
>total 0
>drwxrwxrwx 2 root root 60 Apr 21 12:22 .
>drwxrwxrwt 5 root root 220 Apr 21 12:22 ..
>srwxrwxrwx 1 spronovo users 0 Apr 21 12:22 X0
  • Attach your /mnt/wslg/weston.log file