Há algo suspeito acontecendo. Você precisa reiniciar o serviço do udev via service udev restart
e, em seguida, os comandos udev RUN funcionam conforme o esperado.
Eu tenho um problema estranho com o udev usando o Raspian (Debian) Stretch no meu Raspberry Pi. Aqui está uma regra desusada do udev que desencadeia a anexação de qualquer flash drive USB:
# /etc/udev/rules.d/70-usb-test.rules
KERNEL=="sd?1", SUBSYSTEMS=="usb", RUN+="/opt/bin/usb-test.sh"
KERNEL=="sd?1", SUBSYSTEMS=="usb", SYMLINK+="usb-test"
Conteúdo de /opt/bin/usb-test.sh
(o script está marcado como executável):
#!/bin/bash
date >> /var/log/usb-test.log
O link simbólico /dev/usb-test
é criado, mas não o arquivo /var/log/usb-test.log
.
Esta é a saída de tail /var/log/syslog
:
Oct 30 15:24:02 raspberrypi kernel: [ 9382.740128] scsi 2:0:0:0: Direct-Access 0.00 PQ: 0 ANSI: 2
Oct 30 15:24:02 raspberrypi kernel: [ 9382.747435] sd 2:0:0:0: Attached scsi generic sg2 type 0
Oct 30 15:24:02 raspberrypi kernel: [ 9382.748278] sd 2:0:0:0: [sdc] 15794176 512-byte logical blocks: (8.09 GB/7.53 GiB)
Oct 30 15:24:02 raspberrypi kernel: [ 9382.748810] sd 2:0:0:0: [sdc] Write Protect is off
Oct 30 15:24:02 raspberrypi kernel: [ 9382.748827] sd 2:0:0:0: [sdc] Mode Sense: 00 00 00 00
Oct 30 15:24:02 raspberrypi kernel: [ 9382.749235] sd 2:0:0:0: [sdc] Asking for cache data failed
Oct 30 15:24:02 raspberrypi kernel: [ 9382.749247] sd 2:0:0:0: [sdc] Assuming drive cache: write through
Oct 30 15:24:02 raspberrypi kernel: [ 9382.909187] sdc: sdc1
Oct 30 15:24:02 raspberrypi kernel: [ 9382.913033] sd 2:0:0:0: [sdc] Attached SCSI removable disk
Oct 30 15:24:03 raspberrypi systemd-udevd[3853]: Process '/opt/bin/usb-test.sh' failed with exit code 1.
lsusb:
$ lsusb
Bus 001 Device 005: ID 20a0:0006 Clay Logic
Bus 001 Device 011: ID 1307:0165 Transcend Information, Inc. 2GB/4GB/8GB Flash Drive
Bus 001 Device 006: ID 0480:a009 Toshiba America Inc Stor.E Basics
Bus 001 Device 009: ID 0480:a202 Toshiba America Inc Canvio Basics HDD
Bus 001 Device 004: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
monitor do udevadm:
$ udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
KERNEL[9851.384334] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3 (usb)
KERNEL[9851.402507] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0 (usb)
KERNEL[9851.418037] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2 (scsi)
KERNEL[9851.418582] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/scsi_host/host2 (scsi_host)
UDEV [9851.545506] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3 (usb)
UDEV [9851.570276] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0 (usb)
UDEV [9851.593606] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2 (scsi)
UDEV [9851.615895] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/scsi_host/host2 (scsi_host)
KERNEL[9852.486019] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0 (scsi)
KERNEL[9852.486271] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0 (scsi)
KERNEL[9852.486448] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0/scsi_disk/2:0:0:0 (scsi_disk)
KERNEL[9852.486620] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0/scsi_device/2:0:0:0 (scsi_device)
KERNEL[9852.494568] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0/scsi_generic/sg2 (scsi_generic)
KERNEL[9852.496172] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0/bsg/2:0:0:0 (bsg)
KERNEL[9852.498091] add /devices/virtual/bdi/8:32 (bdi)
UDEV [9852.549816] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0 (scsi)
UDEV [9852.560113] add /devices/virtual/bdi/8:32 (bdi)
UDEV [9852.590072] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0 (scsi)
KERNEL[9852.659280] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0/block/sdc (block)
KERNEL[9852.659644] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0/block/sdc/sdc1 (block)
UDEV [9852.679376] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0/scsi_disk/2:0:0:0 (scsi_disk)
UDEV [9852.726897] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0/scsi_device/2:0:0:0 (scsi_device)
UDEV [9852.741386] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0/bsg/2:0:0:0 (bsg)
UDEV [9852.745223] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0/scsi_generic/sg2 (scsi_generic)
UDEV [9853.032330] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0/block/sdc (block)
UDEV [9853.256996] add /devices/platform/soc/20980000.usb/usb1/1-1/1-1.3/1-1.3.3/1-1.3.3:1.0/host2/target2:0:0/2:0:0:0/block/sdc/sdc1 (block)
Alguém sabe o que está acontecendo?
Há algo suspeito acontecendo. Você precisa reiniciar o serviço do udev via service udev restart
e, em seguida, os comandos udev RUN funcionam conforme o esperado.
Eu tive um problema semelhante em que o script que passei para o RUN estava falhando. O problema está relacionado às permissões aplicadas no arquivo systemd-udevd.service. Você precisará desabilitar algumas dessas permissões. Minha solução foi extraída desta discussão .
O conteúdo final do arquivo /lib/systemd/system/systemd-udevd.service era, no meu caso, o seguinte:
[Service]
Type=notify
OOMScoreAdjust=-1000
Sockets=systemd-udevd-control.socket systemd-udevd-kernel.socket
Restart=always
RestartSec=0
ExecStart=/lib/systemd/systemd-udevd
KillMode=mixed
WatchdogSec=3min
TasksMax=infinity
MountFlags=slave
MemoryDenyWriteExecute=yes
RestrictRealtime=yes
RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_INET AF_INET6e
A solução rápida, como sugerido no link que forneci, é comentar as últimas sete linhas da seguinte maneira:
[Service]
Type=notify
OOMScoreAdjust=-1000
Sockets=systemd-udevd-control.socket systemd-udevd-kernel.socket
Restart=always
RestartSec=0
ExecStart=/lib/systemd/systemd-udevd
#KillMode=mixed
#WatchdogSec=3min
#TasksMax=infinity
#MountFlags=slave
#MemoryDenyWriteExecute=yes
#RestrictRealtime=yes
#RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_INET AF_INET6e
A solução mais longa é pesquisar os efeitos de cada uma das sinalizações comentadas e comentar somente as aplicáveis a suas necessidades. Em seguida, recarregue e reinicie o serviço com os seguintes comandos ou reinicie o pi:
# systemctl daemon-reload
# systemctl restart systemd-udevd.service