You are not logged in.
I created a udev rule where I mount at the desired location an SD card as shown below:
# ACTION=="add", ENV{ID_FS_UUID}=="e9d6401a-a66b-45f9-881e-5239e7a77f10", RUN+="/bin/umount /run/media/cedric/sd_128go"
# ACTION=="add", ENV{ID_FS_UUID}=="e9d6401a-a66b-45f9-881e-5239e7a77f10", RUN+="/bin/mount /dev/mmcblk0p1 /mnt/sd_128go/"
# ACTION=="add", ENV{ID_FS_UUID}=="e9d6401a-a66b-45f9-881e-5239e7a77f10", RUN+="/bin/mount --bind /mnt/sd_128go/Musique /home/cedric/Musique"
# ACTION=="remove", ENV{ID_FS_UUID}=="e9d6401a-a66b-45f9-881e-5239e7a77f10", RUN+="/bin/umount /home/cedric/Musique"
# ACTION=="remove", ENV{ID_FS_UUID}=="e9d6401a-a66b-45f9-881e-5239e7a77f10", RUN+="/bin/umount /mnt/sd_128go"
Since not a long time ago, I realized that it was not working anymore and the sd card was not mounted automatically. So I tried to look for another solution. While looking I read that using mount in a udev rule is not a good idea.
Do you know of any solutions to this problem? Why the previous solution does not work? Is these another solution?
Thanks
Last edited by rwilson (2014-03-29 22:19:10)
Offline
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Have you treid using fstab?
When posting configs, code or command output, please use [ code ] tags https://bbs.archlinux.org/help.php#bbcode
like this
It makes the code more readable and - in case of longer listings - more convenient to scroll through.
Last edited by karol (2014-03-29 21:00:53)
Offline
@Trilby: I have seen that and tried but I can not change the mounting directory.
@karol: No I haven't, what should I do? Thanks for the tip on the formatting.
Offline
What have you tried? I linked to an article with at least half a dozen different options to do what you were requesting. Which ones have you tried, what specifically did you do, and what went wrong?
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I have tried udiskie, ldm and udevil. I did not succeed to get ldm and udevil to work but I did for udiskie.
With udiskie, when I put the SD card, it is automatically mounted as expected.
In general I haven't seen any options to select the folder where to mount the drive depending on the UUID. The only solution I found was to use a udev rule as shown before.
There is something that I don't understand: why isn't my computer triggering automatically the udev rules anymore?
Offline
The udev "RUN+=" command only works for very short-running foreground events, see @jasonwryan's blog for more on this...
Last edited by Head_on_a_Stick (2014-03-30 10:07:39)
Freedom for Öcalan!
Offline
Thank you Head_on_a_stick. I don't see how to manage unmounting the device. Do you have some info on it?
Last edited by rwilson (2014-03-30 12:02:44)
Offline
@Karol
I tried fstab and I can get it to mount where I want but it hangs for the sd card during boot.
Is there a way that the boot process continues without the mounting the sd card until it is ready?
Offline
I have made some progress.
1) I have set-up the partition options in fstab and it does not hang during boot.
/mnt/sd_128go/Musique /home/cedric/Musique none bind,user,noauto 0 0
UUID=e9d6401a-a66b-45f9-881e-5239e7a77f10 /mnt/sd_128go ext4 noatime,nodiratime,user,exec,noauto 0 0
2) I have created a udev rule that calls a script:
ACTION=="add", ENV{ID_FS_UUID}=="e9d6401a-a66b-45f9-881e-5239e7a77f10", RUN+="/usr/local/sbin/udev-auto-mount.sh %k"
ACTION=="remove", ENV{ID_FS_UUID}=="e9d6401a-a66b-45f9-881e-5239e7a77f10", RUN+="/usr/local/sbin/udev-auto-umount.sh %k"
I have tested the scripts and they do not require super privileges to mount the partition and folders. They have been set as executables
3) If I test the rule it is fine
# sudo udevadm test --action=add /sys/block/mmcblk0/mmcblk0p1
...
run: '/usr/local/sbin/udev-auto-mount.sh mmcblk0p1'
...
However, nothing happens when I plug in the sd card.
Offline
You cannot mount filesystems from udev rules. Period. The final nail in the coffin was in systemd 212, with this commit:
http://cgit.freedesktop.org/systemd/sys … 42e0691aec
Effectively, mounting takes place, but in a separate namespace which you will never see as a user.
Last edited by falconindy (2014-03-30 18:05:53)
Offline
OK, thanks falconindy. That make complete sense with what I have found out by myself. It would explain why my rules did not work any more.
Do you know of any way to do what I want to do?
* Mount an SD card with specific UUID in a specific folder
* Mount a folder of this SD card in another folder
Offline
Sorry @rwilson I don't really know anything about udev scripting, I just have an eidetic memory & I read @jasonwryan's blog a few weeks ago...
Freedom for Öcalan!
Offline
Falconindy, thank you for your post. I have also seen "strange effects" (no mount showing in /proc/mounts but inability to rmdir mount point) since systemd 212 which your remark explains. Do you by any chance know the reason behind this change, or can link to a discussion?
A related question: Is there a toolset for inspecting/administrating namespaces, or something in /proc or /sys? This LWN article presents some small programs, but is there a canonical toolset yet?
@rwilson: The usual answer would be to use one of the automounters from the udisks wiki page. But like you, I also found them not flexible enough for my taste. A way around dealing with udev at all might be to run a background process that watches /proc/partitions and mounts when a certain device becomes available. Even better would be a way to make udev trigger a script / program running in the main namespace. I am going to look into that, but at the moment I do not know enough about namespaces to do that.
Officer, I had to drive home - I was way too drunk to teleport!
Offline
rwilson, I have a workaround for you. The cause of the trouble is that systemd's udev daemon runs in a different namespace from the rest of the system from which new mounts do not propagate back. This is configured by the following line in /usr/lib/systemd/system/systemd-udevd.service:
MountFlags=slave
To change this, copy this file to /etc/systemd/system/ , remove this line in the copy and reboot the system. Your mount script should work as before. (Mine did.)
Obvious risk: If /usr/lib/systemd/system/systemd-udevd.service is updated, the one in /etc will still be used, so check for changes after every systemd update, before rebooting.
Less obvious risk: The systemd folks seem to think running mounts from udev is a Bad Thing(TM), though I have not yet seen anyone give a reason. If they are right, you (and I) may be in trouble at some point in the future.
PS: If you want to mount FUSE-based filesystems like NTFS, your script has to quit the control group in which udev puts it in order to avoid getting killed prematurely:
echo $$ > /sys/fs/cgroup/systemd/tasks
Officer, I had to drive home - I was way too drunk to teleport!
Offline
@deepsoul: Thank you for your quick workaround and the inherent limitations.
A neat solution would be to fork an automounting soft and add configuration files depending on UUIDs and other parameters. What do you think?
Offline
After having a look into ldm source code, it does not seem too complicated to add the possibility to run a command after a specific file system has been run. The "device" is created at line 332 from https://github.com/LemonBoy/ldm/blob/master/ldm.c.
The conf file could be a list with this format:
UUID "path to command file"
I don't know how to import such a list from a .conf file and then look through it to find the correct correspondance.
Last edited by rwilson (2014-03-30 22:47:31)
Offline