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%nACTION==add, SUBSYSTEMS==usb, ATTRS{serial}==<serial_number>, RUN+=/bin/mount <options>, OPTIONS=last_ruleACTION==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 followsACTION==add, SUBSYSTEMS==usb, ATTRS{serial}==<serial_number>, SYMLINK+=mx%nACTION==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_ruleACTION==remove, SUBSYSTEMS==usb, ATTRS{serial}==<serial_number>, RUN+=/usr/bin/udisksctl unmount --block-device /dev/mx1 --no-user-interactionIt doesn't work. In syslog I see:Error looking up object for device /dev/mx1But 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?
udev+udisks2: udisksctl gives 'Error looking up object for device'
debian;udev;ntfs;automounting;udisks
Unfortunately I wasn't able to find the reason why udev and udisks2 didn't work together. But I found a solution for my problem here. Below is a simple example how to implement automount of a ntfs usb hdd. First is a script mount.sh to mount a drive#!/bin/bashmkdir -p /media/usbhddmount -t ntfs-3g -o locale=en_IE.UTF-8,fmask=0113,dmask=0002,uid=storage-user,gid=storage-group /dev/mx1 /media/usbhddThen we create a systemd unit in /etc/systemd/system/mount-hdd.service[Unit]Description=mount usb hdd[Service]Type=forkingExecStart=/usr/local/scripts/storage/mount.sh[Install]WantedBy=multi-user.targetAnd finally udev ruleACTION==add, SUBSYSTEMS==usb, KERNEL==sd*, ATTRS{serial}==<serial_number>, SYMLINK+=mx%nACTION==add, SUBSYSTEMS==usb, KERNEL==sd*1, ATTRS{serial}==<serial_number>, RUN+=/bin/systemctl start mount-hddACTION==remove, SUBSYSTEMS==usb, ATTRS{serial}==<serial_number>, RUN+=/bin/umount /media/usbhdd, RUN+=/bin/rmdir /media/usbhdd