1
0

udev.xml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  4. <!ENTITY % general-entities SYSTEM "../general.ent">
  5. %general-entities;
  6. ]>
  7. <sect1 id="ch-scripts-udev">
  8. <?dbhtml filename="udev.html"?>
  9. <title>设备和模块管理概述</title>
  10. <indexterm zone="ch-scripts-udev">
  11. <primary sortas="a-Udev">Udev</primary>
  12. <secondary>usage</secondary>
  13. </indexterm>
  14. <!--para>In <xref linkend="chapter-building-system"/>, we installed the Udev
  15. package when <phrase revision="sysv">eudev</phrase>
  16. <phrase revision="systemd">systemd</phrase> was built. Before we go into the
  17. details regarding how this works, a brief history of previous methods of
  18. handling devices is in order.</para-->
  19. <para>在 <xref linkend="chapter-building-system"/> 中,我们在构建
  20. <phrase revision="sysv">eudev</phrase>
  21. <phrase revision="systemd">systemd</phrase>
  22. 时安装了 Udev 软件包。在我们详细讨论它的工作原理之前,
  23. 首先按时间顺序简要介绍历史上曾经使用过的设备管理方式。</para>
  24. <!--para>Linux systems in general traditionally used a static device creation
  25. method, whereby a great many device nodes were created under <filename
  26. class="directory">/dev</filename> (sometimes literally thousands of nodes),
  27. regardless of whether the corresponding hardware devices actually existed. This
  28. was typically done via a <command>MAKEDEV</command> script, which contains a
  29. number of calls to the <command>mknod</command> program with the relevant
  30. major and minor device numbers for every possible device that might exist in
  31. the world.</para-->
  32. <para>传统的 Linux 系统通常使用静态设备创建方法,即在
  33. <filename class="directory">/dev</filename> 下创建大量设备节点
  34. (有时有数千个节点),无论对应的硬件设备是否真的存在。
  35. 一般通过 <command>MAKEDEV</command> 脚本完成这一工作,
  36. 它包含以相关的主设备号和次设备号,
  37. 为世界上可能存在的每个设备建立节点的大量 <command>mknod</command>
  38. 程序调用。</para>
  39. <!--para>Using the Udev method, only those devices which are detected by the
  40. kernel get device nodes created for them. Because these device nodes will be
  41. created each time the system boots, they will be stored on a <systemitem
  42. class="filesystem">devtmpfs</systemitem> file system (a virtual file system
  43. that resides entirely in system memory). Device nodes do not require much
  44. space, so the memory that is used is negligible.</para-->
  45. <para>使用 Udev 方法,
  46. 只有那些被内核检测到的设备才会获得为它们创建的设备节点。
  47. 由于这些设备节点在每次引导系统时都会重新创建,
  48. 它们被储存在 <systemitem class="filesystem">devtmpfs</systemitem>
  49. 文件系统中(一个虚拟文件系统,完全驻留在系统内存)。
  50. 设备节点不需要太多空间,它们使用的系统内存可以忽略不计。</para>
  51. <sect2>
  52. <title>历史</title>
  53. <!--para>In February 2000, a new filesystem called <systemitem
  54. class="filesystem">devfs</systemitem> was merged into the 2.3.46 kernel
  55. and was made available during the 2.4 series of stable kernels. Although
  56. it was present in the kernel source itself, this method of creating devices
  57. dynamically never received overwhelming support from the core kernel
  58. developers.</para-->
  59. <para>在 2000 年 2 月,一个称为 <systemitem class="filesystem">devfs
  60. </systemitem> 的新文件系统被合并到 2.3.46 版内核中,
  61. 并在 2.4 系列稳定内核中可用。尽管它本身曾经存在于内核源代码中,
  62. 但这种设备节点动态创建方法从未得到内核核心开发者的大力支持。
  63. </para>
  64. <!--para>The main problem with the approach adopted by <systemitem
  65. class="filesystem">devfs</systemitem> was the way it handled device
  66. detection, creation, and naming. The latter issue, that of device node
  67. naming, was perhaps the most critical. It is generally accepted that if
  68. device names are allowed to be configurable, then the device naming policy
  69. should be up to a system administrator, not imposed on them by any
  70. particular developer(s). The <systemitem
  71. class="filesystem">devfs</systemitem> file system also suffered from race
  72. conditions that were inherent in its design and could not be fixed without a
  73. substantial revision to the kernel. It was marked as deprecated for a long
  74. period &ndash; due to a lack of maintenance &ndash; and was finally removed
  75. from the kernel in June, 2006.</para-->
  76. <para><systemitem class="filesystem">devfs</systemitem>
  77. 采用的这种方法的主要问题是它处理设备的检测、创建和命名的方式,
  78. 其中最致命的是设备节点命名方式。一个被广泛接受的理念是,
  79. 如果设备名称是允许配置的,那么设备命名策略应该由系统管理员,
  80. 而不是某个(些)特定开发者决定。
  81. <systemitem class="filesystem">devfs</systemitem>
  82. 还受到其设计中固有的竞争条件的严重影响,
  83. 在不对内核进行大量修改的前提下无法修复这一问题。
  84. 在一段时间后,由于缺乏维护,它被标记为过时特性,最终在
  85. 2006 年 6 月被从内核中移除。</para>
  86. <!--para>With the development of the unstable 2.5 kernel tree, later released
  87. as the 2.6 series of stable kernels, a new virtual filesystem called
  88. <systemitem class="filesystem">sysfs</systemitem> came to be. The job of
  89. <systemitem class="filesystem">sysfs</systemitem> is to export a view of
  90. the system's hardware configuration to userspace processes. With this
  91. userspace-visible representation, the possibility of developing a userspace
  92. replacement for <systemitem class="filesystem">devfs</systemitem> became
  93. much more realistic.</para-->
  94. <para>在不稳定的 2.5 系列内核开发过程中,加入了一个新的虚拟文件系统,
  95. 称为 <systemitem class="filesystem">sysfs</systemitem> ,
  96. 并在 2.6 系列稳定内核中发布。
  97. 它的工作是将系统硬件配置信息导出给用户空间进程,
  98. 有了这个用户空间可见的配置描述,就可能开发一种
  99. <systemitem class="filesystem">devfs</systemitem>
  100. 的用户空间替代品。</para>
  101. </sect2>
  102. <sect2>
  103. <title>Udev 实现</title>
  104. <sect3>
  105. <title>Sysfs</title>
  106. <!--para>The <systemitem class="filesystem">sysfs</systemitem> filesystem
  107. was mentioned briefly above. One may wonder how <systemitem
  108. class="filesystem">sysfs</systemitem> knows about the devices present on
  109. a system and what device numbers should be used for them. Drivers that
  110. have been compiled into the kernel directly register their objects with a
  111. <systemitem class="filesystem">sysfs</systemitem> (devtmpfs internally)
  112. as they are detected by the kernel. For drivers compiled as modules, this
  113. registration will happen when the module is loaded. Once the <systemitem
  114. class="filesystem">sysfs</systemitem> filesystem is mounted (on /sys),
  115. data which the drivers register with <systemitem
  116. class="filesystem">sysfs</systemitem> are available to userspace
  117. processes and to udevd for processing (including modifications to device
  118. nodes).</para-->
  119. <para>前面已经简要提到了
  120. <systemitem class="filesystem">sysfs</systemitem> 文件系统。
  121. 有些读者可能好奇,
  122. <systemitem class="filesystem">sysfs</systemitem>
  123. 是如何知道系统中存在哪些设备,以及应该为它们使用什么设备号的。
  124. 答案是,那些编译到内核中的驱动程序在它们的对象被内核检测到时,
  125. 直接将它们注册到 <systemitem class="filesystem">sysfs</systemitem>
  126. (内部的 devtmpfs)。对于那些被编译为模块的驱动程序,
  127. 注册过程在模块加载时进行。只要
  128. <systemitem class="filesystem">sysfs</systemitem>
  129. 文件系统被挂载好(位于 /sys),用户空间程序即可使用驱动程序注册在
  130. <systemitem class="filesystem">sysfs</systemitem>
  131. 中的数据,Udev 就能够使用这些数据对设备进行处理
  132. (包括修改设备节点)。</para>
  133. </sect3>
  134. <sect3>
  135. <title>设备节点的创建</title>
  136. <!--para>Device files are created by the kernel by the <systemitem
  137. class="filesystem">devtmpfs</systemitem> filesystem. Any driver that
  138. wishes to register a device node will go through the <systemitem
  139. class="filesystem">devtmpfs</systemitem> (via the driver core) to do it.
  140. When a <systemitem class="filesystem">devtmpfs</systemitem> instance is
  141. mounted on <filename class="directory">/dev</filename>, the device node
  142. will initially be created with a fixed name, permissions, and
  143. owner.</para-->
  144. <para>内核通过 <systemitem class="filesystem">devtmpfs</systemitem>
  145. 直接创建设备文件,任何希望注册设备节点的驱动程序都要通过
  146. <systemitem class="filesystem">devtmpfs</systemitem>
  147. (经过驱动程序核心)实现。当一个
  148. <systemitem class="filesystem">devtmpfs</systemitem>
  149. 实例被挂载到 <filename class="directory">/dev</filename>
  150. 时,设备节点将被以固定的名称、访问权限和所有者首次创建。</para>
  151. <!--para>A short time later, the kernel will send a uevent to <command>
  152. udevd</command>. Based on the rules specified in the files within the
  153. <filename class="directory">/etc/udev/rules.d</filename>, <filename
  154. class="directory">/lib/udev/rules.d</filename>, and <filename
  155. class="directory">/run/udev/rules.d</filename> directories, <command>
  156. udevd</command> will create additional symlinks to the device node, or
  157. change its permissions, owner, or group, or modify the internal
  158. <command>udevd</command> database entry (name) for that object.</para-->
  159. <para>很快,内核会向 <command>udevd</command> 发送一个 uevent 事件。
  160. 根据 <filename class="directory">/etc/udev/rules.d</filename>、
  161. <filename class="directory">/lib/udev/rules.d</filename>
  162. 以及 <filename class="directory">/run/udev/rules.d</filename>
  163. 中的规则,<command>udevd</command>
  164. 将为设备节点创建额外的符号链接,或修改其访问权限、所有者、属组,
  165. 或修改该对象的 <command>udevd</command> 数据库条目(名称)。
  166. </para>
  167. <!--para>The rules in these three directories are numbered and all three
  168. directories are merged together. If <command>udevd</command> can't find a
  169. rule for the device it is creating, it will leave the permissions and
  170. ownership at whatever <systemitem
  171. class="filesystem">devtmpfs</systemitem> used initially.</para-->
  172. <para>以上三个目录中的规则都被编号,且这三个目录的内容将合并处理。
  173. 如果 <command>udevd</command> 找不到它正在创建的设备对应的规则,
  174. 它将会沿用 <systemitem class="filesystem">devtmpfs</systemitem>
  175. 最早使用的访问权限和所有权。</para>
  176. </sect3>
  177. <sect3 id="module-loading">
  178. <title>模块加载</title>
  179. <!--para>Device drivers compiled as modules may have aliases built into them.
  180. Aliases are visible in the output of the <command>modinfo</command>
  181. program and are usually related to the bus-specific identifiers of devices
  182. supported by a module. For example, the <emphasis>snd-fm801</emphasis>
  183. driver supports PCI devices with vendor ID 0x1319 and device ID 0x0801,
  184. and has an alias of <quote>pci:v00001319d00000801sv*sd*bc04sc01i*</quote>.
  185. For most devices, the bus driver exports the alias of the driver that
  186. would handle the device via <systemitem
  187. class="filesystem">sysfs</systemitem>. E.g., the
  188. <filename>/sys/bus/pci/devices/0000:00:0d.0/modalias</filename> file
  189. might contain the string
  190. <quote>pci:v00001319d00000801sv00001319sd00001319bc04sc01i00</quote>.
  191. The default rules provided with Udev will cause <command>udevd</command>
  192. to call out to <command>/sbin/modprobe</command> with the contents of the
  193. <envar>MODALIAS</envar> uevent environment variable (which should be the
  194. same as the contents of the <filename>modalias</filename> file in sysfs),
  195. thus loading all modules whose aliases match this string after wildcard
  196. expansion.</para-->
  197. <para>编译为内核模块的设备驱动程序可能有内建的别名,
  198. 别名可以通过 <command>modinfo</command> 程序查询,
  199. 它通常和该模块支持的设备的总线相关标识符有关。
  200. 例如,<emphasis>snd-fm801</emphasis> 驱动程序支持厂商 ID 为
  201. 0x1319,设备 ID 为 0x0801 的 PCI 设备,其别名为
  202. <quote>pci:v00001319d00000801sv*sd*bc04sc01l*</quote>。
  203. 对于多数设备,总线驱动程序会通过
  204. <systemitem class="filesystem">sysfs</systemitem>
  205. 导出应该处理该设备的驱动程序别名,例如
  206. <filename>/sys/bus/pci/devices/0000:00:0d.0/modalias</filename>
  207. 文件应该包含字符串
  208. <quote>pci:v00001319d00000801sv00001319sd00001319bc04sc01i00
  209. </quote>。Udev 附带的默认规则会导致 <command>udevd</command>
  210. 以 <envar>MODALIAS</envar> uevent 环境变量的内容
  211. (应该和 sysfs 的 <filename>modalias</filename> 文件内容一致)调用
  212. <command>/sbin/modprobe</command>,并加载在通配符扩展后,
  213. 别名能够匹配该字符串的所有模块。</para>
  214. <!--para>In this example, this means that, in addition to
  215. <emphasis>snd-fm801</emphasis>, the obsolete (and unwanted)
  216. <emphasis>forte</emphasis> driver will be loaded if it is
  217. available. See below for ways in which the loading of unwanted drivers can
  218. be prevented.</para-->
  219. <para>在本例中,这意味着除了 <emphasis>snd-fm801</emphasis>
  220. 外,过时(且不希望)的 <emphasis>forte</emphasis> 如果可用,
  221. 也会被加载。下面将介绍防止加载不希望的驱动程序的方法。</para>
  222. <!--para>The kernel itself is also able to load modules for network
  223. protocols, filesystems and NLS support on demand.</para-->
  224. <para>内核本身也能够在需要时为网络协议、文件系统和 NLS
  225. 支持加载模块。</para>
  226. </sect3>
  227. <sect3>
  228. <title>处理热插拔/动态设备</title>
  229. <!--para>When you plug in a device, such as a Universal Serial Bus (USB) MP3
  230. player, the kernel recognizes that the device is now connected and
  231. generates a uevent. This uevent is then handled by
  232. <command>udevd</command> as described above.</para-->
  233. <para>当您插入一个设备,例如通用串行总线(USB) MP3 播放器时,
  234. 内核能够发现该设备现在已经被连接到系统,并生成一个 uevent 事件。
  235. 之后 <command>udevd</command> 像前面描述的一样,处理该
  236. uevent 事件。</para>
  237. </sect3>
  238. </sect2>
  239. <sect2>
  240. <title>加载模块和创建设备时的问题</title>
  241. <para>在自动创建设备节点时,可能发现一些问题。</para>
  242. <sect3>
  243. <title>内核模块没有自动加载</title>
  244. <!--para>Udev will only load a module if it has a bus-specific alias and the
  245. bus driver properly exports the necessary aliases to <systemitem
  246. class="filesystem">sysfs</systemitem>. In other cases, one should
  247. arrange module loading by other means. With Linux-&linux-version;, Udev is
  248. known to load properly-written drivers for INPUT, IDE, PCI, USB, SCSI,
  249. SERIO, and FireWire devices.</para-->
  250. <para>Udev 只加载拥有总线特定别名,且总线驱动程序正确地向
  251. <systemitem class="filesystem">sysfs</systemitem>
  252. 导出了必要别名的模块。如果情况不是这样,
  253. 您应该考虑用其他方法加载模块。在 Linux-&linux-version; 中,
  254. 已知 Udev 可以加载编写正确的 INPUT、IDE、PCI、USB、SCSI、SERIO
  255. 和 FireWire 驱动程序。</para>
  256. <!--para>To determine if the device driver you require has the necessary
  257. support for Udev, run <command>modinfo</command> with the module name as
  258. the argument. Now try locating the device directory under
  259. <filename class="directory">/sys/bus</filename> and check whether there is
  260. a <filename>modalias</filename> file there.</para-->
  261. <para>为了确定您需要的设备驱动程序是否包含 Udev 支持,
  262. 以模块名为参数运行 <command>modinfo</command> 命令。
  263. 然后试着在 <filename class="directory">/sys/bus</filename>
  264. 中找到设备对应的目录,并检查其中是否有
  265. <filename>modalias</filename> 文件。</para>
  266. <!--para>If the <filename>modalias</filename> file exists in <systemitem
  267. class="filesystem">sysfs</systemitem>, the driver supports the device and
  268. can talk to it directly, but doesn't have the alias, it is a bug in the
  269. driver. Load the driver without the help from Udev and expect the issue
  270. to be fixed later.</para-->
  271. <para>如果 <systemitem class="filesystem">sysfs</systemitem> 中有
  272. <filename>modalias</filename> 文件,说明驱动程序支持该设备,
  273. 并能够直接和设备交互,但却没有正确地别名。这是驱动程序的 bug ,
  274. 您需要不通过 Udev 直接加载驱动,并等待这个问题日后被解决。</para>
  275. <!--para>If there is no <filename>modalias</filename> file in the relevant
  276. directory under <filename class="directory">/sys/bus</filename>, this
  277. means that the kernel developers have not yet added modalias support to
  278. this bus type. With Linux-&linux-version;, this is the case with ISA
  279. busses. Expect this issue to be fixed in later kernel versions.</para-->
  280. <para>如果在 <filename class="directory">/sys/bus</filename>
  281. 下的相关目录中没有 <filename>modalias</filename> 文件,
  282. 说明内核开发者尚未对该总线类型增加 modalias 支持。
  283. 在 Linux-&linux-version; 中,ISA 总线不受支持。
  284. 只能等待这个问题在日后被解决。</para>
  285. <!--para>Udev is not intended to load <quote>wrapper</quote> drivers such as
  286. <emphasis>snd-pcm-oss</emphasis> and non-hardware drivers such as
  287. <emphasis>loop</emphasis> at all.</para-->
  288. <para>Udev 根本不会尝试加载 <emphasis>snd-pcm-oss</emphasis>
  289. 等 <quote>包装器</quote> 驱动程序,或 <emphasis>loop</emphasis>
  290. 等非硬件驱动程序。</para>
  291. </sect3>
  292. <sect3>
  293. <title>内核模块没有自动加载,且 Udev 不尝试加载它</title>
  294. <!--para>If the <quote>wrapper</quote> module only enhances the
  295. functionality provided by some other module (e.g.,
  296. <emphasis>snd-pcm-oss</emphasis> enhances the functionality of
  297. <emphasis>snd-pcm</emphasis> by making the sound cards available to OSS
  298. applications), configure <command>modprobe</command> to load the wrapper
  299. after Udev loads the wrapped module. To do this, add a
  300. <quote>softdep</quote> line to the corresponding
  301. <filename>/etc/modprobe.d/<replaceable>&lt;filename&gt;</replaceable>.conf</filename>
  302. file. For example:</para-->
  303. <para>如果 <quote>包装器</quote> 仅仅用于增强其他模块的功能
  304. (例如,<emphasis>snd-pcm-oss</emphasis> 增强
  305. <emphasis>snd-pcm</emphasis> 的功能,
  306. 使 OSS 应用程序能够使用声卡),需要配置
  307. <command>modprobe</command> 使其在 Udev 加载被包装的模块时,
  308. 自动加载包装器。为此,在对应的
  309. <filename>/etc/modprobe.d/<replaceable>&lt;filename&gt;</replaceable>.conf
  310. </filename> 文件中加入一个
  311. <quote>softdep</quote> 行,例如:</para>
  312. <screen role="nodump"><literal>softdep snd-pcm post: snd-pcm-oss</literal></screen>
  313. <!--para>Note that the <quote>softdep</quote> command also allows
  314. <literal>pre:</literal> dependencies, or a mixture of both
  315. <literal>pre:</literal> and <literal>post:</literal>. See the
  316. <filename>modprobe.d(5)</filename> manual page for more information
  317. on <quote>softdep</quote> syntax and capabilities.</para-->
  318. <para>注意 <quote>softdep</quote> 命令也允许 <literal>pre:</literal>
  319. 依赖项,或混合使用 <literal>pre:</literal> 和
  320. <literal>post:</literal> 依赖项。参阅
  321. <filename>modprobe.d(5)</filename> man 手册页面,
  322. 了解更多关于 <quote>softdep</quote> 语法和功能的信息。</para>
  323. <!--para>If the module in question is not a wrapper and is useful by itself,
  324. configure the <command>modules</command> bootscript to load this
  325. module on system boot. To do this, add the module name to the
  326. <filename>/etc/sysconfig/modules</filename> file on a separate line.
  327. This works for wrapper modules too, but is suboptimal in that case.</para-->
  328. <para>如果出现问题的模块不是包装器,而是本身就有特定功能的模块,
  329. 需要配置 <command>modules</command> 启动脚本以在系统引导时加载它。
  330. 为此,将模块名添加到 <filename>/etc/sysconfig/modules</filename>
  331. 中,作为单独的一行。包装器模块也可以被添加到这里,
  332. 但对于包装器来说这不是最好的方案。</para>
  333. </sect3>
  334. <sect3>
  335. <title>Udev 加载了不希望的模块</title>
  336. <!--para>Either don't build the module, or blacklist it in a
  337. <filename>/etc/modprobe.d/blacklist.conf</filename> file as done with the
  338. <emphasis>forte</emphasis> module in the example below:</para-->
  339. <para>不要构建该模块,或者在
  340. <filename>/etc/modprobe.d/blacklist.conf</filename>
  341. 文件中禁用它。以 <emphasis>forte</emphasis> 为例,
  342. 下面一行禁用了该模块:</para>
  343. <screen role="nodump"><literal>blacklist forte</literal></screen>
  344. <!--para>Blacklisted modules can still be loaded manually with the
  345. explicit <command>modprobe</command> command.</para-->
  346. <para>被禁用的模块仍然可以通过直接执行 <command>modprobe</command>
  347. 手动加载。</para>
  348. </sect3>
  349. <sect3>
  350. <title>Udev 创建了错误的设备或错误的符号链接</title>
  351. <!--para>This usually happens if a rule unexpectedly matches a device. For
  352. example, a poorly-written rule can match both a SCSI disk (as desired)
  353. and the corresponding SCSI generic device (incorrectly) by vendor.
  354. Find the offending rule and make it more specific, with the help of the
  355. <command>udevadm info</command> command.</para-->
  356. <para>这一般是由于一条规则意外地匹配了某个设备。
  357. 例如,一个写得不好的规则可能同时匹配到 SCSI 磁盘(正确的)
  358. 和对应厂商的 SCSI 通用设备(不正确的)。
  359. 找到引起问题的规则,并通过 <command>udevadm info</command>
  360. 的帮助,将它进一步细化。</para>
  361. </sect3>
  362. <sect3>
  363. <title>Udev 规则工作不可靠</title>
  364. <!--para>This may be another manifestation of the previous problem. If not,
  365. and your rule uses <systemitem class="filesystem">sysfs</systemitem>
  366. attributes, it may be a kernel timing issue, to be fixed in later kernels.
  367. For now, you can work around it by creating a rule that waits for the used
  368. <systemitem class="filesystem">sysfs</systemitem> attribute and appending
  369. it to the <filename>/etc/udev/rules.d/10-wait_for_sysfs.rules</filename>
  370. file (create this file if it does not exist). Please notify the LFS
  371. Development list if you do so and it helps.</para-->
  372. <para>这可能是前一个问题的另一个表现形式。如果不是,
  373. 而且您的规则使用了
  374. <systemitem class="filesystem">sysfs</systemitem> 属性,
  375. 这个问题可能由内核计时问题引发,这类问题需要在新的内核版本中修复。
  376. 目前,您可以创建一条规则以等待被使用的
  377. <systemitem class="filesystem">sysfs</systemitem> 属性,
  378. 并将它附加到 <filename>/etc/udev/rules.d/10-wait-for-sysfs.rules
  379. </filename> 文件中(如果不存在就创建一个文件),绕过这个问题。
  380. 如果您通过这种方法解决了问题,请通知 LFS 开发邮件列表。</para>
  381. </sect3>
  382. <sect3>
  383. <title>Udev 没有创建设备</title>
  384. <!--para>Further text assumes that the driver is built statically into the
  385. kernel or already loaded as a module, and that you have already checked
  386. that Udev doesn't create a misnamed device.</para-->
  387. <para>以下内容假设驱动程序已经被编译到内核中,或作为模块被加载,
  388. 而且您已经检查过并确认 Udev 没有创建命名错误的设备。</para>
  389. <!--para>Udev has no information needed to create a device node if a kernel
  390. driver does not export its data to
  391. <systemitem class="filesystem">sysfs</systemitem>. This is most common
  392. with third party drivers from outside the kernel tree. Create a static
  393. device node in <filename>/lib/udev/devices</filename> with the
  394. appropriate major/minor numbers (see the file
  395. <filename>devices.txt</filename> inside the kernel documentation or the
  396. documentation provided by the third party driver vendor). The static
  397. device node will be copied to <filename class="directory">/dev</filename>
  398. by <command>udev</command>.</para-->
  399. <para>如果驱动程序没有将它的信息导出到
  400. <systemitem class="filesystem">sysfs</systemitem>,
  401. Udev 就无法获得创建设备节点必需的信息。
  402. 这种问题往往出现在内核源代码树以外的第三方驱动程序中。
  403. 这时,需要在 <filename>/lib/udev/devices</filename>
  404. 中使用正确的主设备号和次设备号,创建一个静态设备节点
  405. (参考内核文档中的 <filename>devices.txt</filename>
  406. 或第三方驱动厂商提供的文档),<command>udev</command>
  407. 会将该静态设备节点复制到 <filename class="directory">/dev
  408. </filename>。</para>
  409. </sect3>
  410. <sect3>
  411. <title>重启后设备命名顺序随机变化</title>
  412. <!--para>This is due to the fact that Udev, by design, handles uevents and
  413. loads modules in parallel, and thus in an unpredictable order. This will
  414. never be <quote>fixed</quote>. You should not rely upon the kernel device
  415. names being stable. Instead, create your own rules that make symlinks with
  416. stable names based on some stable attributes of the device, such as a
  417. serial number or the output of various *_id utilities installed by Udev.
  418. See <xref linkend="ch-scripts-symlinks"/> and
  419. <xref linkend="ch-scripts-network"/> for examples.</para-->
  420. <para>这是由于 Udev 从设计上就是并行加载模块的,因此无法预测加载顺序。
  421. 这个问题永远也不会被 <quote>修复</quote>。
  422. 您不应该指望内核提供稳定的设备命名,而是应该创建您自己的规则,
  423. 以根据设备的一些稳定属性,例如设备序列号或 Udev 安装的一些
  424. *_id 工具的输出,来创建具有稳定名称的符号链接。
  425. 可以参考 <xref linkend="ch-scripts-symlinks"/> 和
  426. <xref linkend="ch-scripts-network"/> 中的例子。</para>
  427. </sect3>
  428. </sect2>
  429. <sect2>
  430. <title>扩展阅读</title>
  431. <para>以下链接包含了一些额外的帮助文档:</para>
  432. <itemizedlist>
  433. <listitem>
  434. <para>A Userspace Implementation of <systemitem class="filesystem">devfs</systemitem>
  435. <ulink url="http://www.kroah.com/linux/talks/ols_2003_udev_paper/Reprint-Kroah-Hartman-OLS2003.pdf"/></para>
  436. </listitem>
  437. <listitem>
  438. <para>The <systemitem class="filesystem">sysfs</systemitem> Filesystem
  439. <ulink url="http://www.kernel.org/pub/linux/kernel/people/mochel/doc/papers/ols-2005/mochel.pdf"/></para>
  440. </listitem>
  441. <!-- No longer available
  442. <listitem>
  443. <para>Pointers to further reading
  444. <ulink url="http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html"/>
  445. </para>
  446. </listitem>
  447. -->
  448. </itemizedlist>
  449. </sect2>
  450. </sect1>