udev (正體中文)

From ArchWiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Tango-preferences-desktop-locale-modified.png這個文章或章節的 翻譯 沒有對應到原文章的內容。Tango-preferences-desktop-locale-modified.png

原因: please use the first argument of the template to provide a brief explanation. (請在 Talk:Udev (正體中文) 中討論)

Tango-preferences-desktop-locale.png本條目或段落需要進行翻譯Tango-preferences-desktop-locale.png

註記: please use the first argument of the template to provide more detailed indications. (討論)

“udev”是一個用戶空間系統,它使操作系統管理員能夠為事件註冊用戶空間處理程序。 udevnowiki'/nowikis 守護進程接收到的事件主要由 (Linux) 內核生成,以響應與外圍設備相關的物理事件。因此,udevnowiki'/nowikis 的主要目的是進行外圍檢測和熱插拔,包括將控制權返回給內核的操作,例如加載內核模塊或設備固件。

作為 devfsdhotplug 的繼承者,udev 還通過添加、符號鏈接和重命名來管理 /dev 目錄中的設備節點。 udev 取代了 hotplughwdetect 的功能。

udev 同時(並行)處理單獨的事件,從而導致比舊系統的潛在性能改進。同時,這會使系統管理複雜化,因為例如,內核模塊加載順序不會跨引導保留。如果機器有多個塊設備,這可能會以設備節點在重啟後更改名稱的形式表現出來。例如,如果機器有兩個硬盤驅動器,/dev/sda

可能在下次啟動時變成 /dev/sdb。有關這方面的更多信息,請參見下文。

安裝

udevsystemd 的一部分,因此默認安裝。有關信息,請參閱 systemd-udevd.service(8)。一個獨立的 fork 可以作為 eudevAUReudev-gitAUR 使用。

關於udev規則

udev 由管理員編寫的規則放在 /etc/udev/rules.d/ 中,它們的文件名必須以 .rules 結尾。各種軟件包附帶的“udev”規則可以在 /usr/lib/udev/rules.d/ 中找到。如果 /usr/lib/etc 下有兩個同名文件,則 /etc 中的文件優先。

udev 規則示例

以下是在連接網絡攝像頭時創建符號鏈接 /dev/video-cam 的規則示例。假設此攝像機當前已連接並加載了設備名稱 /dev/video2。編寫此規則的原因是在下次啟動時,設備可能會以不同的名稱顯示,例如 /dev/video0

$ udevadm info --attribute-walk --path=$(udevadm info --query=path --name=/dev/video2)
Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices.It prints for every device found, all possible attributes in the udev rules key format.A rule to match, can be composed by the attributes of the device and the attributes from one single parent device.looking at device '/devices/pci0000:00/0000:00:04.1/usb3/3-2/3-2:1.0/video4linux/video2':  KERNEL=="video2"  SUBSYSTEM=="video4linux"   ...looking at parent device '/devices/pci0000:00/0000:00:04.1/usb3/3-2/3-2:1.0':  KERNELS=="3-2:1.0"  SUBSYSTEMS=="usb"  ...looking at parent device '/devices/pci0000:00/0000:00:04.1/usb3/3-2':  KERNELS=="3-2"  SUBSYSTEMS=="usb"  ATTRS{idVendor}=="05a9"  ATTRS{manufacturer}=="OmniVision Technologies, Inc."  ATTRS{removable}=="unknown"  ATTRS{idProduct}=="4519"  ATTRS{bDeviceClass}=="00"  ATTRS{product}=="USB Camera"  ...

為了識別網絡攝像頭,我們使用 KERNEL=='video2'SUBSYSTEM=='video4linux'video4linux 設備,然後向上走兩層,我們使用來自 USB 父級 SUBSYSTEMS=='usb' 的供應商和產品 ID 匹配網絡攝像頭,ATTRS{idVendor}=="05a9"ATTRS{idProduct}=="4519". 我們現在可以為該設備創建規則匹配,如下所示:

/etc/udev/rules.d/83-webcam.rules
KERNEL=="video[0-9]*", SUBSYSTEM=="video4linux", SUBSYSTEMS=="usb", ATTRS{idVendor}=="05a9", ATTRS{idProduct}=="4519", SYMLINK+="video-cam"

這裡我們使用 SYMLINK+='video-cam' 創建符號鏈接,但我們可以使用 GROUP 輕鬆設置用戶

OWNER='john' 或組='video' 或使用 MODE='0660' 設置權限。

如果您打算編寫規則以在移除設備時執行某些操作,請注意可能無法訪問設備屬性。在這種情況下,您將不得不使用預設設備 environment variables 環境變量。要監視這些環境變量,請在拔下設備時執行:

$ udevadm monitor --environment --udev

在此命令的輸出中,您將看到 ID_VENDOR_IDID_MODEL_ID 等值對,它們與之前使用的屬性 idVendoridProduct 匹配。使用設備環境變量而不是設備屬性的規則可能如下所示:

/etc/udev/rules.d/83-webcam-removed.rules
ACTION=="remove", SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="05a9", ENV{ID_MODEL_ID}=="4519", RUN+="/path/to/your/script"

列出設備的屬性

要獲取可用於編寫規則的設備的所有屬性的列表,請運行以下命令: $ udevadm 信息 --attribute-walk --name=device_namedevice_name 替換為系統中存在的設備,例如 /dev/sda/dev/ttyUSB0。如果您不知道設備名稱,您還可以列出特定係統路徑的所有屬性:

$ udevadm 信息 --attribute-walk --path=/sys/class/backlight/acpi_video0

要縮小對設備的搜索範圍,請找出類並運行:

$ ls /dev/class/by-id

您可以直接使用符號鏈接或它所指向的內容作為 --name 的輸入。例如:

$ udevadm info --attribute-walk --name=/dev/input/by-id/usb-foostan_Corne-event-kbd

加載前測試規則

  1. udevadm 測試 $(udevadm info --query=path --name=device_name) 2&1這不會在您的新規則中執行所有操作,但它會處理現有設備上的符號鏈接規則,如果您無法加載它們,這些規則可能會派上用場。您還可以直接提供要測試“udev”規則的設備的路徑: # udevadm 測試 /sys/class/backlight/acpi_video0/

加載新規則

udev 會自動檢測對規則文件的更改,因此更改會立即生效,而無需重新啟動 udev。但是,規則不會在現有設備上自動重新觸發。熱插拔設備,例如 USB 設備,可能需要重新連接才能使新規則生效,或者至少卸載並重新加載 ohci-hcd 和 ehci-hcd 內核模塊,從而重新加載所有 USB 驅動程序。如果規則無法自動重新加載:

# udevadm control --reload

要手動強制 udev 觸發您的規則:

# udevadm trigger

udisks

udisks

提示和技巧

在規則中安裝驅動器

要掛載可移動驅動器,不要從 udev 規則調用 mount。這是不明智的,原因有兩個:(1) systemd 默認運行 systemd-udevd.service 並帶有單獨的“掛載命名空間”(參見 namespaces(7)),這意味著安裝對系統的其餘部分不可見。 (2) 即使你改變服務參數來解決這個問題(註釋掉 PrivateMountsMountFlags 行),還有另一個問題是從 Udev 啟動的進程在一個幾秒鐘。對於 FUSE 文件系統,例如 NTFS,'mount' 會啟動一個用戶空間進程來處理文件系統內部; 當它被殺死時,如果您嘗試訪問文件系統,您將收到 Transport endpoint not connected 錯誤。

有一些選項有效:

  • 從 Udev 規則啟動自定義 systemd 服務; systemd 服務可以調用一個腳本,該腳本可以啟動任意數量的長時間運行的進程(如

FUSE)。在 /media 下自動掛載 U 盤的簡潔示例是 [https://github.com/Ferk/udev-media-automount udev-media-automount]。它被發現是快速和可靠的。 blog post[失效連結 2021-11-19 ⓘ] 中解釋了相同想法的一個變體。* 在您的 Udev 規則中使用 systemd-mount 而不是 mount。這是 [https://github.com/systemd/systemd/issues/11982#issuecomment-472529566 systemd 開發者推薦的]。例如,這個 Udev 規則應該在“/media”下掛載 USB 磁盤:

ACTION=="add", SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", RUN{program}+="/usr/bin/systemd-mount --no-block --automount=yes --collect $devnode /media"

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: This statement should be backed up with references. (Discuss in Talk:Udev (正體中文)#Mounting drives in rules)

:

然而,在撰寫本文時,它被發現速度緩慢且不可靠。* 使用 udisksudiskie 之類的包。這些功能非常強大,但很難設置。此外,它們旨在用於單用戶會話,因為它們使某些文件系統在會話當前處於活動狀態的非特權用戶的所有權下可用。

訪問固件編程器和 USB 虛擬通信設備

以下規則將允許 users 組中的用戶訪問 AVR 微控制器的 USBtinyISP USB 編程器。

/etc/udev/rules.d/50-usbtinyisp.rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c9f", GROUP="users", MODE="0660"SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="0479", GROUP="users", MODE="0660"

使用“lsusb”獲取其他設備的供應商和產品 ID。

在 VGA 電纜插件上執行

使用以下內容創建規則 /etc/udev/rules.d/95-monitor-hotplug.rules 以在插入 VGA 監視器電纜時啟動 arandr:KERNEL== 'card0', SUBSYSTEM=='drm', ENV{DISPLAY}=':0', ENV{XAUTHORITY}='/home/username/.Xauthority', RUN+='/usr/bin/arandr'一些顯示管理器將 .Xauthority 存儲在用戶主目錄之外。您需要相應地更新

ENV{XAUTHORITY}。例如 GNOME Display Manager 如下所示:

$ printenv 
XAUTHORITY
/run/user/1000/gdm/Xauthority

檢測新的 eSATA 驅動器

如果在插入 eSATA 驅動器時未檢測到它,您可以嘗試一些方法。您可以在插入 eSATA 的情況下重新啟動。或者您可以嘗試:# echo 0 0

0 | tee /sys/class/scsi_host/host*/scan 或者您可以安裝 scsiaddAUR(來自 

AUR)並嘗試:# scsiadd -sHopefully,您的驅動器現在在 /dev 中。如果不是,您可以在運行時嘗試上述命令:# udevadm monitor 以查看是否確實發生了任何事情。

將內部 SATA 端口標記為 eSATA

如果您連接了 eSATA 托架或其他 eSATA 適配器,系統將仍然將此磁盤識別為內部 SATA 驅動器。 

GNOMEKDE 會一直詢問你的 root 密碼。以下規則會將指定的 SATA-Port 標記為外部 eSATA-Port。這樣,普通的 GNOME 用戶就可以像 USB 驅動器一樣將他們的 eSATA 驅動器連接到該端口,而無需任何 root

密碼等。

/etc/udev/rules.d/10-esata.rules
DEVPATH=="/devices/pci0000:00/0000:00:1f.2/host4/*", ENV{UDISKS_SYSTEM}="0"
註記: 使用以下命令連接 eSATA 驅動器後可以找到 DEVPATH(相應地替換 sdb):
$ udevadm info --query=path /dev/sdb
/devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0/block/sdb
$ find /sys/devices/ -name sdb
/sys/devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0/block/sdb

設置靜態設備名稱

因為 udev 異步加載所有模塊,所以它們以不同的順序初始化。這可能會導致設備隨機切換名稱。可以添加“udev”規則以使用靜態設備名稱。對於塊設備,另見持久塊設備命名和對於網絡設備的網絡配置#更改接口名稱

影像設備

首先要設置網絡攝像頭,請參閱網絡攝像頭設置。使用多個網絡攝像頭會在啟動時隨機分配視頻設備為/dev/video*。推薦的解決方案是使用 #udev 規則示例 中的“udev”規則創建符號鏈接:

/etc/udev/rules.d/83-webcam.rules
KERNEL=="video[0-9]*", SUBSYSTEM=="video4linux", SUBSYSTEMS=="usb", ATTRS{idVendor}=="05a9", ATTRS{idProduct}=="4519", SYMLINK+="video-cam1"KERNEL=="video[0-9]*", SUBSYSTEM=="video4linux", SUBSYSTEMS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="08f6", SYMLINK+="video-cam2"
註記: Using names other than /dev/video* will break preloading of v4l1compat.so and perhaps v4l2convert.so

印表機

如果您使用多台打印機,/dev/lp[0-9] 設備將在啟動時隨機分配,這會破壞例如CUPS 配置。您可以創建以下規則,該規則將在 /dev/lp/by-id/dev/lp/by-path

下創建符號鏈接,類似於 [[Persistent Block Device Naming] ] 方案:

/etc/udev/rules.d/60-persistent-printer.rules
ACTION=="remove", GOTO="persistent_printer_end"# This should not be necessary#KERNEL!="lp*", GOTO="persistent_printer_end"SUBSYSTEMS=="usb", IMPORT{builtin}="usb_id"ENV{ID_TYPE}!="printer", GOTO="persistent_printer_end"ENV{ID_SERIAL}=="?*", SYMLINK+="lp/by-id/$env{ID_BUS}-$env{ID_SERIAL}"IMPORT{builtin}="path_id"ENV{ID_PATH}=="?*", SYMLINK+="lp/by-path/$env{ID_PATH}"LABEL="persistent_printer_end"

通過序列號識別磁盤

在特定的磁盤設備 /dev/sdX 上執行某些操作,該設備由其唯一的序列 ID_SERIAL_SHORT

永久標識,如 udevadm info /dev/sd X,可以使用下面的規則。它將找到的設備名稱作為參數傳遞以說明:

/etc/udev/rules.d/69-disk.rules
ACTION=="add", KERNEL=="sd[a-z]", ENV{ID_SERIAL_SHORT}=="X5ER1ALX", RUN+="/path/to/script /dev/%k"

使用 USB 設備從掛起狀態中喚醒

udev 規則可用於啟用 USB 設備(如鼠標或鍵盤)的喚醒功能,以便它可用於將機器從睡眠中喚醒。

註記: 默認情況下,USB 主機控制器都啟用了喚醒功能。可以使用 cat /proc/acpi/wakeup檢查狀態. 下面的規則在這種情況下不是必需的,但可以用作執行其他操作的模板,例如禁用喚醒功能。

首先,識別 USB 設備的供應商和產品標識符。它們將用於在 udev 規則中識別它。例如:

$ lsusb | grep Logitech
Bus 007 Device 002: ID 046d:c52b Logitech, Inc. Unifying Receiver

然後,找到設備連接到的位置:

$ grep c52b /sys/bus/usb/devices/*/idProduct
/sys/bus/usb/devices/1-1.1.1.4/idProduct:c52b

現在創建規則來更改設備和它所連接的 USB 控制器的 power/wakeup 屬性,無論何時添加:

/etc/udev/rules.d/50-wake-on-device.rules
ACTION=="add", SUBSYSTEM=="usb", DRIVERS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c52b", ATTR{power/wakeup}="enabled", ATTR{driver/1-1.1.1.4/power/wakeup}="enabled"

觸發事件

Merge-arrows-2.pngThis article or section is a candidate for merging with #這是關於如何硬編碼變量的冗長獨白.Merge-arrows-2.png

Notes: please use the second argument of the template to provide more detailed indications. (Discuss in Talk:Udev (正體中文))

觸發各種“udev”事件很有用。例如,您可能想要在遠程機器上模擬 USB 設備斷開連接。在這種情況下,使用 udevadm trigger

  1. udevadm trigger --verbose --type=subsystems --action=remove --subsystem-match=usb --attr-match="idVendor=abcd"

此命令將在供應商 ID abcd 的所有 USB 設備上觸發 USB 移除事件。

從 udev 規則觸發桌面通知

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: 這是關於如何硬編碼變量的冗長獨白 (Discuss in Talk:Udev (正體中文))

通過“udev”調用包含對 notify-send 的調用的外部腳本有時可能具有挑戰性,因為通知) 永遠不會顯示在桌面上。 下面是一個示例,說明需要在哪些文件中包含哪些命令和環境變量才能根據“udev”規則成功執行 notify-send

註記: 在此示例中,許多變量是硬核碼的,因此一旦您理解了示例,請考慮使它們具有可移植性(即 $USER 而不是用戶的短名稱)。

1) 以下“udev”規則執行一個腳本,當屏幕亮度根據筆記本電腦的電源狀態改變時,該腳本播放通知聲音並發送桌面通知。創建文件:

/etc/udev/rules.d/99-backlight_notification.rules
# Rule for when switching to batteryACTION=="change", SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="0", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/USERNAME/.Xauthority" RUN+="/usr/bin/su USERNAME_TO_RUN_SCRIPT_AS -c /usr/local/bin/brightness_notification.sh"# Rule for when switching to ACACTION=="change", SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="1", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/USERNAME/.Xauthority" RUN+="/usr/bin/su USERNAME_TO_RUN_SCRIPT_AS -c /usr/local/bin/brightness_notification.sh"

* USERNAME_TO_RUN_SCRIPT_ASUSERNAME

需要更改為顯示通知的圖形會話用戶的短名稱;* 腳本需要使用 執行/usr/bin/su,它將把它的所有權歸於圖形會話的用戶(而不是

root/系統),在那裡將顯示通知。2)在觸發時運行的可執行腳本的內容“udev”規則:

/usr/local/bin/brightness_notification.sh
#!/usr/bin/env bashexport XAUTHORITY=/home/USERNAME_TO_RUN_SCRIPT_AS/.Xauthorityexport DISPLAY=:0export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/UID_OF_USER_TO_RUN_SCRIPT_AS/bus"/usr/bin/sudo -u USERNAME_TO_RUN_SCRIPT_AS /usr/bin/paplay --server=/run/user/UID_OF_USER_TO_RUN_SCRIPT_AS/pulse/native /home/USERNAME/.i3/sounds/Click1.wav > /dev/null 2>&1/usr/bin/notify-send --icon=/usr/share/icons/gnome/256x256/status/battery-full-charging.png 'Changing Power States' --expire-time=4000

* USERNAME_TO_RUN_SCRIPT_AS, UID_OF_USER_TO_RUN_SCRIPT_ASUSERNAME

需要更改為用戶的短名稱和將顯示通知的圖形會話的用戶 UID;* /usr/通過pulseaudio播放音頻時需要bin/sudo;*圖形用戶的三個環境變量(即XAUTHORITYDISPLAYDBUS_SESSION_BUS_ADDRESS)需要定義和導出將顯示通知的會話。

提示: 另見 xpubAUR 作為獲取用戶顯示環境變量並通過 IMPORT 鍵將最後一個導出到 udev 規則的方法。

3) 加載/重新加載新的 udev 規則(見上文)並通過拔掉筆記本電腦的電源進行測試。=== 生成長時間運行的進程

=== udev 啟動的程序將阻止來自該設備的更多事件,以及任何事件處理完成後,從 udev 規則產生的任務將被終止。如果您需要使用 udev 生成長時間運行的進程,您可以使用 at(例如 your_command | at now,或 batch),或創建一個 systemd 單元 [https://blog.fraggod.net/2012/06/16/proper-ish-way-to-start-long-running-systemd-service-on-udev-event-[失效連結 2021-11-19 ⓘ]

device-hotplug.html 可以直接從 udev 規則觸發]。

故障排除

將模塊列入黑名單 === 在極少數情況下,“udev”可能會出錯並加載錯誤的模塊。為了防止它這樣做,您可以 blacklist 模塊。一旦被列入黑名單,“udev”將永遠不會加載該模塊——不會在啟動時加載,甚至不會在收到熱插拔事件時(例如,插入 USB 閃存驅動器)。

故障排除

要獲取硬件 debug 信息,請使用 kernel parameter

udev.log-priority=debug。或者,您可以設置

/etc/udev/udev.conf
udev_log='debug'

此選項也可以通過將配置文件添加到您的 FILES 數組來編譯到您的 initramfs 中

/etc/mkinitcpio.conf
FILES='...
 /etc/udev/udev.conf'

然後重新生成 initramfs

在啟動時掛起

遷移到 LDAP 或更新 LDAP 支持的系統後,“udevd”可能會在引導時掛起,顯示消息“正在啟動 UDev 守護進程”。這通常是由於 udevd 嘗試從 LDAP 查找名稱但失敗,因為網絡尚未啟動。解決方案是確保所有系統組名都在本地存在。提取“udev”規則中引用的組名和系統上實際存在的組名: # grep -Fr GROUP /etc/udev/rules.d/ /usr/lib/udev/rules.d/ | sed 's:.*GROUP="\([-a-z_]\{1,\}\)".*:\1:' | sort -u >udev_groups # cut -d: -f1 /etc/gshadow /etc/group | sort -u >present_groups 要查看差異,請並排比較:

  1. diff -y present_groups udev_groups ... network < nobody < ntp < optical optical power | pcscd rfkill < root root scanner scanner smmsp < storage storage ...

在這種情況下,pcscd 組由於某種原因不在系統中。 添加缺少的群組。此外,請確保在使用 LDAP 之前查找本地資源。 /etc/nsswitch.conf 應包含以下行: group: files ldap

一些應該被視為可移動的設備, 不是

您需要為該特定設備創建自定義的“udev”規則。要獲得設備的明確信息,您可以使用 ID_SERIALID_SERIAL_SHORT(如果需要,請記住更改 /dev/sdb): $ udevadm info /dev/

sdb | grep 

ID_SERIAL然後我們在/etc/udev/rules.d/中創建一個規則並為udisks或udisks2設置變量。對於udisks,設置UDISKS_SYSTEM_INTERNAL='0',即將設備標記為“可移動”,因此“有資格自動安裝”。有關詳細信息,請參閱

udisks(7)

/etc/udev/rules.d/
 
50-external-myhomedisk.rules
ENV{ID_SERIAL_SHORT}==serial_number,
 ENV{UDISKS_SYSTEM_INTERNAL}='0'

對於udisks2,設置{{ic|1=UDISKS_AUTO='1'} }

將設備標記為自動掛載,UDISKS_SYSTEM='0' 將設備標記為“可移動”。詳見

udisks(8)

/etc/udev/rules.d/99-removable.rules
ENV{ID_SERIAL_SHORT}==serial_number,
 ENV{ UDISKS_AUTO}='1', ENV{UDISKS_SYSTEM}='0'

記得用udevdm control

--reload重新加載udev規則。下次插入設備時,它將被視為外部驅動器。

某些模塊未自動加載的聲音問題

一些用戶將這個問題追溯到 /etc/modprobe.d/sound.conf

中的舊條目。嘗試清除該文件並重試。

註記: Since udev=171, OSS 仿真模塊

(snd_seq_oss, snd_pcm_oss, snd_mixer_oss)

默認不會自動加載。

IDE CD/DVD 驅動器支持

從版本 170 開始,udev 不支持 CD-ROM/DVD-ROM 驅動器,這些驅動器通過 ide_cd_mod 模塊作為傳統 IDE 驅動器加載並顯示為 /dev/hd *。該驅動器仍可用於直接訪問硬件的工具,例如 cdparanoia,但對於更高的用戶空間程序(例如 KDE)不可見。導致 ide_cd_mod 模塊先於其他模塊加載,例如 sr_mod,可能是例如由於某種原因,模塊 piix 加載了 initramfs。在這種情況下,您可以將它替換為 /etc/mkinitcpio.conf 中的 ata_piix。=== 光驅的組 ID 設置為“磁盤” ===如果您的光驅的組 ID 是設置為 disk 並且你想把它設置為

optical,你必須創建一個自定義的 udev 規則:

/etc/udev/rules.d 
nowiki#
 IDE CD 設備的權限SUBSYSTEMS=='ide', KERNEL=='hd[az]', ATTR{removable}=='1', 
ATTRS{media}=='cdrom*', GROUP=' SCSI CD 設備的光學'# 權限SUBSYSTEMS=='scsi', 
KERNEL=='s[rg][0-9]*', ATTRS{type}=='5', GROUP='optical'/nowiki

See also

以下爲原本中文版本

其他關於 udev 的資訊可以參考下面的連接 :

要把系統轉換到 Udev 下,你需要執行下列幾個步驟.

安裝 udev 套件

pacman -S udev

編輯 /etc/fstab

請先把 sysfs 這一行設定註解掉,然後 "usbdevfs" 這一行設定必須改為使用 "usbfs" (在同一行內有兩個地方要修改). 最後, 請檢查 /etc/fstab 內是否一行設定包含了 /dev/shm 這個指定. 在編輯完 /etc/fstab 後,上面提到的這幾行應該看起來如同下面列出的一般 :

#sysfs /sys sysfs defaults 0 0
usbfs /proc/bus/usb usbfs defaults 0 0
none /dev/shm tmpfs defaults 0 0
none /dev/pts devpts defaults 0 0

你可能還需要把 /etc/fstab 這個檔案內的其他設定也依照上面的解釋一併修正,以符合 udev 的命名規則.

Make sure you use the /dev/hda1 format and not /dev/discs/disc0/part1 in /etc/fstab or you will get a false report of corrupt disk on booting.

重新開機

大功告成, 系統轉換完畢.

警告 : 無法開啟一個 initial console

如果你的系統在開機載入核心時當機並出現下面這一行警告訊息

WARNING: Unable to open an initial console
  • 拿出你的 Arch Linux 安裝光碟然後用他來開機
  • 掛載上你的 root 硬碟分割區 (例如 : "mount /dev/discs/disc0/part3 /mnt")
  • 鍵入 chroot 轉移到新的掛載目錄上 (例如 : "chroot /mnt")
  • 用下面的指令在 /dev 下建立缺少的 static nodes (靜態節點) :
cd /dev
mknod -m 660 console c 5 1
mknod -m 660 null c 1 3

These nodes are required for starting Udev. You might have both/only one of them/none missing.

More information here.

系統一直連續重啟不停

如果你的系統一直不停的連續重啟, 你可能需要把 menu.lst 裡面的下面這一行移除 :

devfs=nomount

然後當系統啟動完畢後, 請在終端機模式的命令列下鍵入:

/sbin/migrate-udev

現在,你可以再把 devfs=nomount 這一行放回 menu.lst 這個檔案內然後重新啟動系統. 這應該可以解決系統連續重啟的問題.

使用者自訂 Udev

When udev starts up, it will read all .rules files in /etc/udev/rules.d/. When udev is adding a device node, it reads these rules files in lexicographical order until it finds a match. That means that if you need any customizations, you should create a file that is lexicographically-less than the default file, udev.rules. It is the Arch custom to use 00.rules for customizations, but obviously you can be more creative if you wish.

You should not edit the /etc/udev/rules.d/udev.rules file yourself, as it is used by the developers to improve the default ruleset for new users. If you need to tweak a rule from the default ruleset, just copy the line(s) and paste them into a 00.rules file.

下面這一部份只適用於 udev >= 053

編輯權限和規則

The latest version of udev has some upstream changes in the configuration layout.

Permissions and user/group ownership are no longer defined in separate files -- instead they are specified within the rules file itself. Look at /etc/udev/rules.d/udev.rules for examples.

This means that any custom permissions need to be moved into a rules file like /etc/udev/rules.d/udev.rules or /etc/udev/rules.d/00-my.rules. The old files in etc/udev/permissions.d/ have no effect anymore and can be removed.

See the udev(8) manpage for more information on writing rules. The files in etc/udev/permissions.d/ have no effect anymore and can be removed.

The normal user should not need to define new rules, all you have to do is to add the user to the right groups in /etc/group:

gpasswd -a <username> video
gpasswd -a <username> audio
gpasswd -a <username> optical
gpasswd -a <username> floppy
gpasswd -a <username> storage
gpasswd -a <username> scanner

關於 group 權限的解說 :

video: enable tv cards, framebuffer devices (not! graphic cards they belong to users group)
audio: get access to sound devices and rtc
optical: allow burning and ripping from cd/dvd devices
floppy: allow formating and partitioning on floppy devices
storage: allow formating and partitioning on removable storage devices, like usbsticks or usb harddrives.
scanner: allow using the scanner devices

Symlinks of cd/dvd devices are done automatically and should fit your needs.

已知的問題:

  • 如果你更新到 udev >=053 同時系統無法辨識你的 usb 拇指碟,請記得從新開機,然後一切應該都會恢復正常了

Symlinking devices

this is only an example but it should be clear how it works. Add this at the /etc/udev/rules.d/00-myrules.rules:

# cdrom/cdrw links
KERNEL="hdc", SYMLINK="dvd"
KERNEL="hdd", SYMLINK="cdrom cdrecorder"
#important for modem users, change to ttyS1 if serial port 2 is used
KERNEL="ttyS0", SYMLINK="modem"

to check if your symlinks work or to restart udev:

/sbin/udevstart

更多關於規則的設定的資料請參閱:
http://www.reactivated.net/udevrules.php

相關資料