12

I have the following content in in /etc/udev/rules.d/81-external-disk.rules:

ENV{ID_FS_UUID}=="6826692e-79f4-4423-8467-cef4d5e840c5", RUN{program}+="/bin/mount -o nofail,x-systemd.device-timeout=1 -t ext4 -U 6826692e-79f4-4423-8467-cef4d5e840c5 /backup/external"

After running:

udevadm control --reload ; udevadm trigger /dev/sdb1

It does nothing at all. However if II change the mount command for something such as /bin/touch /tmp/xyz it works.

Versions:

[root@helsinki rules.d]# rpm -qa | grep udev
libgudev1-219-19.el7_2.12.x86_64
python-pyudev-0.15-7.el7_2.1.noarch
[root@helsinki rules.d]# rpm -qa | grep systemd
systemd-libs-219-19.el7_2.12.x86_64
systemd-219-19.el7_2.12.x86_64
systemd-sysv-219-19.el7_2.12.x86_64
[root@helsinki rules.d]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

2 Answers 2

21

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.

3
  • Yes I've applied such a workaround, I wonder if has security implications too.
    – sebelk
    Dec 13, 2016 at 19:52
  • 1
    Pretty sure this did not work until I added [Service] between those two lines.
    – goldilocks
    Oct 15, 2017 at 23:10
  • 1
    @goldilocks You are probably right. I added this to the answer, thanks. It might depend on what the last section was in the included file, but it seems systemd now prefers you to use the *.d/*.conf way of making changes, as .include doesnt seem to be documented.
    – meuh
    Oct 16, 2017 at 7:54
19

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
4
  • It worked like a charm on Raspberry (Raspbian 9 "stretch"). Thanks! Oct 24, 2018 at 19:07
  • 2
    It did not work for my Ubuntu 18.04 to solve the problem of no automount for USB drive.
    – Yu Shen
    Jan 12, 2019 at 15:41
  • Worked in Ubuntu 18.04. @YuShen, you might want to check your udev rules.
    – Greg Bell
    Feb 15, 2020 at 1:54
  • 1
    On Ubuntu 20.04, this didn't work for me. Changing MountFlags=shared to PrivateMounts=no did.
    – Mikel
    Jun 23, 2020 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.