0

In Gentoo I had created a small script that was called by udev and allowed me to mount an USB device, identified by its serial number, to any mount point I chose.

Basically, /etc/udev/rules.d/00-removable.rules contains

SUBSYSTEM=="block", ACTION=="add", KERNEL=="sd[b-z]*", RUN+="/usr/local/bin/mountRemovableMedia.sh %k"

and my mountRemovableMedia.sh script uses the device parameter passed to determine the device serial, and then mount it to the mount point I want.

Now, in F21, with systemd, it doesn't work. The script is called (I have a log file written to by the script), the mount command is performed (returns 0, no error), but the actual mount doesn't happen: if I type 'mount' in a terminal, I can't see the device, and if I cd to its mountpoint the directory is empty.

I tried changing mount to udisksctl mount --block-device ... but it still doesn't work.

0

I have had the same problem with a script that worked fine in Fedora 20 and earlier. I think the reason why this does not work any more in Fedora 21 is that udev runs the script with a private mount namespace, although I have not confirmed this.

The workaround I have come up with is the following: Instead of executing the script with udev, I now execute it via a systemd unit.

In detail, I created the following systemd unit file as /etc/systemd/system/mount_device.service:

[Unit]
After=dev-[UUID].device

[Service]
ExecStart=/etc/systemd/scripts/mount_device.sh

[Install]
WantedBy=dev-[UUID].device

where the correct dev-[UUID].device has to be replaced by the right systemd device ID, which can be determined using systemctl --all --full -t device. The unit needs to be enabled by running systemctl enable mount_device.service.

If the script is executed in this way, the mount shows up as expected. The only drawback is that it only works if you know the UUID, label or similar in advance, which might not apply in your case.

  • too bad there is no such thing as /etc/systemd/scripts/mount_device.sh on Debian :( – malat Mar 3 '15 at 20:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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