microsoft / wslg

Enabling the Windows Subsystem for Linux to include support for Wayland and X server related scenarios

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ubuntu 24.04 Wayland falling back to X11

avlec opened this issue · comments

Windows build number:

10.0.22621.0

Your Distribution version:

24.04

Your WSL versions:

WSL version: 2.1.5.0
Kernel version: 5.15.146.1-2
WSLg version: 1.0.60
MSRDC version: 1.2.5105
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.3296

Steps to reproduce:

  1. wsl --install Ubuntu-24.04
  2. setup account
  3. sudo apt update
  4. sudo apt install emacs-pgtk
    (or other GTK app)
  5. emacs

WSL logs:

stderr.log
weston.log
pulseaudio.log

WSL dumps:

No response

Expected behavior:

Emacs or whatever GUI application to launch using Wayland and not Xwayland

Actual behavior:

Outputs the following and falls back to xorg display frames.

MESA: error: ZINK: failed to choose pdev
glx: failed to create drisw screen

image

Some more context if I try to explicitly set the GDK_BACKEND as follows I just get the following console output, no window is opened, and the program terminates.

> GDK_BACKEND=wayland emacs

(emacs:1152): Gtk-WARNING **: 09:26:41.236: cannot open display: :0

On 22.04 I do not need to use weston. I can also just use emacs without pgtk but this should be something that works

Due to a bug of systemd fixed in 24.04, you must do :

ln -sf  /mnt/wslg/runtime-dir/wayland-* $XDG_RUNTIME_DIR/

Or use an autostart conf : https://github.com/viruscamp/wslg-links

BTW, It's real that wayland working in 22.04@WSL depends a bug of systemd.

Yeah I'm not having any luck with the symlink.

This is still happening #1244 (comment)

A weird quirk is that creating this symlink under your user account doesn't work (symlink is red in ls) but creating it when su'd into ubuntu the symlink creation works (symlink is blue in ls) but it still can't open the app.

commented

The fix provided by @viruscamp makes emacs work on wayland instead of Xwayland:

emacs-pgtk_wsl_wayland

Your ls -la $XDG_RUNTIME_DIR output should be like above.

Thanks @viruscamp!

So yeah no dice still. My XDG_RUNTIME_DIR seems to be missing things when compared to your screenshot.

In the screenshot creating those links under my user account doesn't work. Creating the links under the ubuntu user works but it still can't open the display.

image

Perhaps I'm running into this issue ubuntu/WSL#468 because I would have just used the ubuntu username but it complains that user already exists?

How are you installing 24.04? Are you updating from an existing 22.04?

Perhaps I'm running into this issue ubuntu/WSL#468 because I would have just used the ubuntu username but it complains that user already exists?

How are you installing 24.04? Are you updating from an existing 22.04?

I think you met the bug.

id avlec
id ubuntu

You can see that uid=1000 is ubuntu . WSLg works only for uid=1000. That another bug of WSLg.

Ubuntu's fix only applies to new install of 24.04.

Maybe there is only unstable and insecure method:

  • manually edit /etc/passwd to swap uid
  • chown uid for home of swapped user

Yes all of my attempts to use 24.04 on WSL have been fresh installs.

The fixes @viruscamp linked are working on the ubuntu user.

I'm just running into the user bug still with installing 24.04 fresh. (I removed the 24.04 app and reinstalled from winget) Is there some Windows or WSL update I have not gotten?

I guess the fixed wsl-setup package has not been put into the install image of ubuntu 24.04 for WSL.

We'd better wait them to publish a new image.

@avlec you're correct, wslg already starts a compositor:

Command line: /usr/bin/weston --backend=rdp-backend.so --modules=wslgd-notify.so --xwayland --socket=wayland-0 --shell=rdpr
ail-shell.so --log=/mnt/wslg/weston.log --logger-scopes=log,rdp-backend,rdprail-shell

Looks like the Ubuntu-24.04 switches to cloud-init and has user id=1000 defined in the cloud.cfg:

# System and/or distro specific settings
# (not accessible to handlers/transforms)
system_info:
  # This will affect which distro class gets used
  distro: ubuntu
  # Default user name + that default users groups (if added/used)
  default_user:
    name: ubuntu
    lock_passwd: True
    gecos: Ubuntu
    groups: [adm, cdrom, dip, lxd, sudo]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash

and the installer is creating a user with id=1002 messing up wslg which is hardcoded to user id=1000.

If you want to fix it and use emacs-pgtk with wayland backend just edit /etc/group and /etc/passwd and switch IDs. You also have to edit the regkey and change DefaultUid from 0x3ea (1002) to 0x3e8 (1000). Look for the corresponding distro keys in \HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\. Or, wait for the store package to be fixed.

emacs-pgtk works, after applying @viruscamp fix:

emacs_pgtk_ubuntu

Yes @elsaco that's where we've gotten to. Just don't know what @zcobol did to have it working without hacking the user/groups.

Note: an easier hack is to create a 24.04 and use a throw away username and then just do the registry edit trick to change the DefaultUid then you can login as ubuntu and apply viruscamp's fix

@viruscamp is there any issue anywhere tracking the problem you fixed?

I just did a clean install of Ubuntu 24.04 and applied viruscamp's fix and

lrwxrwxrwx 1 ubuntu ubuntu  31 May 19 06:54 wayland-0 -> /mnt/wslg/runtime-dir/wayland-0
lrwxrwxrwx 1 ubuntu ubuntu  36 May 19 06:54 wayland-0.lock -> /mnt/wslg/runtime-dir/wayland-0.lock

Linls are valid

But when I run google-chrome as the ubuntu user (id: 1000) I get:

MESA: error: ZINK: failed to choose pdev
glx: failed to create drisw screen
MESA: error: ZINK: failed to choose pdev
glx: failed to create drisw screen

Does anyone know why or have any suggestions on the best way to debug?

wsl --version shows:

WSL version: 2.2.2.0
Kernel version: 5.15.150.1-2
WSLg version: 1.0.61
MSRDC version: 1.2.5105
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22635.3640

I had a issue " Error: Can't open display: " when I tried to run applications.
PS: I had already installed package x11-apps .

Resolved:

step 1: Windows 11, open Powershell with Run as Administrator, Command line: wsl --update
After updated, I opened WSL ubuntu 24.04 LTS and executed command line: xeyes
And GUI open in Windows.

I don't know if this will help you.

image
I get these strange errors, but xeyes works...

@mwoodpatrick Try to enable systemd and the service from https://github.com/viruscamp/wslg-links, after restart wsl2 you may get chrome working.

To work around the user id issue, I used cloud-init customization

Created file
C:\Users\XXX\.cloud-init\Ubuntu-24.04.user-data

#cloud-config
users:
- default
- name: test
  gecos: Test
  groups: adm, admin, cdrom, floppy, sudo, audio, dip, video, plugdev, users, netdev
  shell: /bin/bash
  sudo: ALL=(ALL) NOPASSWD:ALL
  lock_passwd: false
  plain_text_passwd: test

Then destroyed my wsl environment, and recreated it this way

# THIS WILL DESTROY THE CURRENT INSTALL
wsl --unregister Ubuntu-24.04

ubuntu2404.exe install --root 
ubuntu2404.exe run cloud-init status --wait
wsl --terminate Ubuntu-24.04
wsl

Installed firefox, and it will be using xwayland

Apply the fix from @viruscamp
ln -sf /mnt/wslg/runtime-dir/wayland-* $XDG_RUNTIME_DIR

Firefox now runs fine with full wayland support

To make it run permanent, add it to /etc/bash.bashrc
(echo; echo'# FIX WSLG'; echo 'ln -sf /mnt/wslg/runtime-dir/wayland-* $XDG_RUNTIME_DIR/') >> /etc/bash.bashrc

For bonus point, add that step to cloud-init

- (echo; echo'# FIX WSLG'; echo 'ln -sf  /mnt/wslg/runtime-dir/wayland-* $XDG_RUNTIME_DIR/') >> /etc/bash.bashrc

BUT
what is still failing for me is glxgears (or google_chrome, ...)

$ glxgears
MESA: error: ZINK: failed to choose pdev
glx: failed to create drisw screen

UPDATE
After further investigating this, I believe for better hardware support the usage of the GPU driver that supports WDDM 3.x is required. But that is only supported since windows 11. With windows 10 we are stuck on 2.7. And we are still on windows 10 enterprise. Check dxdiag in windows to see you current version

Would appreciate it if someone could test this with a WDDM 3.x driver on windows 11...

I'm on Debian (12.6) in wsl and emacs 29.2 doesn't launch per above, so it's not just an Ubuntu issue. I compiled emacs locally (using --prefix=<mylocaldirectory>),

But confirm @viruscamp workaround works #1244 (comment).