Linux

udev 規則適用,但不設置組

  • May 6, 2022

我有一個 STM32-Bluepill 板,我在其中刷了一個 USB 引導載入程序。如果我將它連接到我的電腦,它安裝在/dev/ttyACM0. lsusb顯示為Bus 001 Device 006: ID 1eaf:0004 Leaflabs Maple serial interface

對於 Arduino 項目diy,我的電腦上確實有一個組。因此,對於 Bluepill,我創建了以下 udev 規則:

#Bootloader-Mode
DRIVERS=="usb", SUBSYSTEMS=="usb", ATTRS{idVendor}=="1eaf", ATTRS{idProduct}=="0004", GROUP="diy", MODE="0660"
#Normal-Operation-Mode
DRIVERS=="usb", SUBSYSTEMS=="usb", ATTRS{idVendor}=="1eaf", ATTRS{idProduct}=="0003", GROUP="diy", MODE="0660"

這兩個規則都適用,但沒有一個正確設置組/dev/ttyACM0(它總是uucp)。我知道應用了這些規則,因為我目前通過將模式設置為來使用解決方法0666。這給了我使用設備的權限,但無論如何我想正確設置組。

uucp僅由我的預設規則之一設置:/usr/lib/udev/rules.d/50-udev-default.rules. 但我的規則在於,/etc/udev/rules.d/100-bluepill.rules它應該具有更高的優先級。

雖然數字前綴是指定 udev 規則順序的正常方式,但處理實際上是詞法的。來自man udev

RULES FILES
      The udev rules are read from the files located in the system rules
      directories /lib/udev/rules.d and /usr/local/lib/udev/rules.d, the
      volatile runtime directory /run/udev/rules.d and the local
      administration directory /etc/udev/rules.d. **All rules files are
collectively sorted and processed in lexical order**, regardless of the
      directories in which they live. However, files with identical filenames
      replace each other. Files in /etc have the highest priority, files in
      /run take precedence over files with the same name under /usr. This can
      be used to override a system-supplied rules file with a local file if
      needed; a symlink in /etc with the same name as a rules file in /lib,
      pointing to /dev/null, disables the rules file entirely. Rule files
      must have the extension .rules; other extensions are ignored.

所以在(1 < 5)之前100-bluepill.rules排序。要使您的規則最後應用,請選擇類似. 50-udev-default.rules``99-bluepill.rules

引用自:https://unix.stackexchange.com/questions/701630