You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Systemd/Snapd: /dev/shm symlink breaks some snaps with "Private Shared Memory" enabled. #8996
Linux version 5.15.68.1-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Mon Sep 19 19:14:52 UTC 2022
Distro Version
Ubuntu 20.04
Other Software
james@James-Desktop:~$ snap version
snap 2.55.5+20.04
snapd 2.55.5+20.04
series 16
ubuntu 20.04
kernel 5.15.68.1-microsoft-standard-WSL2
N.B: it is essential that snapd is version 2.55.5+, older versions of snapd do not understand this interface and will silently ignore it, and otherwise appear to install correctly.
Expected Behavior
Snap installs succesfully.
Actual Behavior
Snap fails to install due
- Setup snap "joplin-desktop" (28) security profiles for auto-connections (cannot obtain mount security snippets for snap "joplin-desktop": shared-memory plug with "private: true" cannot be connected if "/dev/shm" is a symlink)
Workaround:
james@James-Desktop:~$ sudo snap install joplin-desktop
[sudo] password for james:
error: cannot perform the following tasks:
- Setup snap "joplin-desktop" (28) security profiles for auto-connections (cannot obtain mount security snippets for snap "joplin-desktop": shared-memory plug with "private: true" cannot be connected if "/dev/shm" is a symlink)
james@James-Desktop:~$ sudo rm /dev/shm
james@James-Desktop:~$ sudo snap install joplin-desktop
joplin-desktop v2.8.8 from James Carroll installed
james@James-Desktop:~$ exit
logout
PS C:\Users\eloqu> wsl --shutdown
PS C:\Users\eloqu> ubuntu
james@James-Desktop:~$ joplin-desktop
>> opens, but with inproperly configured /dev/shm, as /dev/shm is re-created as a symlink on every boot.
(As I understand the history of the issue, this is a change from the pre-systemd practice which did require the symlink, and so if WSL is to also support those distributions - and indeed systemd-using distributions which aren't configured to run systemd - that'll need to be there. Perhaps creating it only if systemd != true in /etc/wsl.conf would be viable?)
(Debian sid just added systemd-sysctl.service, systemd-tmpfiles-setup-dev.service, and systemd-tmpfiles-setup.service to the list of units which make use of this, for example.)
These options require the shared memory tmpfs to be mounted at /dev/shm where systemd would, on native linux, put it automatically and fail if they find a symlink there instead.
I am currently working around this by creating and enabling the following systemd service (as fixshm.service) to swap the mount and symlink into their proper-under-systemd places:
[Unit]
Description=Fix the /dev/shm symlink to be a mount
DefaultDependencies=no
Before=sysinit.target
ConditionPathExists=/dev/shm
ConditionPathIsSymbolicLink=/dev/shm
ConditionPathIsMountPoint=/run/shm
[Service]
Type=oneshot
ExecStart=/usr/bin/rm /dev/shm
ExecStart=/usr/bin/mkdir /dev/shm
ExecStart=/bin/umount /run/shm
ExecStart=/usr/bin/rmdir /run/shm
ExecStart=/bin/mount -t tmpfs -o mode=1777,nosuid,nodev,strictatime tmpfs /dev/shm
ExecStart=/usr/bin/ln -s /dev/shm /run/shm
[Install]
WantedBy=sysinit.target
(Which workaround does also resolve the private-memory snap install issue.)
Reacted by Douglas, CactusPuppy, wrvsrx, diijkstra, Mike Waychison and O'Briat
I am currently working around this by creating and enabling the following systemd service (as fixshm.service) to swap the mount and symlink into their proper-under-systemd places:
That's working for me, but what about a simplified version (2-steps vs. 6) using a bind-mount:
[Unit]
Description=Fix the /dev/shm symlink to be a mount
DefaultDependencies=no
Before=sysinit.target
ConditionPathExists=/dev/shm
ConditionPathIsSymbolicLink=/dev/shm
ConditionPathIsMountPoint=/run/shm
[Service]
Type=oneshot
ExecStart=/usr/bin/rm /dev/shm
ExecStart=/bin/mount --bind -o X-mount.mkdir /run/shm /dev/shm
[Install]
WantedBy=sysinit.target
Reacted by CactusPuppy, diijkstra, Guillaume Desforges, Emmaly, Vitalii Mikhailov and Gabriel Freitas
No reason that wouldn't work; I only used the symlink version in the first place because that's what I was familiar with from previous experience. I've updated the server in bottle-imp 1.0 to use the bind mount, and it seems to be working fine.
I would expect so, but I am not familiar enough with Linux deep internals to know if there're any subtle differences between a bind mount of a mount point and the original mount point that something might care about.
(I think it's very unlikely that there is, but it's easy enough to emulate the exact systemd behavior that, well, why not?)
Side note: actually, in the current version of the service I make it less error-prone by moving the /run/shm mount rather than replacing it. as per here:
[Unit]
Description=Fix the /dev/shm symlink to be a mount
DefaultDependencies=no
Before=sysinit.target
ConditionPathExists=/dev/shm
ConditionPathIsSymbolicLink=/dev/shm
ConditionPathIsMountPoint=/run/shm
[Service]
Type=oneshot
ExecStart=/usr/bin/rm /dev/shm
ExecStart=/bin/mount --bind -o X-mount.mkdir /run/shm /dev/shm
[Install]
WantedBy=sysinit.target
That was very useful in solving a similar issue I was having in ManjaroWSL2 where systemd-tmpfiles-setup.service, systemd-tmpfiles-setup-dev.service and systemd-sysctl.service where failing causing apache and mariadb services to also fail.
I found the link to this issue here, that is also another similar issue. Additionally, in that issue a user give the following suggestion:
Before = "sysinit.targets"; should be changed to Before = [ "sysinit.target" "systemd-tmpfiles-setup-dev.service" "systemd-tmpfiles-setup.service" "systemd-sysctl.service" ], otherwise this service might run after those services in before, which causes them fail to start.
Activity
cerebrate commentedon Oct 13, 2022
I note that systemd should be mounting the tmpfs at
/dev/shmautomatically, perhttps://github.com/systemd/systemd/blob/13a5ffa4777545ca18971bf23c6dfd12f005eef2/src/shared/mount-setup.c#L79
(As I understand the history of the issue, this is a change from the pre-systemd practice which did require the symlink, and so if WSL is to also support those distributions - and indeed systemd-using distributions which aren't configured to run systemd - that'll need to be there. Perhaps creating it only if systemd != true in
/etc/wsl.confwould be viable?)cerebrate commentedon Oct 29, 2022
Apparently this is also the real underlying cause of the longstanding systemd-sysusers.service issue (reported here at #9012 for native systemd support, but a long-running issue for systemd hacks such as genie, per https://github.com/arkane-systems/genie/wiki/Systemd-units-known-to-be-problematic-under-WSL#systemd-sysusersservice ), and indeed will cause any systemd unit making use of the
LoadCredential=, etc., options to fail.(Debian sid just added systemd-sysctl.service, systemd-tmpfiles-setup-dev.service, and systemd-tmpfiles-setup.service to the list of units which make use of this, for example.)
These options require the shared memory tmpfs to be mounted at
/dev/shmwhere systemd would, on native linux, put it automatically and fail if they find a symlink there instead.I am currently working around this by creating and enabling the following systemd service (as
fixshm.service) to swap the mount and symlink into their proper-under-systemd places:(Which workaround does also resolve the private-memory snap install issue.)
NotTheDr01ds commentedon Nov 24, 2022
That's working for me, but what about a simplified version (2-steps vs. 6) using a bind-mount:
cerebrate commentedon Nov 26, 2022
No reason that wouldn't work; I only used the symlink version in the first place because that's what I was familiar with from previous experience. I've updated the server in bottle-imp 1.0 to use the bind mount, and it seems to be working fine.
NotTheDr01ds commentedon Nov 28, 2022
Ben Hillis (@benhillis) (and Alistair Young (@cerebrate)) In that case, this (and other related issues) seems resolvable by
initjust creating/dev/shmas a bind-mount rather than a symlink, right?cerebrate commentedon Nov 28, 2022
I would expect so, but I am not familiar enough with Linux deep internals to know if there're any subtle differences between a bind mount of a mount point and the original mount point that something might care about.
(I think it's very unlikely that there is, but it's easy enough to emulate the exact systemd behavior that, well, why not?)
cerebrate commentedon Nov 28, 2022
Side note: actually, in the current version of the service I make it less error-prone by moving the
/run/shmmount rather than replacing it. as per here:https://github.com/arkane-systems/bottle-imp/blob/master/binsrc/imp-executor/__main__.py#L28-L33
gfreitash commentedon Jan 19, 2023
That was very useful in solving a similar issue I was having in ManjaroWSL2 where
systemd-tmpfiles-setup.service,systemd-tmpfiles-setup-dev.serviceandsystemd-sysctl.servicewhere failing causing apache and mariadb services to also fail.I found the link to this issue here, that is also another similar issue. Additionally, in that issue a user give the following suggestion:
Might be useful for others in the future.
JGCarroll commentedon Jan 21, 2023
This is apparently fixed in the latest pre-release.
https://github.com/microsoft/WSL/releases/tag/1.1.0
Marking this issue as closed as a result.