<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno gio 16 feb 2023 alle ore 11:17 Lennart Poettering <<a href="mailto:lennart@poettering.net" target="_blank">lennart@poettering.net</a>> ha scritto:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Matching against "add" is almost certainly wrong, as devices typically<br>
see "change" and other events throughout their early lifetime, and in<br>
that case any settings you make here would get very quickly lost.<br>
<br>
In almost all cases you want a check like ACTION!="remove" instead<br>
which matches all "positive" events and ignores the only negative<br>
event.<br></blockquote><div><br></div><div>I updated my udev rule according to your suggestion, but I don't see a different behaviour, still I'll adopt your recommendation in the future.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
This is almost certainly an escaping issue.  What's the precisely rule<br>
you are using? It's generally a good idea to start with the line that<br>
doesn't work, not the one that works.<br></blockquote><div><br></div><div>Yes! That was a good point. Removed the minus sign (-) from the mount point (/opt/data-ssd --> /opt/data) and now it works.</div><div>Is it a forbidden character in systemd mount points?<br></div><div><br></div><div>Working setup, which means the drive is mounted at boot and if I unplug and then plug in the USB drive at runtime it gets automatically mounted.</div><div>- FS label:</div><div>   $ e2label /dev/sda1<br>      data</div><div>- udev rule:<br>  ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sd*", SUBSYSTEMS=="usb", ENV{DEVTYPE}=="partition", IMPORT{builtin}="blkid", ENV{ID_FS_TYPE}=="ext4", ENV{ID_FS_LABEL_ENC}=="data", ENV{SYSTEMD_WANTS}+="opt-data.mount"</div><div>- fstab entry:</div><div>  LABEL=data  /opt/data  ext4  defaults,nofail,users  0  2</div><div><br></div><div>Also working setup.</div><div>- FS label:</div><div>   $ e2label /dev/sda1<br>      data-ssd</div><div>- udev rule:</div><div>  ACTION!="remove", 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}+="opt-data.mount</div><div>- fstab entry:</div><div>  LABEL=data-ssd  /opt/data  ext4  defaults,nofail,users  0  2</div><div><br></div><div>But not working.</div><div>- FS label:</div><div>  $ e2label /dev/sda1<br>     data</div><div>- udev rule:</div><div>  ACTION!="remove", SUBSYSTEM=="block", KERNEL=="sd*", SUBSYSTEMS=="usb", ENV{DEVTYPE}=="partition", IMPORT{builtin}="blkid", ENV{ID_FS_TYPE}=="ext4", ENV{ID_FS_LABEL_ENC}=="data", ENV{SYSTEMD_WANTS}+="opt-data\x2dssd.mount"</div><div>- fstab entry:</div><div>  LABEL=data /opt/data-ssd  ext4  defaults,nofail,users  0  2</div><div><br></div><div>For the not working case udev rule I tested both ENV{SYSTEMD_WANTS}+="opt-data-ssd.mount" and ENV{SYSTEMD_WANTS}+="opt-data\x2dssd.mount", but no difference.</div><div>And I can print the generated mount unit only with the unicode minus sign "\x2d" in the unit name:</div><div><br></div><div>$ sudo systemctl cat "opt-data\x2dssd.mount"<br>  # /run/systemd/generator/opt-data\x2dssd.mount<br>  # Automatically generated by systemd-fstab-generator<br><br>  [Unit]<br>  Documentation=man:fstab(5) man:systemd-fstab-generator(8)<br>  SourcePath=/etc/fstab<br>  Requires=systemd-fsck@dev-disk-by\x2dlabel-data.service<br>  After=systemd-fsck@dev-disk-by\x2dlabel-data.service<br>  After=blockdev@dev-disk-by\x2dlabel-data.target<br><br>  [Mount]<br>  What=/dev/disk/by-label/data<br>  Where=/opt/data-ssd<br>  Type=ext4<br>  Options=defaults,nofail,users</div><div><br></div><div>While</div><div>$ sudo systemctl cat "opt-data-ssd.mount"<br>   No files found for opt-data-ssd.mount.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Also, 244 is ancient 4y old stuff. Consider updating.<br>
</blockquote><div><br></div><div>Yes true, unfortunately I'm confined to systemd 244 in my application for the time being, but I replicated the same configuration on my laptop running systemd 252 (same SATA disk and adapter) and the behavior is identical.</div><div><br></div><div>Thanks for your insight.<br></div></div></div>