-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
systemd version the issue has been seen with
244
Used distribution
Arch Linux
Expected behaviour you didn't see
See Udev rule to mount disk does not work
Many users want to add udev rules to automatically mount removable devices when attached.
However, Udev by default runs in a separate mount namespace.
The workaround should be documented somewhere easy to find.
In the above SE post, some users reported that creating an override file for the Udev service, with
[Service]
MountFlags=shared
was successful. However, this does not work for me, and another SE user reported the same.
I also tried editing the full Unit file:
# SPDX-License-Identifier: LGPL-2.1+
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=udev Kernel Device Manager
Documentation=man:systemd-udevd.service(8) man:udev(7)
DefaultDependencies=no
After=systemd-sysusers.service systemd-hwdb-update.service
Before=sysinit.target
ConditionPathIsReadWrite=/sys
[Service]
Type=notify
OOMScoreAdjust=-1000
Sockets=systemd-udevd-control.socket systemd-udevd-kernel.socket
Restart=always
RestartSec=0
ExecStart=/usr/lib/systemd/systemd-udevd
KillMode=mixed
WatchdogSec=3min
TasksMax=infinity
####
# edit 13 Mar 2019
PrivateMounts=no
MountFlags=shared
####
MemoryDenyWriteExecute=yes
RestrictRealtime=yes
RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_INET AF_INET6
SystemCallFilter=@system-service @module @raw-io
SystemCallErrorNumber=EPERM
SystemCallArchitectures=native
LockPersonality=yes
IPAddressDeny=any
I tried sudo systemctl daemon-reload, sudo systemctl restart systemd-udevd.service, and also rebooting my system. However Udev still runs in a separate namespace:
# readlink /proc/222/ns/mnt
mnt:[4026532273]
# readlink /proc/1/ns/mnt
mnt:[4026531840]
This is related to #1741 - I am trying to find a better solution for dealing with removable drives, which doesn't use /etc/fstab.
I couldn't find information in systemd.exec or systemd.unit. I will try a different solution but I think someone should comment on the above SE post, since it is the second result on Google for "udev automatically mount removable drive"; the first result is a blog post which also describes a non-working solution. Of interest is also how to debug the non-working situation, e.g. what is the path a user should take to figure out why the supplied PrivateMounts and MountFlags directives are not having an effect.
Thank you!