In Debian Wheezy I had a special rule for my ntfs usb hdd. When it is inserted it is mounted in /media under a specific sub-folder.
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{serial}=="<serial_number>", SYMLINK+="mx%n"
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{serial}=="<serial_number>", RUN+="/bin/mount <options>", OPTIONS="last_rule"
ACTION=="remove", SUBSYSTEMS=="usb", ATTRS{serial}=="<serial_number>", RUN+="/bin/umount <options>"
Ufter I updated to Jessie it stopped working. I found out that after changes in udev you cannot use mount and it is recommended to use either udisks2 or some self-written systemd unit. I chose udisks2 and rewrote rule as follows
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{serial}=="<serial_number>", SYMLINK+="mx%n"
ACTION=="add", SUBSYSTEMS=="usb", ATTRS{serial}=="<serial_number>", RUN+="/bin/su storage_user -c '/usr/bin/udisksctl mount --block-device /dev/mx1 --filesystem-type ntfs --options locale=en_IE.UTF-8,fmask=0113,dmask=0002 --no-user-interaction'", OPTIONS="last_rule"
ACTION=="remove", SUBSYSTEMS=="usb", ATTRS{serial}=="<serial_number>", RUN+="/usr/bin/udisksctl unmount --block-device /dev/mx1 --no-user-interaction"
It doesn't work. In syslog I see:
Error looking up object for device /dev/mx1
But if I run this command from cli it works fine. I believe because of the asynchronous nature of systemd services /dev/mx1 is not ready when udisk2 is trying to mount usb hdd.
- What rule should I write instead?
- Is there any good guide on Internet how to write custom automounting rules especially for ntfs file systems?
udisksctl mount -b /foo/bar
. Probably the special rule is triggerd too early