最終更新:2023-11-14 (火) 08:39:30 (163d)
udev/ルール
https://www.freedesktop.org/software/systemd/man/latest/udev.html
http://0pointer.de/public/systemd-man/udev.html (systemd 226)
uevent
設定ファイル
- 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/ルール/ACTION - 周辺機器の着脱 (add/remove)
- udev/ルール/DEVPATH?
- udev/ルール/NAME?
- udev/ルール/SYMLINK?
- udev/ルール/DRIVER?
- udev/ルール/ENV ...
!=
- 一致しない
代入キー (=,+=)
- アクションの実行
- 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:
- rules are all on one line (lines can be broken with \ just before newline)
- rules consist of "matches" and "actions"
- matches and actions are "key" "operator" "value" triplets
- matches have == or != for operator
- actions have = (assignment) for operator
- matches check one or more attributes of the event to see if the action will be applied
- actions specify what will happen
- example match: BUS=="usb"
- example action: NAME="mydev"
- example rule:
KERNEL=="sd*[0-9]|dasd*[0-9]", ENV{ID_SERIAL}=="?*", \ SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}-part%n"
- all matching rules will fire
- earlier rules have precedence over later rules - so put your customizations early in the rules.d file list
- actions like key="value" override
- 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)
参考
- http://opensuse-man-ja.berlios.de/opensuse-html/cha.udev.html
- https://wiki.archlinux.org/index.php/Udev
- http://www.reactivated.net/writing_udev_rules.html
- http://www.gentoo.gr.jp/transdocs/udevrules/udevrules.html
- https://hana-shin.hatenablog.com/entry/2022/04/28/223022
- https://gihyo.jp/admin/serial/01/ubuntu-recipe/0555