You are not logged in.

#1 2014-03-29 20:50:53

rwilson
Member
Registered: 2013-10-15
Posts: 19

Mounting sd card to specific folder

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

#2 2014-03-29 20:57:49

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,514
Website

Re: Mounting sd card to specific folder


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2014-03-29 20:58:34

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Mounting sd card to specific folder

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

#4 2014-03-29 23:11:00

rwilson
Member
Registered: 2013-10-15
Posts: 19

Re: Mounting sd card to specific folder

@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

#5 2014-03-29 23:20:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,514
Website

Re: Mounting sd card to specific folder

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

#6 2014-03-30 09:54:35

rwilson
Member
Registered: 2013-10-15
Posts: 19

Re: Mounting sd card to specific folder

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

#7 2014-03-30 10:07:06

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,732
Website

Re: Mounting sd card to specific folder

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)

Offline

#8 2014-03-30 10:22:27

rwilson
Member
Registered: 2013-10-15
Posts: 19

Re: Mounting sd card to specific folder

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

#9 2014-03-30 13:56:41

rwilson
Member
Registered: 2013-10-15
Posts: 19

Re: Mounting sd card to specific folder

@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

#10 2014-03-30 17:08:05

rwilson
Member
Registered: 2013-10-15
Posts: 19

Re: Mounting sd card to specific folder

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

#11 2014-03-30 18:05:37

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Mounting sd card to specific folder

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

#12 2014-03-30 19:58:49

rwilson
Member
Registered: 2013-10-15
Posts: 19

Re: Mounting sd card to specific folder

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

#13 2014-03-30 20:11:06

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,732
Website

Re: Mounting sd card to specific folder

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... wink

Offline

#14 2014-03-30 20:32:09

deepsoul
Member
From: Earth
Registered: 2012-12-23
Posts: 67
Website

Re: Mounting sd card to specific folder

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

#15 2014-03-30 21:18:20

deepsoul
Member
From: Earth
Registered: 2012-12-23
Posts: 67
Website

Re: Mounting sd card to specific folder

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

#16 2014-03-30 22:09:33

rwilson
Member
Registered: 2013-10-15
Posts: 19

Re: Mounting sd card to specific folder

@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

#17 2014-03-30 22:37:54

rwilson
Member
Registered: 2013-10-15
Posts: 19

Re: Mounting sd card to specific folder

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

Board footer

Powered by FluxBB