Udev rule to mount disk does not work

This is a systemd feature. The original udev command has been replaced by systemd-udevd (see its man page). One of the differences is that it creates its own filesystem namespace, so your mount is done, but it is not visible in the principal namespace. (You can check this by doing systemctl status systemd-udevd to get the Main PID of the service, then looking through the contents of /proc/<pid>/mountinfo for your filesystem).

If you want to go back to having a shared instead of private filesystem namespace, then create a file /etc/systemd/system/systemd-udevd.service with contents

.include /usr/lib/systemd/system/systemd-udevd.service
[Service]
MountFlags=shared 

or a new directory and file /etc/systemd/system/systemd-udevd.service.d/myoverride.conf with just the last 2 lines, i.e.

[Service]
MountFlags=shared

and restart the systemd-udevd service. I haven't found the implications of doing this.


This same problem occurs in Ubuntu 18.04 with the same underlying cause. To fix it we create an override file for systemd-udevd:

sudo systemctl edit systemd-udevd

And insert into it:

[Service]
MountFlags=shared

(on Ubuntu 20.04, replace MountFlags=shared with PrivateMounts=no.)

Save the file and then execute:

sudo systemctl daemon-reload
sudo service systemd-udevd --full-restart

Tags:

Mount

Udev