Udev rule RUN action is working only for part of devices
by pablocool from LinuxQuestions.org on (#6FZBB)
I prepared udev rule that I use with autofs to automount block devices. SYMLINK action works fine, while RUN does not:
Code:ACTION=="add|change", KERNEL=="sd*", ENV{DEVTYPE}=="partition", ENV{ID_FS_TYPE}!="", ENV{ID_FS_TYPE}!="swap", ENV{ID_FS_TYPE}!="crypto_LUKS", ENV{ID_FS_LABEL}=="?*", \
SYMLINK+="disk/by-me/%k-$env{ID_MODEL}-$env{ID_FS_TYPE}-$env{ID_FS_LABEL}", MODE:="0660", \
RUN+="/bin/bash -c 'rm /media/disk/%k*'", \
RUN+="/bin/ln -sf /media/autodisk/%k-$env{ID_MODEL}-$env{ID_FS_TYPE}-$env{ID_FS_LABEL} /media/disk/%k-$env{ID_MODEL}-$env{ID_FS_TYPE}-$env{ID_FS_LABEL}"
# Fallback: If partition has NO label, use kernel name
ACTION=="add|change", KERNEL=="sd*", ENV{DEVTYPE}=="partition", ENV{ID_FS_TYPE}!="", ENV{ID_FS_TYPE}!="swap", ENV{ID_FS_TYPE}!="crypto_LUKS", ENV{ID_FS_LABEL}!="?*", \
SYMLINK+="disk/by-me/%k-$env{ID_MODEL}-$env{ID_FS_TYPE}", MODE:="0660", \
RUN+="/bin/bash -c 'rm /media/disk/%k*'", \
RUN+="/bin/ln -sf /media/autodisk/%k-$env{ID_MODEL}-$env{ID_FS_TYPE} /media/disk/%k-$env{ID_MODEL}-$env{ID_FS_TYPE}"
# When device is removed, also remove /media/disk/sd*
ACTION=="remove", KERNEL=="sd*", ENV{DEVTYPE}=="partition", ENV{ID_FS_TYPE}!="", ENV{ID_FS_TYPE}!="swap", ENV{ID_FS_TYPE}!="crypto_LUKS", \
RUN+="/bin/bash -c 'rm /media/disk/%k*'"SYMLINK result:
Code:ls -l /dev/disk/by-me/
total 0
lrwxrwxrwx 1 root root 10 10-26 13:04 sda2-TOSHIBA_THNSNC128GCSJ-vfat -> ../../sda2
lrwxrwxrwx 1 root root 10 10-26 13:04 sdb1-Samsung_SSD_850_EVO_120GB-ntfs -> ../../sdb1
lrwxrwxrwx 1 root root 10 10-26 13:04 sdb2-Samsung_SSD_850_EVO_120GB-ntfs -> ../../sdb2
lrwxrwxrwx 1 root root 10 10-26 13:04 sdc1-RTL9210B-CG-vfat-SYSTEM -> ../../sdc1
lrwxrwxrwx 1 root root 10 10-26 13:04 sdc3-RTL9210B-CG-ntfs-Windows -> ../../sdc3
lrwxrwxrwx 1 root root 10 10-26 13:04 sdc4-RTL9210B-CG-ntfs-Windows_RE_tools -> ../../sdc4RUN result:
Code:ls -l /media/disk/
total 0
lrwxrwxrwx 1 root root 47 10-26 13:04 sda2-TOSHIBA_THNSNC128GCSJ-vfat -> /media/autodisk/sda2-TOSHIBA_THNSNC128GCSJ-vfat
lrwxrwxrwx 1 root root 44 10-26 13:04 sdc1-RTL9210B-CG-vfat-SYSTEM -> /media/autodisk/sdc1-RTL9210B-CG-vfat-SYSTEM
lrwxrwxrwx 1 root root 45 10-26 13:04 sdc3-RTL9210B-CG-ntfs-Windows -> /media/autodisk/sdc3-RTL9210B-CG-ntfs-Windows
lrwxrwxrwx 1 root root 54 10-26 13:04 sdc4-RTL9210B-CG-ntfs-Windows_RE_tools -> /media/autodisk/sdc4-RTL9210B-CG-ntfs-Windows_RE_toolssdb1 and sdb2 devices were not created under /media/disk while log shows they should:
Code:(...)
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Running command "/bin/bash -c 'rm /media/disk/sdb1*'"
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Starting '/bin/bash -c 'rm /media/disk/sdb1*''
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Process '/bin/bash -c 'rm /media/disk/sdb1*'' succeeded.
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Running command "/bin/ln -sf /media/autodisk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs"
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Starting '/bin/ln -sf /media/autodisk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs'
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Process '/bin/ln -sf /media/autodisk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs' succeeded.
(...)
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Running command "/bin/bash -c 'rm /media/disk/sdb2*'"
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Starting '/bin/bash -c 'rm /media/disk/sdb2*''
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Process '/bin/bash -c 'rm /media/disk/sdb2*'' succeeded.
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Running command "/bin/ln -sf /media/autodisk/sdb2-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb2-Samsung_SSD_850_EVO_120GB-ntfs"
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Starting '/bin/ln -sf /media/autodisk/sdb2-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb2-Samsung_SSD_850_EVO_120GB-ntfs'
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Process '/bin/ln -sf /media/autodisk/sdb2-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb2-Samsung_SSD_850_EVO_120GB-ntfs' succeeded.
(...)I also created testing/debugging rule:
Code:cat /etc/udev/rules.d/88-test.rules
ACTION=="add", KERNEL=="sd*", ENV{SUBSYSTEM}=="block", \
RUN="/bin/bash -c 'echo -e add\\t%E{DEVNAME} >> /tmp/udev.log'"
ACTION=="change", KERNEL=="sd*", ENV{SUBSYSTEM}=="block", \
RUN="/bin/bash -c 'echo -e change\\t%E{DEVNAME} >> /tmp/udev.log'"
ACTION=="remove", KERNEL=="sd*", ENV{SUBSYSTEM}=="block", \
RUN="/bin/bash -c 'echo -e remove\\t%E{DEVNAME} >> /tmp/udev.log'"Log also shows it should work fine:
Code:Oct 26 13:04:48 serwer (udev-worker)[255]: sda: Running command "/bin/bash -c 'echo -e add\\t/dev/sda >> /tmp/udev.log'"
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb: Running command "/bin/bash -c 'echo -e add\\t/dev/sdb >> /tmp/udev.log'"
Oct 26 13:04:48 serwer (udev-worker)[262]: sda3: Running command "/bin/bash -c 'echo -e add\\t/dev/sda3 >> /tmp/udev.log'"
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Running command "/bin/bash -c 'echo -e add\\t/dev/sdb1 >> /tmp/udev.log'"
Oct 26 13:04:48 serwer (udev-worker)[258]: sda2: Running command "/bin/bash -c 'echo -e add\\t/dev/sda2 >> /tmp/udev.log'"
Oct 26 13:04:48 serwer (udev-worker)[255]: sda1: Running command "/bin/bash -c 'echo -e add\\t/dev/sda1 >> /tmp/udev.log'"
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Running command "/bin/bash -c 'echo -e add\\t/dev/sdb2 >> /tmp/udev.log'"
Oct 26 13:04:49 serwer (udev-worker)[257]: sda2: Running command "/bin/bash -c 'echo -e change\\t/dev/sda2 >> /tmp/udev.log'"
Oct 26 13:04:50 serwer (udev-worker)[307]: sdc: Running command "/bin/bash -c 'echo -e add\\t/dev/sdc >> /tmp/udev.log'"
Oct 26 13:04:50 serwer (udev-worker)[256]: sdc2: Running command "/bin/bash -c 'echo -e add\\t/dev/sdc2 >> /tmp/udev.log'"
Oct 26 13:04:51 serwer (udev-worker)[307]: sdc1: Running command "/bin/bash -c 'echo -e add\\t/dev/sdc1 >> /tmp/udev.log'"
Oct 26 13:04:51 serwer (udev-worker)[255]: sdc4: Running command "/bin/bash -c 'echo -e add\\t/dev/sdc4 >> /tmp/udev.log'"
Oct 26 13:04:51 serwer (udev-worker)[261]: sdc3: Running command "/bin/bash -c 'echo -e add\\t/dev/sdc3 >> /tmp/udev.log'"
Oct 26 13:11:51 serwer (udev-worker)[4487]: sdc3: Running command "/bin/bash -c 'echo -e change\\t/dev/sdc3 >> /tmp/udev.log'"
Oct 26 13:11:52 serwer (udev-worker)[4487]: sdc4: Running command "/bin/bash -c 'echo -e change\\t/dev/sdc4 >> /tmp/udev.log'"But content of the file is also limited (like /media/disk dir content):
Code:cat /tmp/udev.log
change /dev/sda2
add /dev/sdc
add /dev/sdc2
add /dev/sdc1
add /dev/sdc4
add /dev/sdc3
change /dev/sdc3
change /dev/sdc4I also tested rule on sdb1:
Code:sudo udevadm test --action=add /dev/sdb1
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.
Trying to open "/etc/systemd/hwdb/hwdb.bin"...
Trying to open "/etc/udev/hwdb.bin"...
=== trie on-disk ===
tool version: 253
file size: 12004338 bytes
header size 80 bytes
strings 2530498 bytes
nodes 9473760 bytes
Loading kernel module index.
Found cgroup2 on /sys/fs/cgroup/unified, unified hierarchy for systemd controller
Found container virtualization none.
Using default interface naming scheme 'v253'.
Parsed configuration file "/lib/systemd/network/99-default.link"
Created link configuration context.
Reading rules file: /lib/udev/rules.d/10-dm.rules
Reading rules file: /lib/udev/rules.d/13-dm-disk.rules
Reading rules file: /lib/udev/rules.d/40-gentoo.rules
Reading rules file: /lib/udev/rules.d/40-usb_modeswitch.rules
Reading rules file: /lib/udev/rules.d/50-udev-default.rules
Reading rules file: /lib/udev/rules.d/51-android.rules
Reading rules file: /lib/udev/rules.d/60-autosuspend.rules
Reading rules file: /lib/udev/rules.d/60-block.rules
Reading rules file: /lib/udev/rules.d/60-cdrom_id.rules
Reading rules file: /lib/udev/rules.d/60-drm.rules
Reading rules file: /lib/udev/rules.d/60-evdev.rules
Reading rules file: /lib/udev/rules.d/60-fido-id.rules
Reading rules file: /lib/udev/rules.d/60-infiniband.rules
Reading rules file: /lib/udev/rules.d/60-input-id.rules
Reading rules file: /usr/lib/udev/rules.d/60-nfs.rules
Reading rules file: /lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /lib/udev/rules.d/60-persistent-input.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage.rules
Reading rules file: /lib/udev/rules.d/60-persistent-v4l.rules
Reading rules file: /lib/udev/rules.d/60-sensor.rules
Reading rules file: /lib/udev/rules.d/60-serial.rules
Reading rules file: /lib/udev/rules.d/64-btrfs.rules
Reading rules file: /lib/udev/rules.d/65-kvm.rules
Reading rules file: /lib/udev/rules.d/70-camera.rules
Reading rules file: /lib/udev/rules.d/70-joystick.rules
Reading rules file: /lib/udev/rules.d/70-memory.rules
Reading rules file: /lib/udev/rules.d/70-mouse.rules
Reading rules file: /lib/udev/rules.d/70-power-switch.rules
Reading rules file: /lib/udev/rules.d/70-printers.rules
Reading rules file: /lib/udev/rules.d/70-touchpad.rules
Reading rules file: /lib/udev/rules.d/70-uaccess.rules
Reading rules file: /lib/udev/rules.d/71-seat.rules
Reading rules file: /lib/udev/rules.d/73-seat-late.rules
Reading rules file: /lib/udev/rules.d/75-net-description.rules
Reading rules file: /lib/udev/rules.d/75-probe_mtd.rules
Reading rules file: /lib/udev/rules.d/78-sound-card.rules
Reading rules file: /lib/udev/rules.d/80-drivers.rules
Reading rules file: /lib/udev/rules.d/80-libinput-device-groups.rules
Reading rules file: /lib/udev/rules.d/80-net-setup-link.rules
Reading rules file: /lib/udev/rules.d/80-udisks2.rules
Reading rules file: /lib/udev/rules.d/81-net-dhcp.rules
Reading rules file: /etc/udev/rules.d/88-test.rules
Reading rules file: /etc/udev/rules.d/89-sdX-auto.rules
Reading rules file: /lib/udev/rules.d/90-libinput-fuzz-override.rules
Reading rules file: /lib/udev/rules.d/90-pulseaudio.rules
Reading rules file: /etc/udev/rules.d/90-sdX-auto.rules
Reading rules file: /lib/udev/rules.d/90-vconsole.rules
Reading rules file: /etc/udev/rules.d/91-macierz.rules
/etc/udev/rules.d/91-macierz.rules:1 Invalid key/value pair, ignoring.
Reading rules file: /lib/udev/rules.d/95-dm-notify.rules
Reading rules file: /lib/udev/rules.d/95-upower-hid.rules
Reading rules file: /lib/udev/rules.d/95-upower-wup.rules
Reading rules file: /lib/udev/rules.d/96-e2scrub.rules
Reading rules file: /lib/udev/rules.d/99-fuse.rules
Reading rules file: /usr/lib/udev/rules.d/99-nfs.rules
Reading rules file: /lib/udev/rules.d/99-pcscd-hotplug.rules
Reading rules file: /etc/udev/rules.d/99-stmclite.rules
/etc/udev/rules.d/99-stmclite.rules:5 Invalid key/value pair, ignoring.
Reading rules file: /lib/udev/rules.d/99-systemd.rules
sdb1: /lib/udev/rules.d/50-udev-default.rules:74 GROUP 6
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:77 Added SYMLINK 'disk/by-id/ata-Samsung_SSD_850_EVO_120GB_S21UNXAG905854E-part1'
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:108 Added SYMLINK 'disk/by-path/pci-0000:00:1f.5-ata-1.0-part1'
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:111 Added SYMLINK 'disk/by-path/pci-0000:00:1f.5-ata-1-part1'
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:128 Importing properties from results of builtin command 'blkid'
sdb1: Probe /dev/sdb1 with raid and offset=0
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:133 Added SYMLINK 'disk/by-uuid/0C9A7BEB9A7BD026'
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:138 Added SYMLINK 'disk/by-id/wwn-0x5002538d40513230-part1'
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:141 Added SYMLINK 'disk/by-partuuid/f47a8a52-01'
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:148 Added SYMLINK 'disk/by-diskseq/10-part1'
sdb1: /etc/udev/rules.d/88-test.rules:2 RUN '/bin/bash -c 'echo -e add\\t%E{DEVNAME} >> /tmp/udev.log''
sdb1: /etc/udev/rules.d/90-sdX-auto.rules:41 MODE 0660
sdb1: /etc/udev/rules.d/90-sdX-auto.rules:41 Added SYMLINK 'disk/by-me/sdb1-Samsung_SSD_850_EVO_120GB-ntfs'
sdb1: /etc/udev/rules.d/90-sdX-auto.rules:41 RUN '/bin/bash -c 'rm /media/disk/%k*''
sdb1: /etc/udev/rules.d/90-sdX-auto.rules:41 RUN '/bin/ln -sf /media/autodisk/%k-$env{ID_MODEL}-$env{ID_FS_TYPE} /media/disk/%k-$env{ID_MODEL}-$env{ID_FS_TYPE}'
sdb1: Preserve permissions of /dev/sdb1, uid=0, gid=6, mode=0660
sdb1: Successfully created symlink '/dev/disk/by-path/pci-0000:00:1f.5-ata-1-part1' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-uuid/0C9A7BEB9A7BD026' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-id/ata-Samsung_SSD_850_EVO_120GB_S21UNXAG905854E-part1' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-me/sdb1-Samsung_SSD_850_EVO_120GB-ntfs' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-diskseq/10-part1' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-id/wwn-0x5002538d40513230-part1' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-partuuid/f47a8a52-01' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-path/pci-0000:00:1f.5-ata-1.0-part1' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/block/8:17' to '/dev/sdb1'
sdb1: sd-device: Created db file '/run/udev/data/b8:17' for '/devices/pci0000:00/0000:00:1f.5/ata3/host2/target2:0:0/2:0:0:0/block/sdb/sdb1'
DEVPATH=/devices/pci0000:00/0000:00:1f.5/ata3/host2/target2:0:0/2:0:0:0/block/sdb/sdb1
DEVNAME=/dev/sdb1
DEVTYPE=partition
DISKSEQ=10
PARTN=1
MAJOR=8
MINOR=17
SUBSYSTEM=block
ACTION=add
TAGS=:systemd:
ID_ATA=1
ID_TYPE=disk
ID_BUS=ata
ID_MODEL=Samsung_SSD_850_EVO_120GB
ID_MODEL_ENC=Samsung\x20SSD\x20850\x20EVO\x20120GB\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
ID_REVISION=EMT01B6Q
ID_SERIAL=Samsung_SSD_850_EVO_120GB_S21UNXAG905854E
ID_SERIAL_SHORT=S21UNXAG905854E
ID_ATA_WRITE_CACHE=1
ID_ATA_WRITE_CACHE_ENABLED=1
ID_ATA_FEATURE_SET_HPA=1
ID_ATA_FEATURE_SET_HPA_ENABLED=1
ID_ATA_FEATURE_SET_PM=1
ID_ATA_FEATURE_SET_PM_ENABLED=1
ID_ATA_FEATURE_SET_SECURITY=1
ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=2
ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=8
ID_ATA_FEATURE_SET_SECURITY_FROZEN=1
ID_ATA_FEATURE_SET_SMART=1
ID_ATA_FEATURE_SET_SMART_ENABLED=1
ID_ATA_DOWNLOAD_MICROCODE=1
ID_ATA_SATA=1
ID_ATA_SATA_SIGNAL_RATE_GEN2=1
ID_ATA_SATA_SIGNAL_RATE_GEN1=1
ID_ATA_ROTATION_RATE_RPM=0
ID_WWN=0x5002538d40513230
ID_WWN_WITH_EXTENSION=0x5002538d40513230
ID_PATH=pci-0000:00:1f.5-ata-1.0
ID_PATH_TAG=pci-0000_00_1f_5-ata-1_0
ID_PATH_ATA_COMPAT=pci-0000:00:1f.5-ata-1
ID_PART_TABLE_UUID=f47a8a52
ID_PART_TABLE_TYPE=dos
DEVLINKS=/dev/disk/by-path/pci-0000:00:1f.5-ata-1-part1 /dev/disk/by-uuid/0C9A7BEB9A7BD026 /dev/disk/by-id/ata-Samsung_SSD_850_EVO_120GB_S21UNXAG905854E-part1 /dev/disk/by-me/sdb1-Samsung_SSD_850_EVO_120GB-ntfs /dev/disk/by-diskseq/10-part1 /dev/disk/by-id/wwn-0x5002538d40513230-part1 /dev/disk/by-partuuid/f47a8a52-01 /dev/disk/by-path/pci-0000:00:1f.5-ata-1.0-part1
ID_FS_UUID=0C9A7BEB9A7BD026
ID_FS_UUID_ENC=0C9A7BEB9A7BD026
ID_FS_TYPE=ntfs
ID_FS_USAGE=filesystem
ID_PART_ENTRY_SCHEME=dos
ID_PART_ENTRY_UUID=f47a8a52-01
ID_PART_ENTRY_TYPE=0x7
ID_PART_ENTRY_FLAGS=0x80
ID_PART_ENTRY_NUMBER=1
ID_PART_ENTRY_OFFSET=2048
ID_PART_ENTRY_SIZE=102604800
ID_PART_ENTRY_DISK=8:16
CURRENT_TAGS=:systemd:
USEC_INITIALIZED=19872491
run: '/bin/bash -c 'echo -e add\\t/dev/sdb1 >> /tmp/udev.log''
run: '/bin/bash -c 'rm /media/disk/sdb1*''
run: '/bin/ln -sf /media/autodisk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs'
Unload kernel module index.
Unloaded link configuration context.Everything looks fine, however rules does not work as expected.
I stuck and out of ideas.
Help appreciated. Thank you!
Code:ACTION=="add|change", KERNEL=="sd*", ENV{DEVTYPE}=="partition", ENV{ID_FS_TYPE}!="", ENV{ID_FS_TYPE}!="swap", ENV{ID_FS_TYPE}!="crypto_LUKS", ENV{ID_FS_LABEL}=="?*", \
SYMLINK+="disk/by-me/%k-$env{ID_MODEL}-$env{ID_FS_TYPE}-$env{ID_FS_LABEL}", MODE:="0660", \
RUN+="/bin/bash -c 'rm /media/disk/%k*'", \
RUN+="/bin/ln -sf /media/autodisk/%k-$env{ID_MODEL}-$env{ID_FS_TYPE}-$env{ID_FS_LABEL} /media/disk/%k-$env{ID_MODEL}-$env{ID_FS_TYPE}-$env{ID_FS_LABEL}"
# Fallback: If partition has NO label, use kernel name
ACTION=="add|change", KERNEL=="sd*", ENV{DEVTYPE}=="partition", ENV{ID_FS_TYPE}!="", ENV{ID_FS_TYPE}!="swap", ENV{ID_FS_TYPE}!="crypto_LUKS", ENV{ID_FS_LABEL}!="?*", \
SYMLINK+="disk/by-me/%k-$env{ID_MODEL}-$env{ID_FS_TYPE}", MODE:="0660", \
RUN+="/bin/bash -c 'rm /media/disk/%k*'", \
RUN+="/bin/ln -sf /media/autodisk/%k-$env{ID_MODEL}-$env{ID_FS_TYPE} /media/disk/%k-$env{ID_MODEL}-$env{ID_FS_TYPE}"
# When device is removed, also remove /media/disk/sd*
ACTION=="remove", KERNEL=="sd*", ENV{DEVTYPE}=="partition", ENV{ID_FS_TYPE}!="", ENV{ID_FS_TYPE}!="swap", ENV{ID_FS_TYPE}!="crypto_LUKS", \
RUN+="/bin/bash -c 'rm /media/disk/%k*'"SYMLINK result:
Code:ls -l /dev/disk/by-me/
total 0
lrwxrwxrwx 1 root root 10 10-26 13:04 sda2-TOSHIBA_THNSNC128GCSJ-vfat -> ../../sda2
lrwxrwxrwx 1 root root 10 10-26 13:04 sdb1-Samsung_SSD_850_EVO_120GB-ntfs -> ../../sdb1
lrwxrwxrwx 1 root root 10 10-26 13:04 sdb2-Samsung_SSD_850_EVO_120GB-ntfs -> ../../sdb2
lrwxrwxrwx 1 root root 10 10-26 13:04 sdc1-RTL9210B-CG-vfat-SYSTEM -> ../../sdc1
lrwxrwxrwx 1 root root 10 10-26 13:04 sdc3-RTL9210B-CG-ntfs-Windows -> ../../sdc3
lrwxrwxrwx 1 root root 10 10-26 13:04 sdc4-RTL9210B-CG-ntfs-Windows_RE_tools -> ../../sdc4RUN result:
Code:ls -l /media/disk/
total 0
lrwxrwxrwx 1 root root 47 10-26 13:04 sda2-TOSHIBA_THNSNC128GCSJ-vfat -> /media/autodisk/sda2-TOSHIBA_THNSNC128GCSJ-vfat
lrwxrwxrwx 1 root root 44 10-26 13:04 sdc1-RTL9210B-CG-vfat-SYSTEM -> /media/autodisk/sdc1-RTL9210B-CG-vfat-SYSTEM
lrwxrwxrwx 1 root root 45 10-26 13:04 sdc3-RTL9210B-CG-ntfs-Windows -> /media/autodisk/sdc3-RTL9210B-CG-ntfs-Windows
lrwxrwxrwx 1 root root 54 10-26 13:04 sdc4-RTL9210B-CG-ntfs-Windows_RE_tools -> /media/autodisk/sdc4-RTL9210B-CG-ntfs-Windows_RE_toolssdb1 and sdb2 devices were not created under /media/disk while log shows they should:
Code:(...)
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Running command "/bin/bash -c 'rm /media/disk/sdb1*'"
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Starting '/bin/bash -c 'rm /media/disk/sdb1*''
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Process '/bin/bash -c 'rm /media/disk/sdb1*'' succeeded.
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Running command "/bin/ln -sf /media/autodisk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs"
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Starting '/bin/ln -sf /media/autodisk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs'
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Process '/bin/ln -sf /media/autodisk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs' succeeded.
(...)
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Running command "/bin/bash -c 'rm /media/disk/sdb2*'"
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Starting '/bin/bash -c 'rm /media/disk/sdb2*''
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Process '/bin/bash -c 'rm /media/disk/sdb2*'' succeeded.
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Running command "/bin/ln -sf /media/autodisk/sdb2-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb2-Samsung_SSD_850_EVO_120GB-ntfs"
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Starting '/bin/ln -sf /media/autodisk/sdb2-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb2-Samsung_SSD_850_EVO_120GB-ntfs'
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Process '/bin/ln -sf /media/autodisk/sdb2-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb2-Samsung_SSD_850_EVO_120GB-ntfs' succeeded.
(...)I also created testing/debugging rule:
Code:cat /etc/udev/rules.d/88-test.rules
ACTION=="add", KERNEL=="sd*", ENV{SUBSYSTEM}=="block", \
RUN="/bin/bash -c 'echo -e add\\t%E{DEVNAME} >> /tmp/udev.log'"
ACTION=="change", KERNEL=="sd*", ENV{SUBSYSTEM}=="block", \
RUN="/bin/bash -c 'echo -e change\\t%E{DEVNAME} >> /tmp/udev.log'"
ACTION=="remove", KERNEL=="sd*", ENV{SUBSYSTEM}=="block", \
RUN="/bin/bash -c 'echo -e remove\\t%E{DEVNAME} >> /tmp/udev.log'"Log also shows it should work fine:
Code:Oct 26 13:04:48 serwer (udev-worker)[255]: sda: Running command "/bin/bash -c 'echo -e add\\t/dev/sda >> /tmp/udev.log'"
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb: Running command "/bin/bash -c 'echo -e add\\t/dev/sdb >> /tmp/udev.log'"
Oct 26 13:04:48 serwer (udev-worker)[262]: sda3: Running command "/bin/bash -c 'echo -e add\\t/dev/sda3 >> /tmp/udev.log'"
Oct 26 13:04:48 serwer (udev-worker)[257]: sdb1: Running command "/bin/bash -c 'echo -e add\\t/dev/sdb1 >> /tmp/udev.log'"
Oct 26 13:04:48 serwer (udev-worker)[258]: sda2: Running command "/bin/bash -c 'echo -e add\\t/dev/sda2 >> /tmp/udev.log'"
Oct 26 13:04:48 serwer (udev-worker)[255]: sda1: Running command "/bin/bash -c 'echo -e add\\t/dev/sda1 >> /tmp/udev.log'"
Oct 26 13:04:48 serwer (udev-worker)[266]: sdb2: Running command "/bin/bash -c 'echo -e add\\t/dev/sdb2 >> /tmp/udev.log'"
Oct 26 13:04:49 serwer (udev-worker)[257]: sda2: Running command "/bin/bash -c 'echo -e change\\t/dev/sda2 >> /tmp/udev.log'"
Oct 26 13:04:50 serwer (udev-worker)[307]: sdc: Running command "/bin/bash -c 'echo -e add\\t/dev/sdc >> /tmp/udev.log'"
Oct 26 13:04:50 serwer (udev-worker)[256]: sdc2: Running command "/bin/bash -c 'echo -e add\\t/dev/sdc2 >> /tmp/udev.log'"
Oct 26 13:04:51 serwer (udev-worker)[307]: sdc1: Running command "/bin/bash -c 'echo -e add\\t/dev/sdc1 >> /tmp/udev.log'"
Oct 26 13:04:51 serwer (udev-worker)[255]: sdc4: Running command "/bin/bash -c 'echo -e add\\t/dev/sdc4 >> /tmp/udev.log'"
Oct 26 13:04:51 serwer (udev-worker)[261]: sdc3: Running command "/bin/bash -c 'echo -e add\\t/dev/sdc3 >> /tmp/udev.log'"
Oct 26 13:11:51 serwer (udev-worker)[4487]: sdc3: Running command "/bin/bash -c 'echo -e change\\t/dev/sdc3 >> /tmp/udev.log'"
Oct 26 13:11:52 serwer (udev-worker)[4487]: sdc4: Running command "/bin/bash -c 'echo -e change\\t/dev/sdc4 >> /tmp/udev.log'"But content of the file is also limited (like /media/disk dir content):
Code:cat /tmp/udev.log
change /dev/sda2
add /dev/sdc
add /dev/sdc2
add /dev/sdc1
add /dev/sdc4
add /dev/sdc3
change /dev/sdc3
change /dev/sdc4I also tested rule on sdb1:
Code:sudo udevadm test --action=add /dev/sdb1
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.
Trying to open "/etc/systemd/hwdb/hwdb.bin"...
Trying to open "/etc/udev/hwdb.bin"...
=== trie on-disk ===
tool version: 253
file size: 12004338 bytes
header size 80 bytes
strings 2530498 bytes
nodes 9473760 bytes
Loading kernel module index.
Found cgroup2 on /sys/fs/cgroup/unified, unified hierarchy for systemd controller
Found container virtualization none.
Using default interface naming scheme 'v253'.
Parsed configuration file "/lib/systemd/network/99-default.link"
Created link configuration context.
Reading rules file: /lib/udev/rules.d/10-dm.rules
Reading rules file: /lib/udev/rules.d/13-dm-disk.rules
Reading rules file: /lib/udev/rules.d/40-gentoo.rules
Reading rules file: /lib/udev/rules.d/40-usb_modeswitch.rules
Reading rules file: /lib/udev/rules.d/50-udev-default.rules
Reading rules file: /lib/udev/rules.d/51-android.rules
Reading rules file: /lib/udev/rules.d/60-autosuspend.rules
Reading rules file: /lib/udev/rules.d/60-block.rules
Reading rules file: /lib/udev/rules.d/60-cdrom_id.rules
Reading rules file: /lib/udev/rules.d/60-drm.rules
Reading rules file: /lib/udev/rules.d/60-evdev.rules
Reading rules file: /lib/udev/rules.d/60-fido-id.rules
Reading rules file: /lib/udev/rules.d/60-infiniband.rules
Reading rules file: /lib/udev/rules.d/60-input-id.rules
Reading rules file: /usr/lib/udev/rules.d/60-nfs.rules
Reading rules file: /lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /lib/udev/rules.d/60-persistent-input.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage.rules
Reading rules file: /lib/udev/rules.d/60-persistent-v4l.rules
Reading rules file: /lib/udev/rules.d/60-sensor.rules
Reading rules file: /lib/udev/rules.d/60-serial.rules
Reading rules file: /lib/udev/rules.d/64-btrfs.rules
Reading rules file: /lib/udev/rules.d/65-kvm.rules
Reading rules file: /lib/udev/rules.d/70-camera.rules
Reading rules file: /lib/udev/rules.d/70-joystick.rules
Reading rules file: /lib/udev/rules.d/70-memory.rules
Reading rules file: /lib/udev/rules.d/70-mouse.rules
Reading rules file: /lib/udev/rules.d/70-power-switch.rules
Reading rules file: /lib/udev/rules.d/70-printers.rules
Reading rules file: /lib/udev/rules.d/70-touchpad.rules
Reading rules file: /lib/udev/rules.d/70-uaccess.rules
Reading rules file: /lib/udev/rules.d/71-seat.rules
Reading rules file: /lib/udev/rules.d/73-seat-late.rules
Reading rules file: /lib/udev/rules.d/75-net-description.rules
Reading rules file: /lib/udev/rules.d/75-probe_mtd.rules
Reading rules file: /lib/udev/rules.d/78-sound-card.rules
Reading rules file: /lib/udev/rules.d/80-drivers.rules
Reading rules file: /lib/udev/rules.d/80-libinput-device-groups.rules
Reading rules file: /lib/udev/rules.d/80-net-setup-link.rules
Reading rules file: /lib/udev/rules.d/80-udisks2.rules
Reading rules file: /lib/udev/rules.d/81-net-dhcp.rules
Reading rules file: /etc/udev/rules.d/88-test.rules
Reading rules file: /etc/udev/rules.d/89-sdX-auto.rules
Reading rules file: /lib/udev/rules.d/90-libinput-fuzz-override.rules
Reading rules file: /lib/udev/rules.d/90-pulseaudio.rules
Reading rules file: /etc/udev/rules.d/90-sdX-auto.rules
Reading rules file: /lib/udev/rules.d/90-vconsole.rules
Reading rules file: /etc/udev/rules.d/91-macierz.rules
/etc/udev/rules.d/91-macierz.rules:1 Invalid key/value pair, ignoring.
Reading rules file: /lib/udev/rules.d/95-dm-notify.rules
Reading rules file: /lib/udev/rules.d/95-upower-hid.rules
Reading rules file: /lib/udev/rules.d/95-upower-wup.rules
Reading rules file: /lib/udev/rules.d/96-e2scrub.rules
Reading rules file: /lib/udev/rules.d/99-fuse.rules
Reading rules file: /usr/lib/udev/rules.d/99-nfs.rules
Reading rules file: /lib/udev/rules.d/99-pcscd-hotplug.rules
Reading rules file: /etc/udev/rules.d/99-stmclite.rules
/etc/udev/rules.d/99-stmclite.rules:5 Invalid key/value pair, ignoring.
Reading rules file: /lib/udev/rules.d/99-systemd.rules
sdb1: /lib/udev/rules.d/50-udev-default.rules:74 GROUP 6
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:77 Added SYMLINK 'disk/by-id/ata-Samsung_SSD_850_EVO_120GB_S21UNXAG905854E-part1'
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:108 Added SYMLINK 'disk/by-path/pci-0000:00:1f.5-ata-1.0-part1'
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:111 Added SYMLINK 'disk/by-path/pci-0000:00:1f.5-ata-1-part1'
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:128 Importing properties from results of builtin command 'blkid'
sdb1: Probe /dev/sdb1 with raid and offset=0
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:133 Added SYMLINK 'disk/by-uuid/0C9A7BEB9A7BD026'
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:138 Added SYMLINK 'disk/by-id/wwn-0x5002538d40513230-part1'
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:141 Added SYMLINK 'disk/by-partuuid/f47a8a52-01'
sdb1: /lib/udev/rules.d/60-persistent-storage.rules:148 Added SYMLINK 'disk/by-diskseq/10-part1'
sdb1: /etc/udev/rules.d/88-test.rules:2 RUN '/bin/bash -c 'echo -e add\\t%E{DEVNAME} >> /tmp/udev.log''
sdb1: /etc/udev/rules.d/90-sdX-auto.rules:41 MODE 0660
sdb1: /etc/udev/rules.d/90-sdX-auto.rules:41 Added SYMLINK 'disk/by-me/sdb1-Samsung_SSD_850_EVO_120GB-ntfs'
sdb1: /etc/udev/rules.d/90-sdX-auto.rules:41 RUN '/bin/bash -c 'rm /media/disk/%k*''
sdb1: /etc/udev/rules.d/90-sdX-auto.rules:41 RUN '/bin/ln -sf /media/autodisk/%k-$env{ID_MODEL}-$env{ID_FS_TYPE} /media/disk/%k-$env{ID_MODEL}-$env{ID_FS_TYPE}'
sdb1: Preserve permissions of /dev/sdb1, uid=0, gid=6, mode=0660
sdb1: Successfully created symlink '/dev/disk/by-path/pci-0000:00:1f.5-ata-1-part1' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-uuid/0C9A7BEB9A7BD026' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-id/ata-Samsung_SSD_850_EVO_120GB_S21UNXAG905854E-part1' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-me/sdb1-Samsung_SSD_850_EVO_120GB-ntfs' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-diskseq/10-part1' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-id/wwn-0x5002538d40513230-part1' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-partuuid/f47a8a52-01' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/disk/by-path/pci-0000:00:1f.5-ata-1.0-part1' to '/dev/sdb1'
sdb1: Successfully created symlink '/dev/block/8:17' to '/dev/sdb1'
sdb1: sd-device: Created db file '/run/udev/data/b8:17' for '/devices/pci0000:00/0000:00:1f.5/ata3/host2/target2:0:0/2:0:0:0/block/sdb/sdb1'
DEVPATH=/devices/pci0000:00/0000:00:1f.5/ata3/host2/target2:0:0/2:0:0:0/block/sdb/sdb1
DEVNAME=/dev/sdb1
DEVTYPE=partition
DISKSEQ=10
PARTN=1
MAJOR=8
MINOR=17
SUBSYSTEM=block
ACTION=add
TAGS=:systemd:
ID_ATA=1
ID_TYPE=disk
ID_BUS=ata
ID_MODEL=Samsung_SSD_850_EVO_120GB
ID_MODEL_ENC=Samsung\x20SSD\x20850\x20EVO\x20120GB\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
ID_REVISION=EMT01B6Q
ID_SERIAL=Samsung_SSD_850_EVO_120GB_S21UNXAG905854E
ID_SERIAL_SHORT=S21UNXAG905854E
ID_ATA_WRITE_CACHE=1
ID_ATA_WRITE_CACHE_ENABLED=1
ID_ATA_FEATURE_SET_HPA=1
ID_ATA_FEATURE_SET_HPA_ENABLED=1
ID_ATA_FEATURE_SET_PM=1
ID_ATA_FEATURE_SET_PM_ENABLED=1
ID_ATA_FEATURE_SET_SECURITY=1
ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=2
ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=8
ID_ATA_FEATURE_SET_SECURITY_FROZEN=1
ID_ATA_FEATURE_SET_SMART=1
ID_ATA_FEATURE_SET_SMART_ENABLED=1
ID_ATA_DOWNLOAD_MICROCODE=1
ID_ATA_SATA=1
ID_ATA_SATA_SIGNAL_RATE_GEN2=1
ID_ATA_SATA_SIGNAL_RATE_GEN1=1
ID_ATA_ROTATION_RATE_RPM=0
ID_WWN=0x5002538d40513230
ID_WWN_WITH_EXTENSION=0x5002538d40513230
ID_PATH=pci-0000:00:1f.5-ata-1.0
ID_PATH_TAG=pci-0000_00_1f_5-ata-1_0
ID_PATH_ATA_COMPAT=pci-0000:00:1f.5-ata-1
ID_PART_TABLE_UUID=f47a8a52
ID_PART_TABLE_TYPE=dos
DEVLINKS=/dev/disk/by-path/pci-0000:00:1f.5-ata-1-part1 /dev/disk/by-uuid/0C9A7BEB9A7BD026 /dev/disk/by-id/ata-Samsung_SSD_850_EVO_120GB_S21UNXAG905854E-part1 /dev/disk/by-me/sdb1-Samsung_SSD_850_EVO_120GB-ntfs /dev/disk/by-diskseq/10-part1 /dev/disk/by-id/wwn-0x5002538d40513230-part1 /dev/disk/by-partuuid/f47a8a52-01 /dev/disk/by-path/pci-0000:00:1f.5-ata-1.0-part1
ID_FS_UUID=0C9A7BEB9A7BD026
ID_FS_UUID_ENC=0C9A7BEB9A7BD026
ID_FS_TYPE=ntfs
ID_FS_USAGE=filesystem
ID_PART_ENTRY_SCHEME=dos
ID_PART_ENTRY_UUID=f47a8a52-01
ID_PART_ENTRY_TYPE=0x7
ID_PART_ENTRY_FLAGS=0x80
ID_PART_ENTRY_NUMBER=1
ID_PART_ENTRY_OFFSET=2048
ID_PART_ENTRY_SIZE=102604800
ID_PART_ENTRY_DISK=8:16
CURRENT_TAGS=:systemd:
USEC_INITIALIZED=19872491
run: '/bin/bash -c 'echo -e add\\t/dev/sdb1 >> /tmp/udev.log''
run: '/bin/bash -c 'rm /media/disk/sdb1*''
run: '/bin/ln -sf /media/autodisk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs /media/disk/sdb1-Samsung_SSD_850_EVO_120GB-ntfs'
Unload kernel module index.
Unloaded link configuration context.Everything looks fine, however rules does not work as expected.
I stuck and out of ideas.
Help appreciated. Thank you!