- This chapter discusses configuration files and systemd services.
- First, the general configuration files needed to set up networking
- are presented.
+ 本章讨论了配置文件及 systemd 服务。首先是设置网络所需的通用配置文件。
Home
+ "Linux From Scratch - Version 8.0-systemd">首页
- 7.4.
- Managing Devices
+ 7.4. 管理设备
- 7.4.1. Dealing with duplicate devices
+ 7.4.1. 重复设备的处理
- As explained in Section 7.3,
- “Overview of Device and Module Handling”, the order
- in which devices with the same function appear in /dev is essentially random. E.g., if you have a
- USB web camera and a TV tuner, sometimes /dev/video0 refers to the camera and /dev/video1 refers to the tuner, and sometimes
- after a reboot the order changes to the opposite one. For all
- classes of hardware except sound cards and network cards, this is
- fixable by creating Udev rules for custom persistent symlinks. The
- case of network cards is covered separately in Section 7.2,
- “General Network Configuration”, and sound card
- configuration can be found in
- BLFS.
+ 如 7.3 “设备及模块管理综述” 中所述,/dev 中显示的具有相同功能的设备的顺序基本上是随机的。例如,如果您有 USB 网络摄像机和电视调谐器,有时 /dev/video0 指摄像机同时 /dev/video1 指调谐器,有时在重新启动后,顺序变为相反的。对于除了声卡和网卡的所有类别的硬件,可以通过自定义持久性符号链接创建 Udev 规则来修复。网卡的情况将在 7.5 “通用网络配置” 中谈到,声卡配置可以在 BLFS 中找到。
- For each of your devices that is likely to have this problem (even
- if the problem doesn't exist in your current Linux distribution),
- find the corresponding directory under /sys/class or /sys/block. For video devices, this may be
- /sys/class/video4linux/videoX. Figure out the attributes
- that identify the device uniquely (usually, vendor and product IDs
- and/or serial numbers work):
+ 对于每个可能出现此问题的设备(即使您当前的 Linux 发行版中不存在问题),请在 /sys/class 或 /sys/block 下找到相应的目录。对于视频设备,目录可能是 /sys/class/video4linux/videoX。找出能够唯一标识设备的属性(通常,供应商和产品 ID 和/或序列号是有用的):
udevadm info -a -p /sys/class/video4linux/video0
- Then write rules that create the symlinks, e.g.:
+ 然后编写创建符号链接的规则,例如:
EOF
- The result is that /dev/video0 and
- /dev/video1 devices still refer
- randomly to the tuner and the web camera (and thus should never be
- used directly), but there are symlinks /dev/tvtuner and /dev/webcam that always point to the correct
- device.
+ 以上操作的结果是 /dev/video0 和 /dev/video1 设备仍然可能随机指向到调谐器和网络摄像机(因此不应该直接使用),但是符号链接 /dev/tvtuner 与 /dev/webcam 总是指向到正确的设备。
Home
+ "Linux From Scratch - Version 8.0-systemd">首页
- 7.3. Overview of
- Device and Module Handling
+ 7.3. 设备及模块管理综述
- In Chapter
- 6, we installed the Udev package when systemd was built. Before we go into the details
- regarding how this works, a brief history of previous methods of
- handling devices is in order.
+ 在第六章中,我们在 eudev 构建之后安装了 Udev 包。在我们详细了解它是如何工作之前,先简要介绍一下先前方法是如何进行设备管理的。
-
- Linux systems in general traditionally used a static device creation
- method, whereby a great many device nodes were created under
- /dev (sometimes literally thousands of
- nodes), regardless of whether the corresponding hardware devices
- actually existed. This was typically done via a MAKEDEV script, which contains a
- number of calls to the mknod program with the relevant
- major and minor device numbers for every possible device that might
- exist in the world.
+
- Using the Udev method, only those devices which are detected by the
- kernel get device nodes created for them. Because these device nodes
- will be created each time the system boots, they will be stored on a
- devtmpfs file system (a virtual file
- system that resides entirely in system memory). Device nodes do not
- require much space, so the memory that is used is negligible.
+
- In February 2000, a new filesystem called devfs was merged into the 2.3.46 kernel and was
- made available during the 2.4 series of stable kernels. Although it
- was present in the kernel source itself, this method of creating
- devices dynamically never received overwhelming support from the
- core kernel developers.
+
- The main problem with the approach adopted by devfs was the way it handled device detection,
- creation, and naming. The latter issue, that of device node naming,
- was perhaps the most critical. It is generally accepted that if
- device names are allowed to be configurable, then the device naming
- policy should be up to a system administrator, not imposed on them
- by any particular developer(s). The devfs file system also suffered from race
- conditions that were inherent in its design and could not be fixed
- without a substantial revision to the kernel. It was marked as
- deprecated for a long period – due to a lack of maintenance
- – and was finally removed from the kernel in June, 2006.
+
- With the development of the unstable 2.5 kernel tree, later
- released as the 2.6 series of stable kernels, a new virtual
- filesystem called sysfs came to be.
- The job of sysfs is to export a
- view of the system's hardware configuration to userspace processes.
- With this userspace-visible representation, the possibility of
- developing a userspace replacement for devfs became much more realistic.
+
- The sysfs filesystem was
- mentioned briefly above. One may wonder how sysfs knows about the devices present on a
- system and what device numbers should be used for them. Drivers
- that have been compiled into the kernel directly register their
- objects with a sysfs (devtmpfs
- internally) as they are detected by the kernel. For drivers
- compiled as modules, this registration will happen when the
- module is loaded. Once the sysfs
- filesystem is mounted (on /sys), data which the drivers register
- with sysfs are available to
- userspace processes and to udevd for processing (including
- modifications to device nodes).
+
- Device files are created by the kernel by the devtmpfs filesystem. Any driver that wishes
- to register a device node will go through the devtmpfs (via the driver core) to do it. When
- a devtmpfs instance is mounted on
- /dev, the device node will
- initially be created with a fixed name, permissions, and owner.
+
- A short time later, the kernel will send a uevent to udevd. Based on the rules
- specified in the files within the /etc/udev/rules.d, /lib/udev/rules.d, and /run/udev/rules.d directories, udevd will create additional
- symlinks to the device node, or change its permissions, owner, or
- group, or modify the internal udevd database entry (name) for
- that object.
+
- The rules in these three directories are numbered and all three
- directories are merged together. If udevd can't find a rule for the
- device it is creating, it will leave the permissions and
- ownership at whatever devtmpfs
- used initially.
+
- Device drivers compiled as modules may have aliases built into
- them. Aliases are visible in the output of the modinfo program and are usually
- related to the bus-specific identifiers of devices supported by a
- module. For example, the snd-fm801 driver supports PCI devices
- with vendor ID 0x1319 and device ID 0x0801, and has an alias of
- “pci:v00001319d00000801sv*sd*bc04sc01i*”.
- For most devices, the bus driver exports the alias of the driver
- that would handle the device via sysfs. E.g., the /sys/bus/pci/devices/0000:00:0d.0/modalias file
- might contain the string “pci:v00001319d00000801sv00001319sd00001319bc04sc01i00”.
- The default rules provided with Udev will cause udevd to call out to
- /sbin/modprobe with
- the contents of the MODALIAS uevent
- environment variable (which should be the same as the contents of
- the modalias file in sysfs), thus
- loading all modules whose aliases match this string after
- wildcard expansion.
+
- In this example, this means that, in addition to snd-fm801, the obsolete (and unwanted)
- forte driver will be
- loaded if it is available. See below for ways in which the
- loading of unwanted drivers can be prevented.
+
- When you plug in a device, such as a Universal Serial Bus (USB)
- MP3 player, the kernel recognizes that the device is now
- connected and generates a uevent. This uevent is then handled by
- udevd as described
- above.
+
- 7.3.3. Problems with Loading Modules and Creating Devices
+ 7.3.3. 关于加载模块和创建设备的问题
- There are a few possible problems when it comes to automatically
- creating device nodes.
+ 在自动创建设备节点时可能会出现一些问题。
- 7.3.3.1. A kernel module is not loaded automatically
+ 7.3.3.1. 内核模块未自动加载
-
- Udev will only load a module if it has a bus-specific alias and
- the bus driver properly exports the necessary aliases to
- sysfs. In other cases, one should
- arrange module loading by other means. With Linux-4.9.9, Udev is
- known to load properly-written drivers for INPUT, IDE, PCI, USB,
- SCSI, SERIO, and FireWire devices.
+
- To determine if the device driver you require has the necessary
- support for Udev, run modinfo with the module name as
- the argument. Now try locating the device directory under
- /sys/bus and check whether there is
- a modalias file there.
+
- If the modalias file exists in
- sysfs, the driver supports the
- device and can talk to it directly, but doesn't have the alias,
- it is a bug in the driver. Load the driver without the help from
- Udev and expect the issue to be fixed later.
+
- If there is no modalias file in the
- relevant directory under /sys/bus,
- this means that the kernel developers have not yet added modalias
- support to this bus type. With Linux-4.9.9, this is the case with
- ISA busses. Expect this issue to be fixed in later kernel
- versions.
+
- 7.3.3.2. A kernel module is not loaded automatically, and Udev is
- not intended to load it
+ 7.3.3.2. 内核模块未自动加载,且 Udev 不会进行加载
-
- If the “wrapper” module only enhances the
- functionality provided by some other module (e.g., snd-pcm-oss enhances the functionality
- of snd-pcm by making the
- sound cards available to OSS applications), configure
- modprobe to load
- the wrapper after Udev loads the wrapped module. To do this, add
- a “softdep” line in any /etc/modprobe.d/<filename>.conf
- file. For example:
+
- Note that the “softdep” command also allows
- pre: dependencies, or a mixture of
- both pre: and post:. See the modprobe.d(5) manual page for more information
- on “softdep” syntax and capabilities.
+
- If the module in question is not a wrapper and is useful by
- itself, configure the modules bootscript to load this
- module on system boot. To do this, add the module name to the
- /etc/sysconfig/modules file on a
- separate line. This works for wrapper modules too, but is
- suboptimal in that case.
+
- Either don't build the module, or blacklist it in a /etc/modprobe.d/blacklist.conf file as done
- with the forte module in
- the example below:
+
不要在 /etc/modprobe.d/blacklist.conf 文件中构建模块,或将其列入黑名单。如以下示例中的 forte 模块:
blacklist forte
-
- Blacklisted modules can still be loaded manually with the
- explicit modprobe
- command.
+
黑名单模块仍然可以使用显式的 modprobe 命令手动加载。
- 7.3.3.4. Udev creates a device incorrectly, or makes a wrong
- symlink
+ 7.3.3.4. Udev 创建设备不正确,或创建了错误的符号链接
-
- This usually happens if a rule unexpectedly matches a device. For
- example, a poorly-written rule can match both a SCSI disk (as
- desired) and the corresponding SCSI generic device (incorrectly)
- by vendor. Find the offending rule and make it more specific,
- with the help of the udevadm
- info command.
+
如果规则意外匹配了设备,则通常会发生这种情况。例如,写得不好的规则可以同时匹配供应商的 SCSI 磁盘(本应匹配)和相应的 SCSI 通用设备(不应匹配)。在 udevadm info 命令的帮助下,查找违规的规则并使其更具体化。
- 7.3.3.5. Udev rule works unreliably
+ 7.3.3.5. Udev 规则工作不可靠
-
- This may be another manifestation of the previous problem. If
- not, and your rule uses sysfs
- attributes, it may be a kernel timing issue, to be fixed in later
- kernels. For now, you can work around it by creating a rule that
- waits for the used sysfs
- attribute and appending it to the /etc/udev/rules.d/10-wait_for_sysfs.rules file
- (create this file if it does not exist). Please notify the LFS
- Development list if you do so and it helps.
+
- 7.3.3.6. Udev does not create a device
+ 7.3.3.6. Udev 未创建设备
-
- Further text assumes that the driver is built statically into the
- kernel or already loaded as a module, and that you have already
- checked that Udev doesn't create a misnamed device.
+
- Udev has no information needed to create a device node if a
- kernel driver does not export its data to sysfs. This is most common with third party
- drivers from outside the kernel tree. Create a static device node
- in /lib/udev/devices with the
- appropriate major/minor numbers (see the file devices.txt inside the kernel documentation or
- the documentation provided by the third party driver vendor). The
- static device node will be copied to /dev by udev.
+
- 7.3.3.7. Device naming order changes randomly after rebooting
+ 7.3.3.7. 设备命名顺序在重新启动后随机更改
-
- This is due to the fact that Udev, by design, handles uevents and
- loads modules in parallel, and thus in an unpredictable order.
- This will never be “fixed”. You should not rely upon the
- kernel device names being stable. Instead, create your own rules
- that make symlinks with stable names based on some stable
- attributes of the device, such as a serial number or the output
- of various *_id utilities installed by Udev. See Section 7.4, “Managing
- Devices” and Section 7.2,
- “General Network Configuration” for examples.
+
- The LFS-Bootscripts package contains a set of scripts to start/stop
- the LFS system at bootup/shutdown. The configuration files and
- procedures needed to customize the boot process are described in
- the following sections.
+ LFS 引导脚本软件包包括一系列用于在启动或关机过程中启动或停止 LFS 系统的脚本。以下部分将会介绍自定义引导过程所需的配置文件和过程。
- Approximate build time:
- less than 0.1 SBU
+ 预计构建时间:
+ 小于 0.1 SBU
- Required disk space:
+ 所需磁盘空间:244 KB
@@ -73,10 +69,10 @@
- 7.2.1. Installation of LFS-Bootscripts
+ 7.2.1. LFS 引导脚本的安装
- Install the package:
+ 安装软件包:
make install
@@ -85,27 +81,27 @@
7.2.2.
- Contents of LFS-Bootscripts
+ LFS 引导脚本的内容
- Checks the integrity of the file systems before they are
- mounted (with the exception of journal and network based
- file systems)
+ 文件系统挂载前检查文件系统的完整性(基于日志和网络的文件系统除外)
@@ -139,14 +133,7 @@
- Removes files that should not be preserved between
- reboots, such as those in /var/run/ and /var/lock/; it re-creates /var/run/utmp and removes the possibly
- present /etc/nologin,
- /fastboot, and /forcefsck files
+ 删除在重新启动之间不应该保留的文件,例如 /var/run/ 和 /var/lock/ 中的文件;重新创建 /var/run/utmp 并删除可能存在的 /etc/nologin、/fastboot 以及 /forcefsck 文件
@@ -160,8 +147,7 @@
- Loads the correct keymap table for the desired keyboard
- layout; it also sets the screen font
+ 加载所需键盘布局的正确键位表;同时设置屏幕字体
@@ -176,8 +162,7 @@
- Contains common functions, such as error and status
- checking, that are used by several bootscripts
+ 包含几个引导脚本所使用的常见功能,如错误和状态检查
@@ -191,7 +176,7 @@
- Halts the system
+ 停止系统
@@ -205,7 +190,7 @@
- Stops a network device
+ 停止网络设备
@@ -219,7 +204,7 @@
- Initializes a network device
+ 初始化网络设备
@@ -233,7 +218,7 @@
- Sets up the system's hostname and local loopback device
+ 设置系统的主机名和本地环回设备
@@ -247,9 +232,7 @@
- Loads kernel modules listed in /etc/sysconfig/modules, using arguments
- that are also given there
+ 加载 /etc/sysconfig/modules 中列出的内核模块,使用其中给出的参数
@@ -263,9 +246,7 @@
- Mounts all file systems, except ones that are marked
- noauto or are
- network based
+ 挂载所有文件系统,除了标记为 noauto 或基于网络的文件系统
@@ -280,8 +261,7 @@
- Mounts virtual kernel file systems, such as proc
+ 挂载虚拟内核文件系统,如 proc
@@ -295,8 +275,7 @@
- Sets up network interfaces, such as network cards, and
- sets up the default gateway (where applicable)
+ 设置网络接口(例如网卡),并在适用的时候设置默认网关
@@ -310,10 +289,7 @@
- The master run-level control script; it is responsible
- for running all the other bootscripts one-by-one, in a
- sequence determined by the name of the symbolic links
- being processed
+ 主运行级别控制脚本;它负责按照正在处理的符号链接的名称的顺序,依次运行所有其他引导文件
@@ -327,7 +303,7 @@
- Reboots the system
+ 重新启动系统
@@ -342,8 +318,7 @@
- Makes sure every process is terminated before the system
- reboots or halts
+ 确保所有进程在系统重新启动或停止之前已经终止
@@ -357,8 +332,7 @@
- Resets the kernel clock to local time in case the
- hardware clock is not set to UTC time
+ 将内核时钟重置为本地时间,以避免硬件时钟未设置为 UTC 时间的情况发生
@@ -373,8 +347,7 @@
- Provides the functionality needed to assign a static
- Internet Protocol (IP) address to a network interface
+ 提供为网络接口分配静态 IP 地址所需的功能
@@ -388,7 +361,7 @@
- Enables and disables swap files and partitions
+ 启用和禁用交换文件和分区
@@ -402,9 +375,7 @@
- Loads system configuration values from /etc/sysctl.conf, if that file exists,
- into the running kernel
+ 将系统配置值从 /etc/sysctl.conf(如果该文件存在)加载到正在运行的内核中
@@ -418,7 +389,7 @@
- Starts and stops the system and kernel log daemons
+ 启动和停止系统和内核日志守护进程
@@ -432,7 +403,7 @@
- A template to create custom bootscripts for other daemons
+ 为其他守护进程创建自定义引导脚本的模板
@@ -446,8 +417,7 @@
- Prepares the /dev directory
- and starts Udev
+ 准备 /dev 目录并启动 Udev
@@ -462,10 +432,7 @@
- Retries failed udev uevents, and copies generated rules
- files from /run/udev to
- /etc/udev/rules.d if
- required
+ 重试失败的 udev uevents,并在需要的情况下将生成的规则文件从 /run/udev 复制到 /etc/udev/rules.d
- Booting a Linux system involves several tasks. The process must mount
- both virtual and real file systems, initialize devices, activate
- swap, check file systems for integrity, mount any swap partitions or
- files, set the system clock, bring up networking, start any daemons
- required by the system, and accomplish any other custom tasks needed
- by the user. This process must be organized to ensure the tasks are
- performed in the correct order but, at the same time, be executed as
- fast as possible.
+ 启动 Linux 系统涉及到多个任务。启动程序需要挂载虚拟和真实文件系统,初始化设备,激活交换分区,检查文件系统完整性,挂载所有交换分区或者文件,设置系统时钟,开启网络,启动任何系统所需的守护程序,并完成用户需要的任何其他任务。这一过程中必须确保各个任务按照正确的顺序执行,同时需要执行得尽可能快。
7.1.1. System V
- System V is the classic boot process that has been used in Unix and
- Unix-like systems such as Linux since about 1983. It consists of a
- small program, init,
- that sets up basic programs such as login (via getty) and runs a
- script. This script, usually named rc, controls the execution of a
- set of additional scripts that perform the tasks required to
- initialize the system.
+ System V 是一个经典的启动进程,自 1983 年提出后,一直在诸如 Linux 的 Unix 及类 Unix 系统中使用。它由一个叫 init 的小程序组成,init 能够建立基本的程序诸如 login (通过 getty),并且运行一个脚本。这个脚本通常叫做 rc,控制着一系列能够执行所需任务以初始化系统的附加脚本的执行。
- The init program is
- controlled by the /etc/inittab file
- and is organized into run levels that can be run by the user:
+ init 程序由 /etc/inittab 文件控制,用户可以改变运行级别(run level):
- 0 — halt
- 1 — Single user mode
- 2 — Multiuser, without networking
- 3 — Full multiuser mode
- 4 — User definable
- 5 — Full multiuser mode with display manager
+ 0 — 停机
+ 1 — 单用户模式
+ 2 — 多用户模式,没有网络
+ 3 — 完全的多用户模式
+ 4 — 用户可定义的模式
+ 5 — 完全的多用户模式,包括显示管理器
- 6 — reboot
+ 6 — 重启
- The usual default run level is 3 or 5.
+ 通常默认的运行级别是 3 或者 5。
- Advantages
+ 优点
- Established, well understood system.
+ 已确定的、很好理解的系统。
- Easy to customize.
+ 容易进行定制。
- Disadvantages
+ 缺点
- Slower to boot. A medium speed base LFS system takes 8-12
- seconds where the boot time is measured from the first kernel
- message to the login prompt. Network connectivity is
- typically established about 2 seconds after the login prompt.
+ 启动较慢。中等速度的 LFS 系统需要 8-12 秒的时间启动,其中启动时间定义为从第一条内核消息到出现登陆提示所需要的时间。出现登录提示后,网络连接通常在两秒后建立。
- Serial processing of boot tasks. This is related to the
- previous point. A delay in any process such as a file system
- check, will delay the entire boot process.
+ 启动任务的串行执行。这与前一点相关。启动过程中任何一点的延迟,例如文件系统检查的延迟,将会推迟整个启动过程的完成。
- Does not directly support advanced features like control
- groups (cgroups), and per-user fair share scheduling.
+ 不能直接支持如控制组(cgroups)、各用户公平分享调度等高级功能。
- Udev, by default, names network devices according to Firmware/BIOS
- data or physical characteristics like the bus, slot, or MAC
- address. The purpose of this naming convention is to ensure that
- network devices are named consistently and not based on the time
- the network card was discovered. For example, on a computer having
- two network cards made by Intel and Realtek, the network card
- manufactured by Intel may become eth0 and the Realtek card becomes
- eth1. In some cases, after a reboot the cards get renumbered the
- other way around.
+
- In the new naming scheme, typical network device names would then
- be something like enp5s0 or wlp3s0. If this naming convention is
- not desired, the traditional naming scheme or a custom scheme can
- be implemented.
+
- 7.4.1.1. Disabling Persistent Naming on the Kernel Command Line
+ 7.4.1.1. 禁用内核命令行上的持久性命名
-
- The traditional naming scheme using eth0, eth1, etc can be
- restored by adding net.ifnames=0 on the kernel
- command line. This is most appropriate for those systems that
- have only one ethernet device of the same type. Laptops often
- have multiple ethernet connections that are named eth0 and wlan0
- and are also candidates for this method. The command line is
- passed in the GRUB configuration file. See Section 8.4.4,
- “Creating the GRUB Configuration File”.
+
- The naming scheme can be customized by creating custom Udev
- rules. A script has been included that generates the initial
- rules. Generate these rules by running:
+
- In some cases such as when MAC addresess have been assigned to
- a network card manually or in a virtual environment such as
- Qemu or Xen, the network rules file may not have been generated
- because addresses are not consistently assigned. In these
- cases, this method cannot be used.
+
在某些情况下,例如当 MAC 地址已经手动分配给网卡或虚拟环境(如 Qemu 或 Xen)时,网络规则文件可能因为地址未被一致地分配的原因未被生成。在这种情况下无法使用此方法。
-
- The file begins with a comment block followed by two lines for
- each NIC. The first line for each NIC is a commented description
- showing its hardware IDs (e.g. its PCI vendor and device IDs, if
- it's a PCI card), along with its driver in parentheses, if the
- driver can be found. Neither the hardware ID nor the driver is
- used to determine which name to give an interface; this
- information is only for reference. The second line is the Udev
- rule that matches this NIC and actually assigns it a name.
+
该文件以注释块开始,之后,每个 NIC 有两行相关的内容,其中第一行是显示其硬件 ID 的注释描述(例如,如果它是 PCI 卡,则是其 PCI 供应商和设备 ID),以及在括号中显示其驱动程序(如果可以找到驱动程序的话)。硬件 ID 和驱动程序都不用来确定接口的名称; 此信息仅供参考。第二行是匹配此 NIC 的 Udev 规则,实际上为其分配了名称。
-
- All Udev rules are made up of several keys, separated by commas
- and optional whitespace. This rule's keys and an explanation of
- each of them are as follows:
+
所有 Udev 规则由若干键值组成,用逗号和可选的空格分隔。此规则的键值和其解释分别如下:
- SUBSYSTEM=="net" - This tells
- Udev to ignore devices that are not network cards.
+ SUBSYSTEM=="net" - 告诉 Udev 忽略不是网卡的设备。
- ACTION=="add" - This tells
- Udev to ignore this rule for a uevent that isn't an add
- ("remove" and "change" uevents also happen, but don't need
- to rename network interfaces).
+ ACTION=="add" - 告诉 Udev 忽略不是 "add" 的 uevent 的规则("remove" 和 "change" 的 uevents 也会出现,但不需要重命名网络接口)。
- DRIVERS=="?*" - This exists so
- that Udev will ignore VLAN or bridge sub-interfaces
- (because these sub-interfaces do not have drivers). These
- sub-interfaces are skipped because the name that would be
- assigned would collide with their parent devices.
+ DRIVERS=="?*" - 使 Udev 忽略 VLAN 或网桥子接口(因为这些子接口没有驱动程序)。由于将被分配的名称将与其父设备相冲突,这些子接口将被跳过。
- ATTR{address} - The value of
- this key is the NIC's MAC address.
+ ATTR{address} - 该键值为 NIC 的 MAC 地址。
- ATTR{type}=="1" - This ensures
- the rule only matches the primary interface in the case of
- certain wireless drivers, which create multiple virtual
- interfaces. The secondary interfaces are skipped for the
- same reason that VLAN and bridge sub-interfaces are
- skipped: there would be a name collision otherwise.
+ ATTR{type}=="1" - 确保在某些无线驱动程序的情况下(这种情况会创建多个虚拟接口),该规则仅与主接口相匹配。因为与跳过 VLAN 和网桥子接口相同的原因(否则会出现名称冲突),跳过辅助接口。
- NAME - The value of this key
- is the name that Udev will assign to this interface.
+ NAME - 该键值为 Udev 将分配给此接口的名称。
- The value of NAME is the important
- part. Make sure you know which name has been assigned to each of
- your network cards before proceeding, and be sure to use that
- NAME value when creating your
- configuration files below.
+ NAME 的键值是重要的组成部分。确保在继续之前知道分配给每个网卡的名称,并在创建配置文件时确保使用该 NAME 键值。
- 7.4.2. CD-ROM symlinks
+ 7.4.2. CD-ROM 符号链接
- Some software that you may want to install later (e.g., various
- media players) expect the /dev/cdrom
- and /dev/dvd symlinks to exist, and
- to point to a CD-ROM or DVD-ROM device. Also, it may be convenient
- to put references to those symlinks into /etc/fstab. Udev comes with a script that will
- generate rules files to create these symlinks for you, depending on
- the capabilities of each device, but you need to decide which of
- two modes of operation you wish to have the script use.
+ 之后可能要安装的某些软件(例如各种媒体播放器)需要 /dev/cdrom 和 /dev/dvd 符号链接存在并指向 CD-ROM 或 DVD-ROM 设备。将这些符号链接的引用放入 /etc/fstab 可能很方便。Udev 附带一个脚本,它会根据每个设备的功能生成规则文件来创建这些符号链接,但是需要确定使用脚本的两种操作模式。
- First, the script can operate in “by-path”
- mode (used by default for USB and FireWire devices), where the
- rules it creates depend on the physical path to the CD or DVD
- device. Second, it can operate in “by-id” mode
- (default for IDE and SCSI devices), where the rules it creates
- depend on identification strings stored in the CD or DVD device
- itself. The path is determined by Udev's path_id script, and the
- identification strings are read from the hardware by its
- ata_id or
- scsi_id programs,
- depending on which type of device you have.
+ 首先,脚本可以以 “by-path” 模式运行(默认情况下用于 USB 和 FireWire 设备),其中创建的规则取决于 CD 或 DVD 设备的物理路径。其次,它可以以 “by-id” 模式运行(IDE 和 SCSI 设备默认),其中创建的规则取决于存储在 CD 或 DVD 设备本身中的标识字符串。该路径由 Udev 的 path_id 脚本确定,并且通过其 ata_id 或 scsi_id 程序从硬件中读取标识字符串,具体取决于拥有的设备类型。
- There are advantages to each approach; the correct approach to use
- will depend on what kinds of device changes may happen. If you
- expect the physical path to the device (that is, the ports and/or
- slots that it plugs into) to change, for example because you plan
- on moving the drive to a different IDE port or a different USB
- connector, then you should use the “by-id” mode.
- On the other hand, if you expect the device's identification to
- change, for example because it may die, and you would replace it
- with a different device with the same capabilities and which is
- plugged into the same connectors, then you should use the
- “by-path” mode.
+ 每种方法都有自己的优势; 使用方法的正确与否取决于设备可能发生什么样的更改。如果希望设备的物理路径(即插入的端口和/或插槽)可以更改,例如计划将驱动器移动到其他 IDE 端口或不同的 USB连接器,那么应该使用 “by-id” 模式。另一方面,如果希望设备的标识可以更改,例如设备可能会死机,之后将其替换为具有相同功能的其他设备,并将其插入相同的连接器,那么应该使用 “by-path” 模式。
- If either type of change is possible with your drive, then choose a
- mode based on the type of change you expect to happen more often.
+ 如果驱动器两种情况都有可能发生,那么请根据预期发生更多的情况选择一种模式。
- Important
+ 重要
- External devices (for example, a USB-connected CD drive) should
- not use by-path persistence, because each time the device is
- plugged into a new external port, its physical path will change.
- All externally-connected devices will have this problem if you
- write Udev rules to recognize them by their physical path; the
- problem is not limited to CD and DVD drives.
+ 外部设备(例如 USB 连接的 CD 驱动器)不应使用 “by-path” 模式,因为每次将设备插入新的外部端口时,其物理路径将发生变化。如果写入 Udev 规则以通过其物理路径识别它们,那么所有外部连接的设备都将出现此问题; 该问题不仅限于 CD 和 DVD 驱动器。
- If you wish to see the values that the Udev scripts will use, then
- for the appropriate CD-ROM device, find the corresponding directory
- under /sys (e.g., this can be
- /sys/block/hdd) and run a command
- similar to the following:
+ 如果希望知道 Udev 脚本将使用的键值,那么对于相应的 CD-ROM 设备,请在 /sys 下找到相应的目录(例如 /sys/block/hdd),并运行类似于以下的命令:
udevadm test /sys/block/hdd
- Look at the lines containing the output of various *_id programs.
- The “by-id” mode will use the ID_SERIAL
- value if it exists and is not empty, otherwise it will use a
- combination of ID_MODEL and ID_REVISION. The “by-path”
- mode will use the ID_PATH value.
+ 观察包含各种 *_id 程序的输出行的内容。“by-id” 模式将使用 ID_SERIAL 值(如果它存在且不为空),否则将使用 ID_MODEL 和 ID_REVISION 的组合。“by-path”模式将使用 ID_PATH 值。
- If the default mode is not suitable for your situation, then the
- following modification can be made to the /etc/udev/rules.d/83-cdrom-symlinks.rules file,
- as follows (where mode is
- one of “by-id” or “by-path”):
+ 如果默认模式不适合您的情况,则可以对 /etc/udev/rules.d/83-cdrom-symlinks.rules 文件进行修改,如下所示(其中 mode 为 “by-id” 或 “by-path” 二者之一):
sed -i -e 's/"write_cd_rules"/"write_cd_rules
/etc/udev/rules.d/83-cdrom-symlinks.rules
- Note that it is not necessary to create the rules files or symlinks
- at this time, because you have bind-mounted the host's /dev directory into the LFS system, and we assume
- the symlinks exist on the host. The rules and symlinks will be
- created the first time you boot your LFS system.
+ 请注意,此时不需要创建规则文件或符号链接,因为您已将主机的 /dev 目录绑定到 LFS 系统中,同时我们假设主机上存在符号链接。首次引导 LFS 系统时,将创建规则和符号链接。
- However, if you have multiple CD-ROM devices, then the symlinks
- generated at that time may point to different devices than they
- point to on your host, because devices are not discovered in a
- predictable order. The assignments created when you first boot the
- LFS system will be stable, so this is only an issue if you need the
- symlinks on both systems to point to the same device. If you need
- that, then inspect (and possibly edit) the generated /etc/udev/rules.d/70-persistent-cd.rules file
- after booting, to make sure the assigned symlinks match what you
- need.
+ 但是,如果您有多个 CD-ROM 设备,那么当时生成的符号链接可能指向与主机上已指向设备不同的设备,因为无法预测设备发现的顺序。首次启动 LFS 系统时创建的分配将是稳定的,因此,此问题仅出现在需要两个系统的符号链接指向同一设备的情况下。如果需要,请在启动后检查(可能需要编辑)生成的 /etc/udev/rules.d/70-persistent-cd.rules 文件,以确保所分配的符号链接符合您所需要的。
- 7.4.3. Dealing with duplicate devices
+ 7.4.3. 重复设备的处理
- As explained in Section 7.3,
- “Overview of Device and Module Handling”, the order
- in which devices with the same function appear in /dev is essentially random. E.g., if you have a
- USB web camera and a TV tuner, sometimes /dev/video0 refers to the camera and /dev/video1 refers to the tuner, and sometimes
- after a reboot the order changes to the opposite one. For all
- classes of hardware except sound cards and network cards, this is
- fixable by creating Udev rules for custom persistent symlinks. The
- case of network cards is covered separately in Section 7.5,
- “General Network Configuration”, and sound card
- configuration can be found in
- BLFS.
+ 如 7.3 “设备及模块管理综述” 中所述,/dev 中显示的具有相同功能的设备的顺序基本上是随机的。例如,如果您有 USB 网络摄像机和电视调谐器,有时 /dev/video0 指摄像机同时 /dev/video1 指调谐器,有时在重新启动后,顺序变为相反的。对于除了声卡和网卡的所有类别的硬件,可以通过自定义持久性符号链接创建 Udev 规则来修复。网卡的情况将在 7.5 “通用网络配置” 中谈到,声卡配置可以在 BLFS 中找到。
- For each of your devices that is likely to have this problem (even
- if the problem doesn't exist in your current Linux distribution),
- find the corresponding directory under /sys/class or /sys/block. For video devices, this may be
- /sys/class/video4linux/videoX. Figure out the attributes
- that identify the device uniquely (usually, vendor and product IDs
- and/or serial numbers work):
+ 对于每个可能出现此问题的设备(即使您当前的 Linux 发行版中不存在问题),请在 /sys/class 或 /sys/block 下找到相应的目录。对于视频设备,目录可能是 /sys/class/video4linux/videoX。找出能够唯一标识设备的属性(通常,供应商和产品 ID 和/或序列号是有用的):
udevadm info -a -p /sys/class/video4linux/video0
- Then write rules that create the symlinks, e.g.:
+ 然后编写创建符号链接的规则,例如:
EOF
- The result is that /dev/video0 and
- /dev/video1 devices still refer
- randomly to the tuner and the web camera (and thus should never be
- used directly), but there are symlinks /dev/tvtuner and /dev/webcam that always point to the correct
- device.
+ 以上操作的结果是 /dev/video0 和 /dev/video1 设备仍然可能随机指向到调谐器和网络摄像机(因此不应该直接使用),但是符号链接 /dev/tvtuner 与 /dev/webcam 总是指向到正确的设备。
- 7.3. Overview of
- Device and Module Handling
+ 7.3. 设备及模块管理综述
- In Chapter
- 6, we installed the Udev package when eudev was built. Before we go into the details
- regarding how this works, a brief history of previous methods of
- handling devices is in order.
+ 在第六章中,我们在 eudev 构建之后安装了 Udev 包。在我们详细了解它是如何工作之前,先简要介绍一下先前方法是如何进行设备管理的。
-
- Linux systems in general traditionally used a static device creation
- method, whereby a great many device nodes were created under
- /dev (sometimes literally thousands of
- nodes), regardless of whether the corresponding hardware devices
- actually existed. This was typically done via a MAKEDEV script, which contains a
- number of calls to the mknod program with the relevant
- major and minor device numbers for every possible device that might
- exist in the world.
+
- Using the Udev method, only those devices which are detected by the
- kernel get device nodes created for them. Because these device nodes
- will be created each time the system boots, they will be stored on a
- devtmpfs file system (a virtual file
- system that resides entirely in system memory). Device nodes do not
- require much space, so the memory that is used is negligible.
+
- In February 2000, a new filesystem called devfs was merged into the 2.3.46 kernel and was
- made available during the 2.4 series of stable kernels. Although it
- was present in the kernel source itself, this method of creating
- devices dynamically never received overwhelming support from the
- core kernel developers.
+
- The main problem with the approach adopted by devfs was the way it handled device detection,
- creation, and naming. The latter issue, that of device node naming,
- was perhaps the most critical. It is generally accepted that if
- device names are allowed to be configurable, then the device naming
- policy should be up to a system administrator, not imposed on them
- by any particular developer(s). The devfs file system also suffered from race
- conditions that were inherent in its design and could not be fixed
- without a substantial revision to the kernel. It was marked as
- deprecated for a long period – due to a lack of maintenance
- – and was finally removed from the kernel in June, 2006.
+
- With the development of the unstable 2.5 kernel tree, later
- released as the 2.6 series of stable kernels, a new virtual
- filesystem called sysfs came to be.
- The job of sysfs is to export a
- view of the system's hardware configuration to userspace processes.
- With this userspace-visible representation, the possibility of
- developing a userspace replacement for devfs became much more realistic.
+
- The sysfs filesystem was
- mentioned briefly above. One may wonder how sysfs knows about the devices present on a
- system and what device numbers should be used for them. Drivers
- that have been compiled into the kernel directly register their
- objects with a sysfs (devtmpfs
- internally) as they are detected by the kernel. For drivers
- compiled as modules, this registration will happen when the
- module is loaded. Once the sysfs
- filesystem is mounted (on /sys), data which the drivers register
- with sysfs are available to
- userspace processes and to udevd for processing (including
- modifications to device nodes).
+
- Device files are created by the kernel by the devtmpfs filesystem. Any driver that wishes
- to register a device node will go through the devtmpfs (via the driver core) to do it. When
- a devtmpfs instance is mounted on
- /dev, the device node will
- initially be created with a fixed name, permissions, and owner.
+
- A short time later, the kernel will send a uevent to udevd. Based on the rules
- specified in the files within the /etc/udev/rules.d, /lib/udev/rules.d, and /run/udev/rules.d directories, udevd will create additional
- symlinks to the device node, or change its permissions, owner, or
- group, or modify the internal udevd database entry (name) for
- that object.
+
- The rules in these three directories are numbered and all three
- directories are merged together. If udevd can't find a rule for the
- device it is creating, it will leave the permissions and
- ownership at whatever devtmpfs
- used initially.
+
- Device drivers compiled as modules may have aliases built into
- them. Aliases are visible in the output of the modinfo program and are usually
- related to the bus-specific identifiers of devices supported by a
- module. For example, the snd-fm801 driver supports PCI devices
- with vendor ID 0x1319 and device ID 0x0801, and has an alias of
- “pci:v00001319d00000801sv*sd*bc04sc01i*”.
- For most devices, the bus driver exports the alias of the driver
- that would handle the device via sysfs. E.g., the /sys/bus/pci/devices/0000:00:0d.0/modalias file
- might contain the string “pci:v00001319d00000801sv00001319sd00001319bc04sc01i00”.
- The default rules provided with Udev will cause udevd to call out to
- /sbin/modprobe with
- the contents of the MODALIAS uevent
- environment variable (which should be the same as the contents of
- the modalias file in sysfs), thus
- loading all modules whose aliases match this string after
- wildcard expansion.
+
- In this example, this means that, in addition to snd-fm801, the obsolete (and unwanted)
- forte driver will be
- loaded if it is available. See below for ways in which the
- loading of unwanted drivers can be prevented.
+
- When you plug in a device, such as a Universal Serial Bus (USB)
- MP3 player, the kernel recognizes that the device is now
- connected and generates a uevent. This uevent is then handled by
- udevd as described
- above.
+
- 7.3.3. Problems with Loading Modules and Creating Devices
+ 7.3.3. 关于加载模块和创建设备的问题
- There are a few possible problems when it comes to automatically
- creating device nodes.
+ 在自动创建设备节点时可能会出现一些问题。
- 7.3.3.1. A kernel module is not loaded automatically
+ 7.3.3.1. 内核模块未自动加载
-
- Udev will only load a module if it has a bus-specific alias and
- the bus driver properly exports the necessary aliases to
- sysfs. In other cases, one should
- arrange module loading by other means. With Linux-4.9.9, Udev is
- known to load properly-written drivers for INPUT, IDE, PCI, USB,
- SCSI, SERIO, and FireWire devices.
+
- To determine if the device driver you require has the necessary
- support for Udev, run modinfo with the module name as
- the argument. Now try locating the device directory under
- /sys/bus and check whether there is
- a modalias file there.
+
- If the modalias file exists in
- sysfs, the driver supports the
- device and can talk to it directly, but doesn't have the alias,
- it is a bug in the driver. Load the driver without the help from
- Udev and expect the issue to be fixed later.
+
- If there is no modalias file in the
- relevant directory under /sys/bus,
- this means that the kernel developers have not yet added modalias
- support to this bus type. With Linux-4.9.9, this is the case with
- ISA busses. Expect this issue to be fixed in later kernel
- versions.
+
- 7.3.3.2. A kernel module is not loaded automatically, and Udev is
- not intended to load it
+ 7.3.3.2. 内核模块未自动加载,且 Udev 不会进行加载
-
- If the “wrapper” module only enhances the
- functionality provided by some other module (e.g., snd-pcm-oss enhances the functionality
- of snd-pcm by making the
- sound cards available to OSS applications), configure
- modprobe to load
- the wrapper after Udev loads the wrapped module. To do this, add
- a “softdep” line in any /etc/modprobe.d/<filename>.conf
- file. For example:
+
- Note that the “softdep” command also allows
- pre: dependencies, or a mixture of
- both pre: and post:. See the modprobe.d(5) manual page for more information
- on “softdep” syntax and capabilities.
+
- If the module in question is not a wrapper and is useful by
- itself, configure the modules bootscript to load this
- module on system boot. To do this, add the module name to the
- /etc/sysconfig/modules file on a
- separate line. This works for wrapper modules too, but is
- suboptimal in that case.
+
- Either don't build the module, or blacklist it in a /etc/modprobe.d/blacklist.conf file as done
- with the forte module in
- the example below:
+
不要在 /etc/modprobe.d/blacklist.conf 文件中构建模块,或将其列入黑名单。如以下示例中的 forte 模块:
blacklist forte
-
- Blacklisted modules can still be loaded manually with the
- explicit modprobe
- command.
+
黑名单模块仍然可以使用显式的 modprobe 命令手动加载。
- 7.3.3.4. Udev creates a device incorrectly, or makes a wrong
- symlink
+ 7.3.3.4. Udev 创建设备不正确,或创建了错误的符号链接
-
- This usually happens if a rule unexpectedly matches a device. For
- example, a poorly-written rule can match both a SCSI disk (as
- desired) and the corresponding SCSI generic device (incorrectly)
- by vendor. Find the offending rule and make it more specific,
- with the help of the udevadm
- info command.
+
如果规则意外匹配了设备,则通常会发生这种情况。例如,写得不好的规则可以同时匹配供应商的 SCSI 磁盘(本应匹配)和相应的 SCSI 通用设备(不应匹配)。在 udevadm info 命令的帮助下,查找违规的规则并使其更具体化。
- 7.3.3.5. Udev rule works unreliably
+ 7.3.3.5. Udev 规则工作不可靠
-
- This may be another manifestation of the previous problem. If
- not, and your rule uses sysfs
- attributes, it may be a kernel timing issue, to be fixed in later
- kernels. For now, you can work around it by creating a rule that
- waits for the used sysfs
- attribute and appending it to the /etc/udev/rules.d/10-wait_for_sysfs.rules file
- (create this file if it does not exist). Please notify the LFS
- Development list if you do so and it helps.
+
- 7.3.3.6. Udev does not create a device
+ 7.3.3.6. Udev 未创建设备
-
- Further text assumes that the driver is built statically into the
- kernel or already loaded as a module, and that you have already
- checked that Udev doesn't create a misnamed device.
+
- Udev has no information needed to create a device node if a
- kernel driver does not export its data to sysfs. This is most common with third party
- drivers from outside the kernel tree. Create a static device node
- in /lib/udev/devices with the
- appropriate major/minor numbers (see the file devices.txt inside the kernel documentation or
- the documentation provided by the third party driver vendor). The
- static device node will be copied to /dev by udev.
+
- 7.3.3.7. Device naming order changes randomly after rebooting
+ 7.3.3.7. 设备命名顺序在重新启动后随机更改
-
- This is due to the fact that Udev, by design, handles uevents and
- loads modules in parallel, and thus in an unpredictable order.
- This will never be “fixed”. You should not rely upon the
- kernel device names being stable. Instead, create your own rules
- that make symlinks with stable names based on some stable
- attributes of the device, such as a serial number or the output
- of various *_id utilities installed by Udev. See Section 7.4, “Managing
- Devices” and Section 7.5,
- “General Network Configuration” for examples.
+