WSL: Cannot use GUI apps/tools as Wayland socket doesn't exist in `XDG_RUNTIME_DIR`
Windows Version
10.0.19044.4046
WSL Version
2.0.14.0
Are you using WSL 1 or WSL 2?
- WSL 2
- WSL 1
Kernel Version
5.15.133.1-1
Distro Version
Arch
Other Software
- wl-clipboard 2.2.1 (shouldn’t be the root cause)
- systemd 255.4-2
Repro Steps
- Install
wl-clipboard->sudo pacman -S wl-clipboard - Run
echo "foobar" | wl-copy
Expected Behavior
foobar is copied to Windows clipboard through Wayland
Actual Behavior
❯ echo "foobar" | wl-copy
Failed to connect to a Wayland server: No such file or directory
Note: WAYLAND_DISPLAY is set to wayland-0
Note: XDG_RUNTIME_DIR is set to /run/user/1000/
Please check whether /run/user/1000//wayland-0 socket exists and is accessible.
Diagnostic Logs
Not applicable
Additional Note
I couldn’t open any GUI apps and any Wayland-related tools such as wl-copy.
❯ echo "foobar" | wl-copy
Failed to connect to a Wayland server: No such file or directory
Note: WAYLAND_DISPLAY is set to wayland-0
Note: XDG_RUNTIME_DIR is set to /run/user/1000/
Please check whether /run/user/1000//wayland-0 socket exists and is accessible.
The following are the content of /run/user/1000/
❯ ls -la /run/user/1000/
total 0
drwx------ 7 mangkoran mangkoran 220 Mar 7 08:38 ./
drwxr-xr-x 3 root root 60 Mar 7 08:34 ../
srw-rw-rw- 1 mangkoran mangkoran 0 Mar 7 08:34 bus=
prw------- 1 mangkoran mangkoran 0 Mar 7 08:34 fish_universal_variables.notifier|
drwx------ 2 mangkoran mangkoran 60 Mar 7 08:34 gcr/
drwx------ 2 mangkoran mangkoran 160 Mar 7 08:34 gnupg/
drwxr-xr-x 2 mangkoran mangkoran 60 Mar 7 08:34 p11-kit/
srw-rw-rw- 1 mangkoran mangkoran 0 Mar 7 08:34 pipewire-0=
srw-rw-rw- 1 mangkoran mangkoran 0 Mar 7 08:34 pipewire-0-manager=
drwxr-xr-x 2 mangkoran mangkoran 60 Mar 7 08:34 pulse/
drwxr-xr-x 6 mangkoran mangkoran 160 Mar 7 08:34 systemd/
Based on that it seems wayland-0 socket is missing in XDG_RUNTIME_DIR. Hmm pretty weird I think as I don’t disable guiApplications in .wslconfig.
Then I found https://github.com/microsoft/wslg/issues/1187. I proceed to check /mnt/wslg/runtime-dir/.
❯ ls -la /mnt/wslg/runtime-dir/
total 0
drwx------ 4 mangkoran mangkoran 120 Mar 7 09:24 ./
drwxrwxrwt 8 root root 320 Mar 7 08:34 ../
drwx------ 3 mangkoran mangkoran 60 Mar 7 08:34 dbus-1/
drwx------ 2 mangkoran mangkoran 80 Mar 7 08:34 pulse/
srwxrwxrwx 1 mangkoran mangkoran 0 Mar 7 08:34 wayland-0=
-rw-rw---- 1 mangkoran mangkoran 0 Mar 7 08:34 wayland-0.lock
And yep there it is. So Wayland socket is currently not in XDG_RUNTIME_DIR. It seems the Wayland socket was previously symlinked in XDG_RUNTIME_DIR as in https://github.com/microsoft/WSL/issues/10205. Then I tried to link the Wayland socket.
~
❯ ln -s /mnt/wslg/runtime-dir/wayland-0* /run/user/1000/
~
❯ echo "foobar" | wl-copy
~
❯ echo $status
0
Although it works as intended, I think this isn’t the default behavior/a regression.
Workaround
As a workaround, I created a simple systemd user oneshot service/unit.
❯ cat ~/.config/systemd/user/symlink-wayland-socket.service
[Unit]
Description=Symlink Wayland socket to XDG_RUNTIME_DIR
[Service]
Type=oneshot
ExecStart=/usr/bin/ln -s /mnt/wslg/runtime-dir/wayland-0 $XDG_RUNTIME_DIR
ExecStart=/usr/bin/ln -s /mnt/wslg/runtime-dir/wayland-0.lock $XDG_RUNTIME_DIR
[Install]
WantedBy=default.target
Enable it using the following command.
systemctl --user enable symlink-wayland-socket.service
[!TIP] For Ubuntu 24.04 user, please refer to additional workaround by @noopole https://github.com/microsoft/WSL/issues/11261#issuecomment-2233443300
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 43
- Comments: 48 (5 by maintainers)
Links to this issue
Commits related to this issue
- fix: https://github.com/microsoft/WSL/issues/11261 — committed to naveenkumarg-oss/dotfiles by deleted user 2 years ago
- revert: https://github.com/microsoft/WSL/issues/11261 — committed to naveenkumarg-oss/dotfiles by deleted user 2 years ago
- refactor: make wsl-clipboard fast using the workaround See: https://github.com/microsoft/WSL/issues/11261#issuecomment-2334775209 — committed to naveenkumarg-oss/dotfiles by deleted user 2 years ago
- github.com/microsoft/WSL/issues/11261 — committed to yilisharcs/.dotfiles by yilisharcs 2 years ago
To make it work under Ubuntu 24.04 I had to set
rxpermissions or change owner onruntime-dir, then I could create the simlink.(where 1002 is the current user.)
Here is another workaround according to this post. Create
/etc/systemd/system/user-runtime-dir@.service.d/override.confand add:This will link everything in
/mnt/wslg/runtime-dirto/run/user/$UID. The reason why I don’t mount/mnt/wslg/runtime-dirat/run/user/$UIDlike what the original post does is that it will causeuser@UID.service’s failure due to/run/user/$UID’s incorrect owner@arf1372 You could try the symlink command first (not the systemd service) and see if solves the issue on your machine.
This command is harmless as it just symlinks and not removing any files. If anything goes wrong, you could restart WSL and everything will be reverted.
This issue has been automatically closed since it has not had any author activity for the past 7 days. If you’re still experiencing this issue please re-file it as a new issue.
Thank you!
I hate auto ignore issues bots! Now you are just going to get duplicates if multiple people try to resubmit this…
Fixed with https://github.com/microsoft/WSL/releases/tag/2.5.1
I looked into this topic more thoroughly with WSL 2.3.26 and WSL 2.4.8 and both meet the following description when systemd is enabled:
/run/usertmpfs mount point./run/user/<UID>subdirectory and populates it with the interesting contents, such as the wayland-0 socket.user-runtime-dir@<UID>.serviceunit eventually kicks in and attempts to create the user runtime directory as a mount point, but it first checks whether that directory is already a mount point or not:https://github.com/systemd/systemd/blob/main/src/login/user-runtime-dir.c#L81-L82
Here we fork. On older versions of systemd that don’t contain this commit, the binary
/lib/systemd/systemd-user-runtime-dirchecks whether the existing/run/user/<UID>is a mount point and the check “suceeds” because the line below makes thepath_is_mount_point()function return 0, what the comparison considered succesful.https://github.com/systemd/systemd/blob/main/src/basic/mountpoint-util.c#L274-L275
Newer versions of systemd had that behaviour fixed (return 0 is not a mount point), thus instead of stopping there, the
systemd-user-runtime-dirbinary proceeds with creating/run/user/1000as a tmpfs mount point, effectively wiping out any previous content.Ubuntu 22.04 is an example of the first case while Ubuntu 24.04 demonstrates the second case.
I suspect the easiest and cleanest way to solve this is by having WSL create
/run/user/<UID>as a tmpfs mount point instead of directory.right? I mean why the rush, you are just going to create more work for yourself. Now I can never expect to see a resolution for this 😪
bad bot!
Although this issue is about Wayland, for anyone who found this becaus X apps don’t work either (like me), if you want to use X11 apps, too, you will also have to symlink
/mnt/wslg/.X11-unix/X0to/tmp/.X11-unix/X0.I’m also still having the same issues in the new prerelease, I wonder if there are settings we can check to make sure we’re getting a ‘clean’ config?
Hi @benhillis . Could we keep this ticket opened as long as the fix hasn’t applied yet? The bot isn’t quite helpful. Most of us already know that many people may follow this issue and we don’t want to add “unhelpful” comment just to keep the issue from being closed by the bot.
Hey Carlos, thanks for digging in and helping here! I think you’re right, I just built a private WSL that creates a tmpfs mount as /run/user/<uid> and it looks like the repo above is working. I’ll clean this up and get this submitted.
Thanks to everybody for your help here.
So, this may not be a satisfying work-around for everyone, but this poblem was bowing up my Neovim session, because WAYLAND_DISPLAY was set, causing Neovim to assume that wl-copy was in play and working properly.
I added this awful bodge to my .zshrc that may help someone so I am including it here. If WSL is detected, we unset WAYLAND_DISPLAY but also add a ‘wway’ alias to put it back if we actually WANT to run a GUI app 😃
Yay! My neovim works again 😃
WSLg bug: https://github.com/microsoft/wslg/issues/1244
I’m happy to report that this is now fixed in my WSL2. Thanks everyone for all your hard work!
Many thanks, @mangkoran, for the precise description. I had the same problem with WSL 2.3.26.0 and distribution Debian 12 (Bookworm). The workaround fixed the problem.
For me on Ubuntu 24.04.01 LTS this script worked
I have no idea why @mangkoran script did not work, I know it worked for earlier Ubuntus under WSL
This is the same snippet, which had been already described as “workaround” in the initial description of this issue. However, I was referring to ideas about how to make the permission change permanent, which has been mentioned by @noopole above:
@king-11 It should be the following.
I will add this to my top post.
PS: A quick Google search should help you faster 😉
Many thanks, @mangkoran, for the details and the service script. Had the same issue with WSL 2.1.5 and Fedora 39 and the workaround fixed it.
Can confirm with:
Versions
Workaround
Exactly what @mangkoran mentioned by creating a oneshot systemd service.