I want to go beyond this excellent solution by @A.B. which permits to auto-mount a given removable ext3 FS using a udev rule. Specifically I'd like to specify several mount options: "nodev,noexec,x-gvfs-show", preferably within the specific udev rule used to mount it, since it deals with one very specific physical medium.
With no option specified, the volume mounts so:
$ cat /proc/mounts | grep -e MYLABEL
/dev/mmcblk0p1 /mnt/MYLABEL ext3 rw,relatime,data=ordered 0 0
To specify mount options I tried to expand the udev rule from the previous solution so:
KERNEL=="mmc*", ENV{ID_FS_UUID}=="______", RUN+="/usr/local/sbin/mount_by.sh '%E{ID_FS_LABEL}' '%E{ID_FS_UUID}' 'nodev,noexec,x-gvfs-show'"
where /usr/local/sbin/mount_by.sh includes:
#!/bin/sh
/bin/mount "/dev/disk/by-uuid/$2" "/mnt/$1" -o "$3"
The above breaks quietly as root defined mount options seem to be rejected and the volume (an SD card) is silently mounted at /media/MYUSER/MYLABEL.
What's wrong ?
What I tried to do:
The many posts I have seen dealing with mount-option(s) specification difficulties when using udev (e.g. 1,2,...) remain unanswered.
One deals with the GVFS option x-gvfs-show used in conjunction with udev rules, when the mounted volume must appear under Devices on the Nautilus GUI and the non-root user must be able to unmount it. To at least get that last aspect covered, I reverted to NOT specifying mount option in my udev rules but added an /etc/fstab entry, a pretty ugly hack given the fact I keep a functioning udev rule for the same uuid volume in parallel. Still, I added :
UUID=_________ /mnt/MYLABEL ext3 nodev,noexec,x-gvfs-show 0 2
The FS is mounted but although it appears as intended in Nautilus, cat /proc/mounts | grep -e MYLABEL yields the same result as before... i.e. options nodev,noexec appear to be blithely ignored.
Not too surprisingly I also get the error message on screen:
Unable to mount MYLABEL. Device /dev/mmcblk0p1 is already mounted at `/mnt/MYLABEL'.
Any thought anyone ?
BOUNTY Please try to provide a canonical answer that can serve this OP and the whole lot of people interested in specifying mount-options via a udev rule. If not possible, please explain why and provide a viable workaround. Cheers.