[systemd-devel] Antw: [EXT] Launch a mount unit from udev rule via ENV{SYSTEMD_WANTS}
Ulrich Windl
Ulrich.Windl at rz.uni-regensburg.de
Thu Feb 16 07:39:04 UTC 2023
>>> Jacopo <fingolfin00 at gmail.com> schrieb am 15.02.2023 um 17:59 in Nachricht
<CAO-AGAuKP=BvtTfGOpCcePGaZAiqzcA9+exi0V-rSYkLNMLohg at mail.gmail.com>:
> I'be been having issues lately trying to automatically remount an external
> USB drive that is mounted at boot from an fstab entry:
> LABEL=data-ssd /opt/data-ssd ext4 defaults,nofail,users 0 2
>
> I'm using systemd 244 and after some investigation I learned about the
> possibility to launch a systemd unit from a udev rule via
> ENV{SYSTEMD_WANTS} (see here
> https://github.com/systemd/systemd/issues/22589#issuecomment-1047940003 and
> https://github.com/systemd/systemd/pull/11373#issuecomment-594014841)
>
> In particular the second suggestion is exactly what I need, but the only
> way I could make it work was launching a dummy.service that "Wants" the
> corresponding mount unit:
>
> udev rule:
> ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*", SUBSYSTEMS=="usb",
And is your SSD really a "sd*" device?
> ENV{DEVTYPE}=="partition", IMPORT{builtin}="blkid",
> ENV{ID_FS_TYPE}=="ext4", ENV{ID_FS_LABEL_ENC}=="data-ssd",
> ENV{SYSTEMD_WANTS}+="dummy.service"
>
> dummy.service:
> [Unit]
> Description=Dummy service
> Wants=opt-data\x2dssd.mount
>
> [Service]
> Type=simple
> ExecStart=/bin/echo "I'm dummy"
>
> [Install]
> WantedBy=local-fs.target
>
> I also tested using ACTION!="remove" in the udev rule, but same result.
>
> As I mentioned in the github issue before being redirected here, if I query
> with udevadm, ENV{SYSTEMD_WANTS} is printed out only with in the
> non-working case (.mount unit launched directly from the udev rule):
>
> # udevadm info --query=property --path=/sys/class/block/sda1
> [...]
> SYSTEMD_WANTS=opt-data\x2dssd.mount
> [...]
>
> whereas it disappears if launching the dummy.service first.
>
> Thanks
More information about the systemd-devel
mailing list