Note
2025-11-17 では以下の両方とも不要。逆に問題を起こすし元の設定に戻しておいた方がよい
Warning
2025-11-17 時点では、tmp.mount の後に .X11-unix をマウントするように変わったらしい。fstab に追記してても動くけど、余計な設定なので何もしない方が良いと思う。
どうやら、こんな事が起きてるらしい
- WSL2 が boot した時に
/mnt/wslg/.X11-unixを/tmp/.X11-unixにマウントする - distro が起動した後 systemd が
tmp.mountターゲットを起動して/tmpが再マウントされるBefore=local-fs.targetになってる
- その結果、
/tmp/.X11-unixが消えてしまう
とりあえず解決策としては、/etc/fstab に /tmp を書いてあげれば tmp.mount より優先されるから問題が解決するっぽい。
- fstab は WSL が処理してくれる
/mnt/wslg/.X11-unixは fstab の後にマウントされるtmp.mountは/tmpがあれば動かない
fstab:
# Static information about the filesystems.
# See fstab(5) for details.
# <file system> <dir> <type> <options> <dump> <pass>
tmpfs /tmp tmpfs rw,nodev,nosuid,noatime 0 0
tmpfs /var/tmp tmpfs rw,nodev,nosuid,noatime 0 0
- https://wiki.archlinux.org/title/Tmpfs
- microsoft/WSL#1278
- microsoft/WSL#11739
- https://learn.microsoft.com/en-us/windows/wsl/wsl-config#automount-settings
Caution
2025-11-17 時点では、user-runtime-dir@.service の後に WSL が symlink を作るように挙動が変わったぽい。ので、以下の対策は現時点では不要で、逆にこれをやると /run/user/<uid> が作られなくなる。
/run/user/<uid>/waynald-0 が消えるやつ。こんな事が起きてる。
- WSL にユーザーが (最初に?) ログインした時に
/run/user/<uid>/wayland-0や/run/user/<uid>/pulse/native等を/mnt/wslg/runtime-dirから symlink してる - その後 systemd で
user@.service->user-runtime-dir@.serviceと動いて、user-runtime-dir@.serviceが/usr/lib/systemd/systemd-user-runtime-dirを使って/run/user/<uid>を tmpdir でマウントする - WSL が作った user runtime-dir が上書きされて
wayland-0がなくなる。
/usr/lib/systemd/systemd-user-runtime-dir が動かないようにすればいい。
cat <<EOF | sudo systemctl --stdin edit user-runtime-dir@.service
[Service]
ExecStart=
ExecStart=/bin/true
ExecStop=
ExecStop=/bin/true
EOF
user-runtime-dir@.service の mask だと user@.service の起動に失敗するからやめた方が良い。
/var/run/user/1000/wayland-0がないのはuser-runtime-dir@1000.serviceで上書きされるからっぽい。けど、これを mask すると
user@1000.serviceが開始できなくて、それはそれで困る。