diff --git a/lfs-8.0-systemd/chapter07/chapter07.html b/lfs-8.0-systemd/chapter07/chapter07.html index bb9aa4d..c58ade7 100644 --- a/lfs-8.0-systemd/chapter07/chapter07.html +++ b/lfs-8.0-systemd/chapter07/chapter07.html @@ -3,9 +3,9 @@ + "application/xhtml+xml; charset=utf-8" /> - Chapter 7. System Configuration + 第七章 系统配置 @@ -19,72 +19,71 @@

Linux From Scratch - Version 8.0-systemd

- Part III. Building the LFS System + 第三部分 构建 LFS 系统

- 7. System - Configuration + 7. 系统配置

- Table of Contents + 目录

@@ -93,25 +92,25 @@

diff --git a/lfs-8.0-systemd/chapter07/introduction.html b/lfs-8.0-systemd/chapter07/introduction.html index 1cd1165..88eb952 100644 --- a/lfs-8.0-systemd/chapter07/introduction.html +++ b/lfs-8.0-systemd/chapter07/introduction.html @@ -3,9 +3,9 @@ + "application/xhtml+xml; charset=utf-8" /> - 7.1. Introduction + 7.1. 引言 @@ -19,142 +19,129 @@

Linux From Scratch - Version 8.0-systemd

- Chapter 7. System Configuration + 第七章 系统配置

7.1. Introduction + "ch-scripts-introduction">7.1. 引言

- This chapter discusses configuration files and systemd services. - First, the general configuration files needed to set up networking - are presented. + 本章讨论了配置文件及 systemd 服务。首先是设置网络所需的通用配置文件。

- Second, issues that affect the proper setup of devices are discussed. + 其次讨论了影响设备正确设置的问题。

- Third, configuring the system clock and keyboard layout. + 第三,配置系统时钟和键盘布局。

- Fourth, a brief introduction to the scripts and configuration files - used when the user logs into the system. + 第四,简要介绍用户登录系统时使用的脚本和配置文件。

- And finally, configuring the systemd behavior. + 最后,配置 systemd 的行为。

@@ -164,25 +151,25 @@

  • Up + "第七章 系统配置">返回
  • Home + "Linux From Scratch - Version 8.0-systemd">首页

diff --git a/lfs-8.0-systemd/chapter07/symlinks.html b/lfs-8.0-systemd/chapter07/symlinks.html index 071d6c6..e41ff7c 100644 --- a/lfs-8.0-systemd/chapter07/symlinks.html +++ b/lfs-8.0-systemd/chapter07/symlinks.html @@ -3,9 +3,9 @@ + "application/xhtml+xml; charset=utf-8" /> - 7.4. Managing Devices + 7.4. 管理设备 @@ -19,78 +19,53 @@

Linux From Scratch - Version 8.0-systemd

- Chapter 7. System Configuration + 第七章 系统配置

- 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 总是指向到正确的设备。

@@ -119,25 +88,25 @@

diff --git a/lfs-8.0-systemd/chapter07/udev.html b/lfs-8.0-systemd/chapter07/udev.html index e28253e..2fb1783 100644 --- a/lfs-8.0-systemd/chapter07/udev.html +++ b/lfs-8.0-systemd/chapter07/udev.html @@ -3,9 +3,9 @@ + "application/xhtml+xml; charset=utf-8" /> - 7.3. Overview of Device and Module Handling + 7.3. 设备及模块管理综述 @@ -19,425 +19,203 @@

Linux From Scratch - Version 8.0-systemd

- Chapter 7. System Configuration + 第七章 系统配置

- 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. +

通常来说,Linux 系统使用静态设备创建方法,由此在 /dev 目录创建了大量的设备节点(有时甚至达到数千个),而不管相应的硬件设备是否实际存在。这通常由 MAKEDEV 脚本完成,该脚本包括若干对 mknod 程序的调用,其中包含任何可能存在于世界中的大大小小的设备的编号。

-

- 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. +

通过使用 Udev 方法,只有那些被内核检测到的设备才能创建设备节点。由于这些设备节点在系统引导时创建,因此它们将被存储于 devtmpfs 文件系统(一个完全位于系统内存中的虚拟文件系统)中。设备节点不需要太多空间,因此使用的内存可以忽略不计。

- 7.3.1. History + 7.3.1. 历史

-

- 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. +

2000 年 2 月,一个名为 devfs 的新文件系统被合并到 2.3.46 内核中,并且在 2.4 系列稳定内核中可用。尽管相关的内核源代码本身存在,但这种动态创建设备的方法从未得到核心内核开发者的广泛支持。

-

- 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. +

采用 devfs 方法的主要问题是处理设备检测、创建和命名的方式。后一个问题,即设备节点命名,也许是最关键的问题。通常得到认可的是如果允许对设备名称进行配置,那么设备命名策略应由系统管理员决定,而不是由任何特定的开发人员施加。devfs 文件系统也遭受其设计中固有的竞争条件的影响,如果不对内核进行大量修改,就无法得到修复。由于缺乏维护,它被长时间标记为被淘汰状态,并最终于 2006 年 6 月从内核中删除。

-

- 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. +

经过不稳定的 2.5 内核树的发展,之后发布的 2.6 系列稳定内核中,诞生了一个称为 sysfs 的新的虚拟文件系统。sysfs 的任务是将系统的硬件配置视图导出到用户空间进程。通过用户空间的可视化表示,开发一个用户空间进程以替换 devfs 变得更加现实。

- 7.3.2. Udev Implementation + 7.3.2. Udev 实现

7.3.2.1. Sysfs

-

- 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). +

上文简要介绍了 sysfs 文件系统。大家可能想知道 sysfs 如何知道系统上存在的设备以及应该使用哪些设备号。对于已经编译到内核中的驱动程序,当被内核检测时,直接通过 sysfs(位于 devtmpfs 内部)来注册对象。对于编译为模块的驱动程序,当注册模块加载时,会发生注册。一旦挂载了 sysfs 文件系统(位于 /sys),驱动程序使用 sysfs 注册的数据可用于用户空间进程和 udevd 以进行处理(包括对设备节点的修改)。

- 7.3.2.2. Device Node Creation + 7.3.2.2. 设备节点的创建

-

- 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. +

设备文件由内核通过 devtmpfs 文件系统创建。任何希望注册设备节点的驱动程序都将通过 devtmpfs (由驱动程序核心)来完成。当 devtmpfs 实例挂载在 /dev 上时,设备节点将以固定的名称、权限和所有者初始创建。

-

- 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. +

不久之后,内核将向 udevd 发送一个 uevent。根据 /etc/udev/rules.d/lib/udev/rules.d/run/udev/rules.d 目录中的文件中指定的规则,udevd 将为设备节点创建其他符号链接,或更改其权限、所有者或组,或修改该对象的内部 udevd 数据库条目(名称)。

-

- 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. +

这三个目录中的规则被编号,并且这三个目录被合并在一起。如果 udevd 找不到正在创建的设备的规则,那么会将其权限和所有权指定为 devtmpfs 最初所使用的。

- 7.3.2.3. Module Loading + 7.3.2.3. 模块的加载

-

- 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. +

编译为模块的设备驱动程序可能会在其中内置别名。别名在 modinfo 程序的输出中可见,通常与模块支持的设备的总线特定标识符相关。例如,snd-fm801 驱动程序支持供应商 ID 为 0x1319、设备 ID 为 0x0801 的 PCI 设备,并具有 pci:v00001319d00000801sv*sd*bc04sc01i* 的别名。对于大多数设备,总线驱动程序通过 sysfs 导出所处理设备的驱动程序的别名。例如,/sys/bus/pci/devices/0000:00:0d.0/modalias 文件可能包含字符串 pci:v00001319d00000801sv00001319sd00001319bc04sc01i00。Udev 提供的默认规则将引起 udevdMODALIAS uevent 环境变量的内容(它们应与 sysfs 中的 modalias 文件的内容相同)调用 /sbin/modprobe,从而加载别名与经过通配符扩展的字符串相匹配的所有模块。

-

- 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. +

在这个例子中,这就意味着除了 snd-fm801 之外,过时的(和不需要的)forte 驱动程序将被加载(如果可用的话)。请参阅下文了解如何防止加载不需要的驱动程序。

-

- The kernel itself is also able to load modules for network - protocols, filesystems and NLS support on demand. +

内核本身也可以根据需要加载网络协议、文件系统和 NLS 支持模块。

- 7.3.2.4. Handling Hotpluggable/Dynamic Devices + 7.3.2.4. 热插拔/动态设备的处理

-

- 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. +

当插入设备,例如通用串行总线(USB)MP3 播放器时,内核会识别设备已连接,并生成 uevent。这个 uevent 之后由 udevd 做如前所述的处理。

- 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. +

如果 Udev 具有总线特定的别名,并且总线驱动程序正确地将必需的别名导出到 sysfs,那么 Udev 将仅加载内核模块。在其他情况下,应通过其他方式安排模块的加载。使用 Linux-4.9.9,Udev 可以为 INPUT,IDE,PCI,USB,SCSI,SERIO 和 FireWire 设备加载正确写入的驱动程序。

-

- 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. +

要确定需要的设备驱动程序是否具有对 Udev 的必要支持,请以模块名称作为参数运行 modinfo。尝试将设备目录定位在 /sys/bus 下,检查是否存在 modalias 文件。

-

- 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. +

如果在 modalias 中存在 sysfs 文件,则驱动程序支持该设备,并可直接与该设备进行通信,但不具有别名,这是驱动程序中的错误。在没有 Udev 帮助的情况下加载驱动程序,并期望问题在以后修复。

-

- 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. +

如果在 /sys/bus 下的相关目录中没有 modalias 文件,这意味着内核开发人员尚未向此总线类型添加 modalias 支持。在 Linux-4.9.9 中,这是 ISA 总线存在的情况。期望在以后的内核版本中修复此问题。

-

- Udev is not intended to load wrapper - drivers such as snd-pcm-oss and non-hardware drivers - such as loop at all. +

Udev 不会加载“封装”(wrapper)的驱动程序,如 snd-pcm-oss,以及非硬件驱动程序,如 loop

- 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: +

如果“封装”(wrapper)模块仅增强了某些其他模块提供的功能(例如,snd-pcm-oss 通过使声卡可用于 OSS 应用程序来增强 snd-pcm 的功能),请在 Udev 加载后配置 modprobe 以加载封装的模块。为此,请在任何 /etc/modprobe.d/<filename>.conf 文件中添加 softdep 行。例如:

 softdep snd-pcm post: snd-pcm-oss
 
-

- 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. +

请注意,softdep 命令还允许 pre: 依赖,或 pre:post: 之间的混合。有关 softdep 语法和功能的更多信息,请参阅 modprobe.d(5) 手册页。

-

- 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. +

如果所涉及的模块不是封装模块,并且本身很有用,请配置 modules 引导脚本以在系统启动时加载该模块。为此,请将模块名称添加到 /etc/sysconfig/modules 文件中。这对于封装模块也是如此,但在这种情况下并不是最佳的解决方案。

- 7.3.3.3. Udev loads some unwanted module + 7.3.3.3. Udev 加载了一些不需要的模块

-

- 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. +

这可能是之前的问题的另一个表现。如果不是,并且您的规则使用 sysfs 属性,则可能是内核计时问题,这将在后来的内核中修复。对于目前来说,可以通过创建一个等待使用的 sysfs 属性并将其附加到 /etc/udev/rules.d/10-wait_for_sysfs.rules 文件的规则来解决(如果不存在,那么创建此文件)。如果这样做有帮助,请通知 LFS 开发列表。

- 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 不会创建错误的设备。

-

- 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. +

如果内核驱动程序没有将其数据导出到 sysfs,那么 Udev 无需创建设备节点所需的信息。这在内核树以外的第三方驱动程序中最常见。可以在 /lib/udev/devices 中创建一个具有适合的主要/次要编号的静态设备节点(请参阅内核文档中的 devices.txt 文件或第三方驱动程序供应商提供的文档)。静态设备节点将被 /dev 复制到 /dev

- 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. +

这是因为 Udev 在设计上是并行地处理 uevents 并且加载模块的,因此会出现不可预测的顺序。这永远不会 固定。因此不应该依赖内核设备名称是稳定的。相反,根据设备的某些稳定属性(如序列号或 Udev 安装的各种 *_id 程序的输出)创建自己的规则,以创建具有稳定名称的符号链接。有关示例请参见 7.4. “管理设备”7.5. “通用网络设置”

- 7.3.4. Useful Reading + 7.3.4. 有用的阅读资料

- Additional helpful documentation is available at the following - sites: + 以下站点提供其他有用的资料:

diff --git a/lfs-8.0/chapter07/bootscripts.html b/lfs-8.0/chapter07/bootscripts.html index 037ac45..a366d00 100644 --- a/lfs-8.0/chapter07/bootscripts.html +++ b/lfs-8.0/chapter07/bootscripts.html @@ -3,9 +3,9 @@ + "application/xhtml+xml; charset=utf-8" /> - 7.2. LFS-Bootscripts-20150222 + 7.2. LFS-引导脚本-20150222 @@ -19,53 +19,49 @@

Linux From Scratch - Version 8.0

- Chapter 7. System Configuration + 第七章 系统配置

- 7.2. - LFS-Bootscripts-20150222 + 7.2. LFS-引导脚本-20150222

- 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 引导脚本的内容

- Installed scripts: + 所安装的脚本: checkfs, cleanfs, console, functions, halt, ifdown, ifup, localnet, modules, mountfs, mountvirtfs, network, rc, reboot, sendsignals, setclock, ipv4-static, swap, sysctl, sysklogd, template, udev, and udev_retry
- Installed directories: - /etc/rc.d, /etc/init.d (symbolic link), - /etc/sysconfig, /lib/services, /lib/lsb (symbolic link) + 所安装的目录: + /etc/rc.d, /etc/init.d (符号链接), + /etc/sysconfig, /lib/services, /lib/lsb (符号链接)

- Short Descriptions + 简要描述

@@ -123,9 +119,7 @@

@@ -139,14 +133,7 @@

@@ -160,8 +147,7 @@

@@ -176,8 +162,7 @@

@@ -191,7 +176,7 @@

@@ -205,7 +190,7 @@

@@ -219,7 +204,7 @@

@@ -233,7 +218,7 @@

@@ -247,9 +232,7 @@

@@ -263,9 +246,7 @@

@@ -280,8 +261,7 @@

@@ -295,8 +275,7 @@

@@ -310,10 +289,7 @@

@@ -327,7 +303,7 @@

@@ -342,8 +318,7 @@

@@ -357,8 +332,7 @@

@@ -373,8 +347,7 @@

@@ -388,7 +361,7 @@

@@ -402,9 +375,7 @@

@@ -418,7 +389,7 @@

@@ -432,7 +403,7 @@

@@ -446,8 +417,7 @@

@@ -462,10 +432,7 @@

@@ -478,25 +445,25 @@

  • Up + "第七章 系统配置">返回
  • Home + "Linux From Scratch - Version 8.0 ">首页
diff --git a/lfs-8.0/chapter07/chapter07.html b/lfs-8.0/chapter07/chapter07.html index 789faf8..cf9fa1b 100644 --- a/lfs-8.0/chapter07/chapter07.html +++ b/lfs-8.0/chapter07/chapter07.html @@ -3,9 +3,9 @@ + "application/xhtml+xml; charset=utf-8" /> - Chapter 7. System Configuration + 第七章 系统配置 @@ -19,70 +19,68 @@

Linux From Scratch - Version 8.0

- Part III. Building the LFS System + 第三部分 构建 LFS 系统

  • Up + "第III部分 构建 LFS 系统">返回
  • Home + "Linux From Scratch - Version 8.0 ">首页

- 7. System - Configuration + 7. 系统配置

@@ -91,25 +89,25 @@

  • Up + "第III部分 构建 LFS 系统">返回
  • Home + "Linux From Scratch - Version 8.0 ">首页

diff --git a/lfs-8.0/chapter07/introduction.html b/lfs-8.0/chapter07/introduction.html index f3d16f2..895aeba 100644 --- a/lfs-8.0/chapter07/introduction.html +++ b/lfs-8.0/chapter07/introduction.html @@ -3,9 +3,9 @@ + "application/xhtml+xml; charset=utf-8" /> - 7.1. Introduction + 7.1. 引言 @@ -19,130 +19,108 @@

Linux From Scratch - Version 8.0

- Chapter 7. System Configuration + 第七章 系统配置

  • Up + "Chapter 7. System Configuration">返回
  • Home + "Linux From Scratch - Version 8.0 ">首页

7.1. Introduction + "ch-scripts-introduction">7.1. 引言

- 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)、各用户公平分享调度等高级功能。

  • - Adding scripts requires manual, static sequencing decisions. + 添加脚本需要手动的、静态地进行操作。

@@ -153,25 +131,25 @@

  • Up + "Chapter 7. System Configuration">返回
  • Home + "Linux From Scratch - Version 8.0 ">首页

diff --git a/lfs-8.0/chapter07/symlinks.html b/lfs-8.0/chapter07/symlinks.html index efe648e..ccae46d 100644 --- a/lfs-8.0/chapter07/symlinks.html +++ b/lfs-8.0/chapter07/symlinks.html @@ -3,9 +3,9 @@ + "application/xhtml+xml; charset=utf-8" /> - 7.4. Managing Devices + 7.4. 管理设备 @@ -19,93 +19,62 @@

Linux From Scratch - Version 8.0

- Chapter 7. System Configuration + 第七章 系统配置

  • Up + "第七章 系统配置">返回
  • Home + "Linux From Scratch - Version 8.0 ">首页

- 7.4. - Managing Devices + 7.4. 管理设备

- 7.4.1. Network Devices + 7.4.1. 网络设备

-

- 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. +

默认情况下,Udev 根据固件/BIOS 数据或总线、插槽、MAC 地址等物理特性来命名网络设备。此命名约定的目的是确保网络设备的名称一致,而不是基于网卡发现的时间。例如,在有分别由 Intel 和 Realtek 制造的两个网卡的计算机上,由 Intel 制造的网卡可能变成 eth0,同时 Realtek 制造的网卡变成 eth1。在某些情况下,重新启动后,网卡会重新以相反的顺序编号。

-

- 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. +

在新的命名方案中,典型的网络设备名称将类似于 enp5s0 或 wlp3s0。如果不需要这个命名约定,那么可以实现传统的命名方案或自定义方案。

- 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”. +

通过在内核命令行中添加 net.ifnames=0 可以恢复使用 eth0,eth1 等的传统命名方案。这对于只有同一类型的以太网设备的系统最为合适。笔记本电脑通常有多个以太网连接,名称为 eth0 和 wlan0,也适合此方法。命令行在 GRUB 配置文件中传递。请参见 8.4.4 “创建 GRUB 配置文件”

- 7.4.1.2. Creating Custom Udev Rules + 7.4.1.2. 创建自定义 Udev 规则

-

- 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: +

可以通过创建自定义 Udev 规则来自定义命名方案。目前已经存在生成初始规则的脚本,可以通过运行以下命令生成这些规则:

 bash /lib/udev/init-net-rules.sh
 
-

- Now, inspect the /etc/udev/rules.d/70-persistent-net.rules file, - to find out which name was assigned to which network device: +

现在,检查 /etc/udev/rules.d/70-persistent-net.rules 文件,找出分配给网络设备的名称:

 cat /etc/udev/rules.d/70-persistent-net.rules
@@ -113,180 +82,90 @@ 

[Note]

- Note + 注意

-

- 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_idscsi_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]

- 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 文件进行修改,如下所示(其中 modeby-idby-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 总是指向到正确的设备。

@@ -381,25 +217,25 @@

  • Up + "第七章 系统配置">返回
  • Home + "Linux From Scratch - Version 8.0 ">首页

diff --git a/lfs-8.0/chapter07/udev.html b/lfs-8.0/chapter07/udev.html index 4566711..22ef3de 100644 --- a/lfs-8.0/chapter07/udev.html +++ b/lfs-8.0/chapter07/udev.html @@ -3,9 +3,9 @@ + "application/xhtml+xml; charset=utf-8" /> - 7.3. Overview of Device and Module Handling + 7.3. 设备及模块管理综述 @@ -19,425 +19,203 @@

Linux From Scratch - Version 8.0

- Chapter 7. System Configuration + 第七章 系统配置

  • Up + "第七章 系统配置">返回
  • Home + "Linux From Scratch - Version 8.0 ">首页

- 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. +

通常来说,Linux 系统使用静态设备创建方法,由此在 /dev 目录创建了大量的设备节点(有时甚至达到数千个),而不管相应的硬件设备是否实际存在。这通常由 MAKEDEV 脚本完成,该脚本包括若干对 mknod 程序的调用,其中包含任何可能存在于世界中的大大小小的设备的编号。

-

- 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. +

通过使用 Udev 方法,只有那些被内核检测到的设备才能创建设备节点。由于这些设备节点在系统引导时创建,因此它们将被存储于 devtmpfs 文件系统(一个完全位于系统内存中的虚拟文件系统)中。设备节点不需要太多空间,因此使用的内存可以忽略不计。

- 7.3.1. History + 7.3.1. 历史

-

- 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. +

2000 年 2 月,一个名为 devfs 的新文件系统被合并到 2.3.46 内核中,并且在 2.4 系列稳定内核中可用。尽管相关的内核源代码本身存在,但这种动态创建设备的方法从未得到核心内核开发者的广泛支持。

-

- 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. +

采用 devfs 方法的主要问题是处理设备检测、创建和命名的方式。后一个问题,即设备节点命名,也许是最关键的问题。通常得到认可的是如果允许对设备名称进行配置,那么设备命名策略应由系统管理员决定,而不是由任何特定的开发人员施加。devfs 文件系统也遭受其设计中固有的竞争条件的影响,如果不对内核进行大量修改,就无法得到修复。由于缺乏维护,它被长时间标记为被淘汰状态,并最终于 2006 年 6 月从内核中删除。

-

- 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. +

经过不稳定的 2.5 内核树的发展,之后发布的 2.6 系列稳定内核中,诞生了一个称为 sysfs 的新的虚拟文件系统。sysfs 的任务是将系统的硬件配置视图导出到用户空间进程。通过用户空间的可视化表示,开发一个用户空间进程以替换 devfs 变得更加现实。

- 7.3.2. Udev Implementation + 7.3.2. Udev 实现

7.3.2.1. Sysfs

-

- 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). +

上文简要介绍了 sysfs 文件系统。大家可能想知道 sysfs 如何知道系统上存在的设备以及应该使用哪些设备号。对于已经编译到内核中的驱动程序,当被内核检测时,直接通过 sysfs(位于 devtmpfs 内部)来注册对象。对于编译为模块的驱动程序,当注册模块加载时,会发生注册。一旦挂载了 sysfs 文件系统(位于 /sys),驱动程序使用 sysfs 注册的数据可用于用户空间进程和 udevd 以进行处理(包括对设备节点的修改)。

- 7.3.2.2. Device Node Creation + 7.3.2.2. 设备节点的创建

-

- 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. +

设备文件由内核通过 devtmpfs 文件系统创建。任何希望注册设备节点的驱动程序都将通过 devtmpfs (由驱动程序核心)来完成。当 devtmpfs 实例挂载在 /dev 上时,设备节点将以固定的名称、权限和所有者初始创建。

-

- 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. +

不久之后,内核将向 udevd 发送一个 uevent。根据 /etc/udev/rules.d/lib/udev/rules.d/run/udev/rules.d 目录中的文件中指定的规则,udevd 将为设备节点创建其他符号链接,或更改其权限、所有者或组,或修改该对象的内部 udevd 数据库条目(名称)。

-

- 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. +

这三个目录中的规则被编号,并且这三个目录被合并在一起。如果 udevd 找不到正在创建的设备的规则,那么会将其权限和所有权指定为 devtmpfs 最初所使用的。

- 7.3.2.3. Module Loading + 7.3.2.3. 模块的加载

-

- 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. +

编译为模块的设备驱动程序可能会在其中内置别名。别名在 modinfo 程序的输出中可见,通常与模块支持的设备的总线特定标识符相关。例如,snd-fm801 驱动程序支持供应商 ID 为 0x1319、设备 ID 为 0x0801 的 PCI 设备,并具有 pci:v00001319d00000801sv*sd*bc04sc01i* 的别名。对于大多数设备,总线驱动程序通过 sysfs 导出所处理设备的驱动程序的别名。例如,/sys/bus/pci/devices/0000:00:0d.0/modalias 文件可能包含字符串 pci:v00001319d00000801sv00001319sd00001319bc04sc01i00。Udev 提供的默认规则将引起 udevdMODALIAS uevent 环境变量的内容(它们应与 sysfs 中的 modalias 文件的内容相同)调用 /sbin/modprobe,从而加载别名与经过通配符扩展的字符串相匹配的所有模块。

-

- 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. +

在这个例子中,这就意味着除了 snd-fm801 之外,过时的(和不需要的)forte 驱动程序将被加载(如果可用的话)。请参阅下文了解如何防止加载不需要的驱动程序。

-

- The kernel itself is also able to load modules for network - protocols, filesystems and NLS support on demand. +

内核本身也可以根据需要加载网络协议、文件系统和 NLS 支持模块。

- 7.3.2.4. Handling Hotpluggable/Dynamic Devices + 7.3.2.4. 热插拔/动态设备的处理

-

- 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. +

当插入设备,例如通用串行总线(USB)MP3 播放器时,内核会识别设备已连接,并生成 uevent。这个 uevent 之后由 udevd 做如前所述的处理。

- 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. +

如果 Udev 具有总线特定的别名,并且总线驱动程序正确地将必需的别名导出到 sysfs,那么 Udev 将仅加载内核模块。在其他情况下,应通过其他方式安排模块的加载。使用 Linux-4.9.9,Udev 可以为 INPUT,IDE,PCI,USB,SCSI,SERIO 和 FireWire 设备加载正确写入的驱动程序。

-

- 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. +

要确定需要的设备驱动程序是否具有对 Udev 的必要支持,请以模块名称作为参数运行 modinfo。尝试将设备目录定位在 /sys/bus 下,检查是否存在 modalias 文件。

-

- 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. +

如果在 modalias 中存在 sysfs 文件,则驱动程序支持该设备,并可直接与该设备进行通信,但不具有别名,这是驱动程序中的错误。在没有 Udev 帮助的情况下加载驱动程序,并期望问题在以后修复。

-

- 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. +

如果在 /sys/bus 下的相关目录中没有 modalias 文件,这意味着内核开发人员尚未向此总线类型添加 modalias 支持。在 Linux-4.9.9 中,这是 ISA 总线存在的情况。期望在以后的内核版本中修复此问题。

-

- Udev is not intended to load wrapper - drivers such as snd-pcm-oss and non-hardware drivers - such as loop at all. +

Udev 不会加载“封装”(wrapper)的驱动程序,如 snd-pcm-oss,以及非硬件驱动程序,如 loop

- 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: +

如果“封装”(wrapper)模块仅增强了某些其他模块提供的功能(例如,snd-pcm-oss 通过使声卡可用于 OSS 应用程序来增强 snd-pcm 的功能),请在 Udev 加载后配置 modprobe 以加载封装的模块。为此,请在任何 /etc/modprobe.d/<filename>.conf 文件中添加 softdep 行。例如:

 softdep snd-pcm post: snd-pcm-oss
 
-

- 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. +

请注意,softdep 命令还允许 pre: 依赖,或 pre:post: 之间的混合。有关 softdep 语法和功能的更多信息,请参阅 modprobe.d(5) 手册页。

-

- 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. +

如果所涉及的模块不是封装模块,并且本身很有用,请配置 modules 引导脚本以在系统启动时加载该模块。为此,请将模块名称添加到 /etc/sysconfig/modules 文件中。这对于封装模块也是如此,但在这种情况下并不是最佳的解决方案。

- 7.3.3.3. Udev loads some unwanted module + 7.3.3.3. Udev 加载了一些不需要的模块

-

- 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. +

这可能是之前的问题的另一个表现。如果不是,并且您的规则使用 sysfs 属性,则可能是内核计时问题,这将在后来的内核中修复。对于目前来说,可以通过创建一个等待使用的 sysfs 属性并将其附加到 /etc/udev/rules.d/10-wait_for_sysfs.rules 文件的规则来解决(如果不存在,那么创建此文件)。如果这样做有帮助,请通知 LFS 开发列表。

- 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 不会创建错误的设备。

-

- 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. +

如果内核驱动程序没有将其数据导出到 sysfs,那么 Udev 无需创建设备节点所需的信息。这在内核树以外的第三方驱动程序中最常见。可以在 /lib/udev/devices 中创建一个具有适合的主要/次要编号的静态设备节点(请参阅内核文档中的 devices.txt 文件或第三方驱动程序供应商提供的文档)。静态设备节点将被 /dev 复制到 /dev

- 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. +

这是因为 Udev 在设计上是并行地处理 uevents 并且加载模块的,因此会出现不可预测的顺序。这永远不会 固定。因此不应该依赖内核设备名称是稳定的。相反,根据设备的某些稳定属性(如序列号或 Udev 安装的各种 *_id 程序的输出)创建自己的规则,以创建具有稳定名称的符号链接。有关示例请参见 7.4. “管理设备”7.5. “通用网络设置”

- 7.3.4. Useful Reading + 7.3.4. 有用的阅读资料

- Additional helpful documentation is available at the following - sites: + 以下站点提供其他有用的资料:

- Checks the integrity of the file systems before they are - mounted (with the exception of journal and network based - file systems) + 文件系统挂载前检查文件系统的完整性(基于日志和网络的文件系统除外)

- 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 文件

- Loads the correct keymap table for the desired keyboard - layout; it also sets the screen font + 加载所需键盘布局的正确键位表;同时设置屏幕字体

- Contains common functions, such as error and status - checking, that are used by several bootscripts + 包含几个引导脚本所使用的常见功能,如错误和状态检查

- Halts the system + 停止系统

- Stops a network device + 停止网络设备

- Initializes a network device + 初始化网络设备

- Sets up the system's hostname and local loopback device + 设置系统的主机名和本地环回设备

- Loads kernel modules listed in /etc/sysconfig/modules, using arguments - that are also given there + 加载 /etc/sysconfig/modules 中列出的内核模块,使用其中给出的参数

- Mounts all file systems, except ones that are marked - noauto or are - network based + 挂载所有文件系统,除了标记为 noauto 或基于网络的文件系统

- Mounts virtual kernel file systems, such as proc + 挂载虚拟内核文件系统,如 proc

- Sets up network interfaces, such as network cards, and - sets up the default gateway (where applicable) + 设置网络接口(例如网卡),并在适用的时候设置默认网关

- 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 + 主运行级别控制脚本;它负责按照正在处理的符号链接的名称的顺序,依次运行所有其他引导文件

- Reboots the system + 重新启动系统

- Makes sure every process is terminated before the system - reboots or halts + 确保所有进程在系统重新启动或停止之前已经终止

- Resets the kernel clock to local time in case the - hardware clock is not set to UTC time + 将内核时钟重置为本地时间,以避免硬件时钟未设置为 UTC 时间的情况发生

- Provides the functionality needed to assign a static - Internet Protocol (IP) address to a network interface + 提供为网络接口分配静态 IP 地址所需的功能

- Enables and disables swap files and partitions + 启用和禁用交换文件和分区

- Loads system configuration values from /etc/sysctl.conf, if that file exists, - into the running kernel + 将系统配置值从 /etc/sysctl.conf(如果该文件存在)加载到正在运行的内核中

- Starts and stops the system and kernel log daemons + 启动和停止系统和内核日志守护进程

- A template to create custom bootscripts for other daemons + 为其他守护进程创建自定义引导脚本的模板

- Prepares the /dev directory - and starts Udev + 准备 /dev 目录并启动 Udev

- 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