Using udev tools I know nearly every things about my usb stick.
With udev rule, I can tell when a specific usb stick is inserted or remove using its id ( ex : usb-Multiple_Card_Reader_058F63666438-0:0-part1 ).
I have not found myself a rule to tell when it is really mounted ( files and folders are accessible ).
I need that rule to trigger a systemd service of mine.
For example, I have a memory stick labelled T9I11A (vfat filesystem). When it is mounted via udisks (desktop-mounting), the above command will report
run-media-dean-T9I11A.mount loaded active mounted /run/media/dean/T9I11A
and of course it will be reported via ‘mount’ command like this
/dev/sdb1 on /run/media/dean/T9I11A type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=100,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)
I could write a custom unit (/etc/systemd/system/mount-trigger.service) like this
Thank you for your quick answer.
I have tried already something like that (Failed to run) but in addition the problem is that is user dependent.
I look something just hardware dependent or if I can use a variable to replace (in your example) dean by $(logname).
I have tried to use ( in systemd notation ) dev-disk-by-uuid-12BD3AE67CF89 in WantedBy,Requires et After but I got syntax error.
Do you have any ideas that I can develop?
By the way, can you tell me where is(are) the rules(s) which tell udisks2 to mount usb disks in ‘/run/media/$USER/LABEL_OF_THE_USB_DISK’.
I have not found any config file(s) mentioned in man udisks
I have also search for the string ‘UDISKS_FILESYSTEM_SHARED’ in /etc and /usr and not found any place.
Any help is welcome
The udisks2 rules file is /usr/lib/udev/rules.d/80-udisks2.rules (the mounting location is handled within udisks2 code)
If set to 1, the filesystem on the device will be mounted in a shared directory (e.g. /media/VolumeName) instead of a
private directory (e.g. /run/media/$USER/VolumeName) when the Filesystem.Mount() method is handled.
I buy a GARMIN device and add it to /etc/fstab once. Whenever I plug it into USB the GARMIN gets mounted and new GPX data are transferred automatically. After a few years the drive has become obsolete. I buy a new one and fix the UUID in /etc/fstab. Any shorter and simpler procedure available?
I think you’ve missed the whole point of this thread. The OP is wanting to detect a particular ‘auto-mounted’ removable device. However, they also didn’t want it to be user-specific. The udev rule was ONLY used to cause the ‘shared’ removable device to then be mounted to ‘/media/…’. To clarify further, it does not do the mounting - that is done by the desktop environment.
During one of my tests I use this configuration :
( Don’t pay attention to the file name of unit.path and unit.service. I have use the same files for different criteria)
USB LABEL : ‘BESTRUNNER-8Go-14’
FILE 1 : THIS_IS_THE_TRIGGER_FILE.txt
Location : on the usb stick : /run/media/user_install/BESTRUNNER-8Go-14
Each time it is modified then saved, it is suppose to trigger my systemd unit.
FILE 2 : trigger.sh
Location : in home user : /home/user_install/bin
Activated each time the unit.service is triggered : write text to a tmp file
/usr/bin/date >> /tmp/udev.log
FILE 3 : USB_TEST_is_mounted.path
Location : /etc/systemd/system
Activate the configured unit paired whenever a change occured, when the file which was open for writing gets closed.
Description=Trigger the systemd unit paired when the monitored file have changed : THIS_IS_THE_TRIGGER_FILE.txt
FILE 4 : USB_TEST_is_mounted.service
Location : /etc/systemd/system
This unit is triggered by the paired unit.path
Description=Executes script when 'THIS_IS_THE_TRIGGER_FILE.txt' has changed.
This works as the documentation indicates, with one detail: after about ten tests, the name of the mountpoint has changed.
Normally I got ‘/run/media/user_install/BESTRUNNER-8Go-14/…/…’. But after a while I got ‘/run/media/user_install/BESTRUNNER-8Go-141/…/…’ or ‘/run/media/user_install/BESTRUNNER-8Go-142/…/…’
Even after multiple reboot.
That mean that under certain circumstances, we could not rely on /run/media/$USER/USB_LABEL/…/…