Eudev

From Gentoo Wiki
Jump to: navigation, search
This page is a translated version of the page Eudev and the translation is 58% complete.

Other languages:
English • ‎español • ‎français • ‎polski • ‎русский • ‎中文(中国大陆)‎ • ‎日本語

Warning: Display title "eudev/zh-cn" overrides earlier display title "Eudev".

Resources

For configurations not using systemd, eudev is Gentoo's device file manager for the Linux kernel.[1] It manages device nodes in /dev and handles all user space actions when adding or removing devices. It is a fork of systemd's udev with the goal of obtaining better compatibility with existing software such as OpenRC, Upstart, older kernels, various toolchains, and anything else required[2] by (but not well supported through) udev. Configurations utilizing systemd should not use it.

/dev目录

大多数Linux用户都知道 /dev/sda1 只是内核找到的第一个磁盘上的第一个分区的快速方法。这很简单,对吧?

但请考虑USB,IEEE 1394,热插拔PCI等热插拔设备。这些设备的第一个设备是什么?而且持续多久?当第一个设备消失时,其他设备会被命名为什么?这将如何影响正在进行的事务?如果一个打印作业突然从高端激光打印机转移到几乎死机的矩阵打印机,仅仅是因为有人决定拔下激光打印机上的插头(恰好是第一台打印机),这会不会很有趣?

进入设备管理器。一个现代设备管理器(包括 udeveudev)必须:

  • 在用户空间中运行;
  • 动态创建和删除device file
  • 提供一致的设备命名;
  • 提供用户空间应用程序接口(API)。

每当设备结构发生变化时,内核都会发出一个由设备管理器获取的 uevent ,然后设备管理器遵循 /etc/udev/rules.d, /run/udev/rules.d/lib/udev/rules.d 目录中声明的规则,根据uevent中包含的信息,它会找到触发和执行所需操作所需的规则。这些动作可能涉及设备文件的创建或删除,还可能触发将特定固件文件加载到内核内存中。

安装

USE 标记

Some packages know the udev USE flag for enabling virtual/udev integration.

USE flags for sys-fs/eudev Linux dynamic and persistent device naming support (aka userspace devfs)

hwdb read vendor/device string database and add it to udev database local
introspection Add support for GObject based introspection global
kmod enable module loading through libkmod local
rule-generator install legacy rule generator rules and support scripts - note that the functionality within was dropped from sys-fs/udev as it is not stable in all cases; use at your own risk local
static-libs Build static versions of dynamic libraries as well global

Emerge

To avoid registration in the world set, the oneshot option should be used.

root #emerge --ask --oneshot sys-fs/eudev

配置

RC服务

The RC name is udev, not eudev. It needs to be registered in the sysinit runlevel.

root #rc-update add udev sysinit
 * rc-update: udev already installed in runlevel `sysinit'; skipping

From sys-fs/udev-init-scripts version 29 onward, udev-trigger should also be added to the sysinit runlevel.

Migrating from udev to eudev

Migrating from udev 216 to eudev 1.10-r2 (March 2015) is straight forward:

root #emerge --ask --oneshot sys-fs/eudev

In case the system uses multilib and, for example, has the abi_x86_32 USE flag active against the older udev package, then don't forget to change it too:

FILE /etc/portage/package.use在 package.use 从 udev 到eudev
# sys-fs/udev abi_x86_32
sys-fs/eudev abi_x86_32

Keep classic 'eth0' naming

内核提供的网络设备名称 eth0, wlan0 等可以通过 /lib/udev/rules.d/80-net-name-slot.rules udev 规则在启动时更改参见 dmesg

为了保持经典的命名,这个规则可以用 /etc/udev/rules.d 目录中用同样命名的空文件覆盖:

root #touch /etc/udev/rules.d/80-net-name-slot.rules

Alternatively add net.ifnames=0 to the kernel command line, change the default policy or create a custom one.

An interesting resource related to the network naming is I don't like this, how do I disable this on the Freedesktop wiki.

Use new 'predictable' naming

The new network interface naming convention is not the same so interfaces will need to be re-linked. Use /etc/init.d/net.lo as a link target for whatever interface names need to be added. Be sure to replace <interface_name> in the commands below with the Ethernet interface names present on the system. It is possible to discover which interfaces exist by running the ifconfig command:

user $ifconfig

Create symbolic links for the existing interfaces in the /etc/init.d/ and /etc/conf.d/ directories:

root #ln -s /etc/init.d/net.lo /etc/init.d/net.<interface_name>
root #ln -s /etc/conf.d/net.lo /etc/conf.d/net.<interface_name>

Add the script(s) to the default runlevel to have the interface(s) start automatically:

root #rc-update add net.<interface_name> default

故障排除

使用 udevadm

开始 udevadm monitor 并且观察发生的变化:

user $udevadm monitor

Get device info using udevadm info followed by the device path:

user $udevadm info -p /devices/pci0000:00/0000:00:1d.7

Get the device path using its name:

user $udevadm info -q path -n input/mouse1
/devices/pci0000:00/0000:00:1d.7/usb1/1-3/1-3.4/1-3.4:1.0/0003:046D:C404.0006/input/input24/mouse1

Test an event run using udevadm test followed by the device path for which an event is to be tested:

user $udevadm test /devices/pci0000:00/0000:00:1d.7

To get a list of all udevadm commands:

user $udevadm -h

Migrating older releases

从 udev 171-r10 到 eudev 1.2-r1

在 Gentoo 论坛上查看 这个帖子

Broken system switching from udev to eudev

在 Gentoo 论坛上查看 这个帖子

另请参阅

外部资源

参考

  1. Bug 575718 - Request for council decision RE virtual/udev default provider, Gentoo's Bugzilla Main Page, (Last modified) February 27th, 2016. Retrieved on March 1st, 2016.
  2. Project:Eudev, Gentoo Wiki, (Last modified) November 12th, 2015. Retrieved on March 11th, 2016.