[systemd-devel] Launch a mount unit from udev rule via ENV{SYSTEMD_WANTS}

Leon Fauster leonfauster at googlemail.com
Thu Feb 16 12:08:55 UTC 2023


Am 16.02.23 um 11:17 schrieb Lennart Poettering:
> On Mi, 15.02.23 17:59, Jacopo (fingolfin00 at gmail.com) wrote:
> 
>> udev rule:
>> ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*", SUBSYSTEMS=="usb",
>> ENV{DEVTYPE}=="partition", IMPORT{builtin}="blkid",
>> ENV{ID_FS_TYPE}=="ext4", ENV{ID_FS_LABEL_ENC}=="data-ssd",
>> ENV{SYSTEMD_WANTS}+="dummy.service"
> 
> Matching against "add" is almost certainly wrong, as devices typically
> see "change" and other events throughout their early lifetime, and in
> that case any settings you make here would get very quickly lost.
> 
> In almost all cases you want a check like ACTION!="remove" instead
> which matches all "positive" events and ignores the only negative
> event.


This is an interestring thread - I have here an old implementation
of an automount (luks/externaldevice), that also uses udev as follows:

SUBSYSTEM=="block", \
ENV{ID_FS_TYPE}=="crypto_LUKS", \
ENV{DEVTYPE}=="partition", \
ATTR{partition}=="1", \
ENV{ID_SERIAL}==" {{LONGSERIAL}} ", \
ACTION=="add|change", SYMLINK+="backup/usbhd5", \
RUN+="/usr/bin/systemctl start backup@%E{ACTION}"


The actions are handled in the script that the
unit starts, decryption / mounting also. The mount
point is in this case namespaced, that already bothered me.
Maybe I should revised this solution to be future save.
So, ENV{SYSTEMD_WANTS} is the way to go?

--
Leon




More information about the systemd-devel mailing list