WSL: snaps with private shared memory support enabled don't install
Also, a solution to an old problem.
So, I saw this bug report, concerning this snapd feature, and naturally I had to poke the issue.
Eh, that’s not entirely true.
I made a note to poke the issue at some future time, and then accidentally resolved in when dealing with a different problem. See, way back in the day, genie had a certain issue in which the systemd-sysusers.service wouldn’t start properly - detailed here in the documentation. And with the able assistance of a genie user, we found a cause, we found a workaround, and we moved on.
Until today, when I noted that some recent Debian updated had added the problematic LoadCredential= lines to several other systemd units (systemd-sysctl.service, systemd-tmpfiles-setup-dev.service, and systemd-tmpfiles-setup.service). And motivated by suddenly having four failing services instead of one, I went for another look into the problem.
It turns out that for LoadCredential= and the other credential options to work properly, the private shared memory filesystem has to be mounted where systemd would mount it, which is to say, at /dev/shm. Unfortunately, WSL currently mounts that filesystem at /run/shm, and symlinks to it from /dev/shm, which means that any units using these options won’t run properly. And creates that problem for snapd mentioned up at the top, because it too expects /dev/shm to be the mount point.
And the workaround?
This systemd services, added and enabled:
[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 quickly swaps the mount point and the symlink to their respective correct places when running under system, before anything that might use /dev/shm starts up, and then everything works.
(This will be going into bottle-imp 0.10, shipping in the next day or so, so if you use bottle-imp, you might as well wait for it. Otherwise, don’t forget to remove your version of the service before bottle-imp installs its version.)