0

So I have the UDEV rule:

ACTION=="add", SUBSYSTEMS=="block", KERNEL=="sd[a-z]1", RUN+="/usr/local/bin/script.sh"

This is saved in /etc/udev/rules.d/10-usb.rules

I want it to trigger the script when any USB key is attached.

I am testing with 3 different USB sticks.

Without the UDEV rule in place (well a blank 10-usb.rules file), the USB auto mounts fine.

With the UDEV rule in place (I use udevadm control --reload then udevadm trigger at each change), the script triggers (in the script I have some files being copied first on the Pi, before over to the USB) but the USB doesn't mount properly, hence messing up the file transfer.

Looking with tail -f /var/log/messages I can see the USB being attached, but it stays greyed out in the top right corner of the Pi (eject devices).

Any ideas as to why the mounting issue comes into play when the UDEV rule is in place?

  • Not Pi specific. You will almost certainly get a better quality response if you find a more appropriate site for the question. – joan Jul 18 '18 at 11:34
0

I suppose the USB automount on your system also happens via UDEV rules (typically /etc/udev/rules.d/80-udisks2.rules or a similar file in /usr/lib/udev/). Since your script relies on the drive already being mounted, you could try to make sure your rule executes after udisks. I would start with renaming your UDEV rule file to /etc/udev/rules.d/99-usb.rules and checking whether that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.