1

I understand, that there are a lot of topics, however this is not still clear to me.

First of all, i have systemd service, script and udev rule which are run when USB-device connected. This works as expected.

[Unit]
After=run-media-serg-GARMIN.mount
Description=Backup garmin activities when Garmin 830 is connected
Requires=run-media-serg-GARMIN.mount

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/ckkhm153z75sw6z5nr277kvn2pi4z8jy-glibc-locales-2.35-224/lib/locale/locale-archive"
Environment="PATH=/nix/store/l6jgwxkc3jhr029vfzfwzcy28iyckwsj-coreutils-9.1/bin:/nix/store/gn1s1s5z19cf0wiir2cd38jckcjc6kn6-findutils-4.9.0/bin:/nix/store/pvb117r7fhwb08717ks21a6y9hlnp63b-gnugrep-3.7/bin:/nix/store/v0hg83sdv4v51c0prmdigry6wdmmpzmp-gnused-4.8/bin:/nix/store/jnrdsg66spsm9n9amz5lspigdds7nrmf-systemd-251.16/bin:/nix/store/l6jgwxkc3jhr029vfzfwzcy28iyckwsj-coreutils-9.1/sbin:/nix/store/gn1s1s5z19cf0wiir2cd38jckcjc6kn6-findutils-4.9.0/sbin:/nix/store/pvb117r7fhwb08717ks21a6y9hlnp63b-gnugrep-3.7/sbin:/nix/store/v0hg83sdv4v51c0prmdigry6wdmmpzmp-gnused-4.8/sbin:/nix/store/jnrdsg66spsm9n9amz5lspigdds7nrmf-systemd-251.16/sbin"
Environment="TZDIR=/nix/store/z0kg1c0f8fx6r4rgg5bdy01lb2b9izqg-tzdata-2023a/share/zoneinfo"


ExecStart=/nix/store/fqr3f89hajwb0s5s50kd72jp8a93xipm-garmin-backup/bin/garmin-backup
Type=forking
ACTION=="change", SUBSYSTEM=="block",
        ENV{ID_VENDOR_ID}=="091e", ENV{ID_MODEL_ID}=="2c32", ENV{ID_SERIAL}=="Garmin_GARMIN_Flash-0:0",
    ENV{SYSTEMD_WANTS}=="${garminService}.service"

But what i don't really like, that mountpoints are hardcoded, for example "after" and "requires" lines in systemd service depends on my current user name. And i can not be sure that mountpoint will always exactly same in another Desktop Environment.

One of my ideas of solving this problem, are:

  1. Disable automounting in udev rule
  2. Create systemd mount service which will always mount on same location.

But maybe there is a more simple solution. Can you help me, please?

1 Answer 1

1

Create an /etc/fstab entry for the USB device (referencing it through LABEL= as you currently rely on its filesystem label anyway, or referencing it through /dev/disk/by-id or similar). When UDisks2 mounts a removable device it will use the fstab configuration over the default. (It will not, however, care about systemd .mount units at all.)

The /run/media paths are not DE-specific as far as the DE uses UDisks2 to perform privileged operations. It is possible to mark a device as "shared" for UDisks2 through an udev property as documented in udisks(8) – setting ENV{UDISKS_FILESYSTEM_SHARED} to 1 on the block device will cause UDisks2 to always mount it at /media/LABEL instead of a per-user path.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .