最終更新:2023-11-14 (火) 08:39:30 (163d)  

udev/ルール
Top / udev / ルール

https://www.freedesktop.org/software/systemd/man/latest/udev.html

http://0pointer.de/public/systemd-man/udev.html (systemd 226)

uevent

  • デバイスが追加または削除されるたびに、カーネルはueventを送信して、udevに変更を通知

設定ファイル

  • All rules files are collectively sorted and processed in lexical order, regardless of the directories in which they live.
  • Rule files must have the extension .rules; other extensions are ignored.
  • ⁠/etc、/run、/lib」の順で優先
    カスタマイズ・ルール・ファイルが格納されます。これらのファイルは変更できます。Linux/etc/udev/rules.d
    デフォルト・ルール・ファイルが格納されます。 これらのファイルは編集しないでください。Linux/lib/udev/rules.d
    一時ルール・ファイルが格納されます。 これらのファイルは編集しないでください。Linux/dev/.udev/rules.d? (RHEL)
    Linux/run/udev/rules.d? (Ubuntu)

各行の意味

検索条件

  • ==とか!=?で指定してあるのが検索条件

実行するアクション

  • =とか+=?が実行するアクション

マッチしなかった場合

  • Even if there are no matching rules, udev will create the device node with the default name supplied by the kernel.

用途

  • When a udev rule matching event information is found,
  • it can be used:
    • To define the name and path of a device file.
    • To define the owner, group and permissions of a device file.
    • To execute a specified program.

演算子

マッチキー (==)

  • 比較を行い、すべてのマッチ条件がそろうとアクションが事項される
  • udev/ルール/KERNEL? - カーネルが認識している周辺機器の名前
  • udev/ルール/ATTR?{filename} - Match sysfs attribute values of the event device.
  • udev/ルール/SUBSYSTEM - カーネル内部のサブシステムの部位

!=

  • 一致しない

代入キー (=,+=)

  • アクションの実行
  • udev/ルール/NAME?="ほげ"
  • udev/ルール/MODE?="0644"
  • udev/ルール/OPTIONS?
    • udev/ルール/OPTIONS?="last_rule" - このルールが最終的なルールであって,以後の設定で同じ条件が適合した場合でもそのルールは適用されない
  • udev/ルール/SYMLINK? - /devにシンボリックリンクを追加
  • udev/ルール/GROUP?="ほげ"
  • udev/ルール/RUN
  • udev/ルール/IMPORT
  • ...

:=

  • この後の代入を認めない

メモ

  • NAMEは1デバイス1つ。
  • SYMLINKは複数可能。

ワイルドカード

  • %k - カーネル名
  • %n - カーネル番号

Rules for rules:

  1. rules are all on one line (lines can be broken with \ just before newline)
  2. rules consist of "matches" and "actions"
  3. matches and actions are "key" "operator" "value" triplets
  4. matches have == or != for operator
  5. actions have = (assignment) for operator
  6. matches check one or more attributes of the event to see if the action will be applied
  7. actions specify what will happen
  8. example match: BUS=="usb"
  9. example action: NAME="mydev"
  10. example rule:
    KERNEL=="sd*[0-9]|dasd*[0-9]", ENV{ID_SERIAL}=="?*", \
           SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}-part%n"
  11. all matching rules will fire
  12. earlier rules have precedence over later rules - so put your customizations early in the rules.d file list
  13. actions like key="value" override
  14. actions like key+="value" add to the actions that are executed, eg SYMLINK+="foo" means "in addition to any other symlinks you were going to make for this event, also make one called foo"

ファイル

デバイスの属性の表示 (udevadm)

# udevadm info -a -n /dev/ttyUSB0

ドキュメント

Writing udev rules

udevルールについて (Oracle Linux)

参考