Il giorno gio 16 feb 2023 alle ore 11:17 Lennart Poettering < lenn...@poettering.net> ha scritto:
> 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. > 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. This is almost certainly an escaping issue. What's the precisely rule > you are using? It's generally a good idea to start with the line that > doesn't work, not the one that works. > Yes! That was a good point. Removed the minus sign (-) from the mount point (/opt/data-ssd --> /opt/data) and now it works. Is it a forbidden character in systemd mount points? 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. - FS label: $ e2label /dev/sda1 data - udev rule: 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" - fstab entry: LABEL=data /opt/data ext4 defaults,nofail,users 0 2 Also working setup. - FS label: $ e2label /dev/sda1 data-ssd - udev rule: 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 - fstab entry: LABEL=data-ssd /opt/data ext4 defaults,nofail,users 0 2 But not working. - FS label: $ e2label /dev/sda1 data - udev rule: 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" - fstab entry: LABEL=data /opt/data-ssd ext4 defaults,nofail,users 0 2 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. And I can print the generated mount unit only with the unicode minus sign "\x2d" in the unit name: $ sudo systemctl cat "opt-data\x2dssd.mount" # /run/systemd/generator/opt-data\x2dssd.mount # Automatically generated by systemd-fstab-generator [Unit] Documentation=man:fstab(5) man:systemd-fstab-generator(8) SourcePath=/etc/fstab Requires=systemd-fsck@dev-disk-by\x2dlabel-data.service After=systemd-fsck@dev-disk-by\x2dlabel-data.service After=blockdev@dev-disk-by\x2dlabel-data.target [Mount] What=/dev/disk/by-label/data Where=/opt/data-ssd Type=ext4 Options=defaults,nofail,users While $ sudo systemctl cat "opt-data-ssd.mount" No files found for opt-data-ssd.mount. > Also, 244 is ancient 4y old stuff. Consider updating. > 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. Thanks for your insight.