1

This question already has an answer here:

I'm trying to automount a USB device upon plugin but it refuses to mount. I set a rule to execute the following script :

#!/bin/bash
mkdir /media/mnt
echo AFTER MKDIR > /home/output
sleep 5
echo AFTER SLEEP >> /home/output
mount /dev/sdb1 /media/mnt
echo $? >> /home/output
echo AFTER MOUNT >> /home/output

The script gets executed nicely, lsblk shows that /dev/sdb1 is present, output contain all the echoes, yet sdb1 won't be mounted in /media/mnt. The mount command exit code is 0

When I execute the mount command in that script manually after the USB device is plugged in it mounts it without problem.

marked as duplicate by sourcejedi, elbarna, jimmij, Archemar, Mr Shunz Jan 31 at 11:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Where did you set that rule? Is it run by root? Perhaps adding a line in your script to validate the effective UID might be a good idea: id >> /home/output – Julie Pelletier Jul 31 '16 at 18:10
  • @JuliePelletier in /etc/udev/rules.d both the script and the rule where made by root. id returns root – ChiseledAbs Jul 31 '16 at 18:30
  • 1
    Are you using systemd? – meuh Jul 31 '16 at 18:31
  • @meuh no I'm using udev that calls the script in OP – ChiseledAbs Jul 31 '16 at 18:35
  • But is your archlinux configured to use systemd for most things? – meuh Jul 31 '16 at 18:36
2

Had to add MountFlags=shared in /usr/lib/systemd/system/systemd-udevd.service, whatever this is. See mount is not executed when called by udev

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