rosswesleyporter
Hi Your link is no longer working! Can you provide a new one?
For me the following worked:
I uninstalled autofs and usbmount cause they seem to conflict to my udev rule which did the job perfectly for me. I want to mount a special USB stick (and only this stick, if it is plugged in, to start a rsync process). So I created a file in udev rules in /etc/udev/rules.d/60-usbstartscript.rules:
#Action when mounting
KERNEL=="sd[a-z][0-9]", ENV{ID_MODEL_ID}=="1a03", ENV{ID_VENDOR_ID}=="1b1c", ACTION=="add", ENV{mount_options}="relatime", RUN+="/bin/mount -o $env{mount_options} /dev/%k / myUSBdevice"
#Action when unmounting
KERNEL=="sd[a-z][0-9]", ENV{ID_MODEL_ID}=="1a03", ENV{ID_VENDOR_ID}=="1b1c", ACTION=="remove", RUN+="/bin/umount -l /myUSBdevice"
You can find out the relevant Model ID and Vendor id by typing:
$udevadm info -q all -p $(udevadm info -q path -n /dev/sdXY)
in my case /dev/sdb1
After that restart system with
$udevadm control --reload-rules &&udevadm trigger
$systemctl daemon-reload
The code here helped me:
https://askubuntu.com/questions/792362/writing-udev-rule-for-fixed-mount-point-for-hotswap-sata-devices-ubuntu-14-04
At least that worked for me!
[EDIT]:
That was not the whole solution! It turned out that commands run via RUN+= have only a short limited live and I got soon errors like "Transport endpoint is not connected” and my mount point broke before the script was run succesfully through: So I set up a systemd process which I instead started when hot plugged in:
Script in /etc/systemd/system/myUSBservice@.service
[Unit]
Description=myUSBrsync.sh to /nextCloud
[Service]
Type=simple
ExecStart=/root/myUSBrsync.sh -v %I
and in the udev rule file /etc/udev/rules.d/60-usbstartscript.rules:
KERNEL=="sd[a-z][0-9]", ENV{ID_MODEL_ID}=="1a03", ENV{ID_VENDOR_ID}=="1b1c", ACTION=="add", ENV{SYSTEMD_WANTS}="paeddasUSBStickSync@%k.service"
In the related script (myUSBrsync.sh) I do the mounting of the device using its UUID and prove if it is already mounted and then rsync all folders to the /nextcloud folder. In the end I umount the device! Now I can rsync my USB device without even connecting to the a bash remotely.
I derived that recipe from the following link and is now tested:
https://unix.stackexchange.com/questions/497266/mount-fuse-mergerfs-in-udev-script
https://yakking.branchable.com/posts/systemd-2-udevd/