aboutsummaryrefslogtreecommitdiffstats
path: root/chapter06/udev.xml
blob: a92ddbc15dcf9dc22e5604fb026db9b6f911e4f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  <!ENTITY % general-entities SYSTEM "../general.ent">
  %general-entities;
]>

<sect1 id="ch-system-udev" role="wrap">
  <?dbhtml filename="udev.html"?>

  <title>Udev-&udev-version;</title>

  <indexterm zone="ch-system-udev">
    <primary sortas="a-Udev">Udev</primary>
  </indexterm>

  <sect2 role="package">
    <title/>

    <para>The Udev package contains programs for dynamic creation of device
    nodes.</para>

    <segmentedlist>
      <segtitle>&buildtime;</segtitle>
      <segtitle>&diskspace;</segtitle>

      <seglistitem>
        <seg>0.1 SBU</seg>
        <seg>4.8 MB</seg>
      </seglistitem>
    </segmentedlist>

    <segmentedlist>
      <segtitle>&dependencies;</segtitle>

      <seglistitem>
        <seg>Coreutils and Make</seg>
      </seglistitem>
    </segmentedlist>

  </sect2>

  <sect2 role="installation">
    <title>Installation of Udev</title>

    <para>Create some devices and directories that Udev cannot handle due to
    them being required very early in the boot process:</para>

<screen><userinput>install -dv /lib/{firmware,udev/devices/{pts,shm}}
mknod -m0666 /lib/udev/devices/null c 1 3
ln -sv /proc/self/fd /lib/udev/devices/fd
ln -sv /proc/self/fd/0 /lib/udev/devices/stdin
ln -sv /proc/self/fd/1 /lib/udev/devices/stdout
ln -sv /proc/self/fd/2 /lib/udev/devices/stderr
ln -sv /proc/kcore /lib/udev/devices/core</userinput></screen>

    <para>Compile the package:</para>

<screen><userinput>make EXTRAS="extras/ata_id extras/cdrom_id extras/edd_id \
            extras/firmware extras/floppy extras/scsi_id \
            extras/usb_id extras/volume_id"</userinput></screen>

    <variablelist>
      <title>The meaning of the make option:</title>

      <varlistentry>
        <term><parameter>EXTRAS=...</parameter></term>
        <listitem>
          <para>This builds several helper binaries that can aid in writing custom
          Udev rules.</para>
        </listitem>
      </varlistentry>

    </variablelist>

    <para>To test the results, issue:
    <userinput>make test</userinput>.</para>

    <para>Install the package:</para>

<screen><userinput>make DESTDIR=/ \
    EXTRAS="extras/ata_id extras/cdrom_id extras/edd_id \
            extras/firmware extras/floppy extras/scsi_id \
            extras/usb_id extras/volume_id" install</userinput></screen>

    <variablelist>
      <title>The meaning of the make parameter:</title>

      <varlistentry>
        <term><parameter>DESTDIR=/</parameter></term>
        <listitem>
          <para>This prevents the Udev build process from killing any
          <command>udevd</command> processes that may be running on the
          host system.</para>
        </listitem>
      </varlistentry>

    </variablelist>

    <para>Udev's configuration is far from ideal by default, so install
    the configuration files here:</para>

<screen><userinput>cp -v ../&udev-config-file; /etc/udev/rules.d/25-lfs.rules</userinput></screen>

    <para>Create some rules that work around broken sysfs attribute creation
    timing in linux-2.6.15:</para>

<screen><userinput>cat &gt;&gt; /etc/udev/rules.d/10-wait_for_sysfs.rules &lt;&lt; "EOF"
ACTION=="add", DEVPATH=="/devices/*", ENV{PHYSDEVBUS}=="?*", WAIT_FOR_SYSFS="bus"
ACTION=="add", SUBSYSTEM=="net", WAIT_FOR_SYSFS="address"
EOF</userinput></screen>

    <para>Install the documentation that explains how to create Udev rules:</para>

<screen><userinput>install -m644 -D -v docs/writing_udev_rules/index.html /usr/share/doc/udev-&udev-version;/index.html</userinput></screen>

    <important>

      <para>When Udev is started by the LFS-Bootscripts, a replay of all kernel
      device events happens. These events tell Udev what devices exist.
      Sometimes the Udev bootscript doesn't wait long enough for
      <command>udevd</command> to process all of the replayed events and
      consequently the devices for those missed events are not created before the
      script exits. Since <command>udevd</command> is still running in the
      background, the devices will be created a few milliseconds later, but the
      next bootscript to run may require a device to exist before it has been
      created. To avoid such missed events, and to avoid hardcoding an overly
      long wait time, It is recommended that you run the following commands to
      aide the LFS development team in debugging these missed events and finding
      an acceptable solution more quickly.</para>

      <para>First, create a simple C file:</para>

<screen><userinput>cat &gt; bug.c &lt;&lt; EOF
<literal>/* Simple event recorder */
#define _GNU_SOURCE
#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;unistd.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;argz.h&gt;
int main(int argc, char * argv[])
{
  char * envz;
  size_t len;
  int bug;
  bug = open("/dev/bug", O_WRONLY | O_APPEND);
  if (bug == -1)
  return 0;
  setenv("_SEPARATOR", "--------------------------------------", 1);
  argz_create(environ, &amp;envz, &amp;len);
  argz_stringify(envz, len, '\n');
  envz[len-1]='\n';
  write(bug, envz, len);
  close(bug);
  free(envz);
  return 0;
}</literal>
EOF</userinput></screen>

      <para>Now compile it:</para>

<screen><userinput>gcc -o /lib/udev/bug bug.c</userinput></screen>

      <para>The next step adds a simple logging rule to run this program.</para>

<screen><userinput>cat &gt; /etc/udev/rules.d/90-bug.rules &lt;&lt; "EOF"
<literal>ACTION=="add", RUN+="bug"</literal>
EOF</userinput></screen>

      <para>When booting the new LFS system, if any events are missed, a warning
      message will appear and a <filename>/dev/bugreport</filename> file will be
      created. The warning message will tell you where to send feedback.</para>

    </important>

  </sect2>

  <sect2 id="contents-udev" role="content">
    <title>Contents of Udev</title>

    <segmentedlist>
      <segtitle>Installed programs</segtitle>
      <segtitle>Installed directory</segtitle>

      <seglistitem>
        <seg>ata_id, cdrom_id, create_floppy_devices, edd_id, firmware_helper,
        scsi_id, udevcontrol, udevd, udevinfo, udevmonitor, udevtest, usb_id
        and vol_id</seg>
        <seg>/etc/udev</seg>
      </seglistitem>
    </segmentedlist>

    <variablelist>
      <bridgehead renderas="sect3">Short Descriptions</bridgehead>
      <?dbfo list-presentation="list"?>
      <?dbhtml list-presentation="table"?>

      <varlistentry id="ata_id">
        <term><command>ata_id</command></term>
        <listitem>
          <para>Provides Udev with a unique string and
          additional information (uuid, label) for an ATA drive</para>
          <indexterm zone="ch-system-udev ata_id">
            <primary sortas="b-ata_id">ata_id</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="cdrom_id">
        <term><command>cdrom_id</command></term>
        <listitem>
          <para>Provides Udev with the capabilities of a
          CD-ROM or DVD-ROM drive</para>
          <indexterm zone="ch-system-udev cdrom_id">
            <primary sortas="b-cdrom_id">cdrom_id</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="create_floppy_devices">
        <term><command>create_floppy_devices</command></term>
        <listitem>
          <para>Creates all possible floppy devices based on the CMOS type</para>
          <indexterm zone="ch-system-udev create_floppy_devices">
            <primary sortas="b-create_floppy_devices">create_floppy_devices</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="edd_id">
        <term><command>edd_id</command></term>
        <listitem>
          <para>Provides Udev with the EDD ID for a BIOS disk drive</para>
          <indexterm zone="ch-system-udev edd_id">
            <primary sortas="b-edd_id">edd_id</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="firmware_helper">
        <term><command>firmware_helper</command></term>
        <listitem>
          <para>Uploads firmware to devices</para>
          <indexterm zone="ch-system-udev firmware_helper">
            <primary sortas="b-firmware_helper">firmware_helper</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="scsi_id">
        <term><command>scsi_id</command></term>
        <listitem>
          <para>Provides Udev with a unique SCSI identifier
          based on the data returned from sending a SCSI INQUIRY command to
          the specified device</para>
          <indexterm zone="ch-system-udev scsi_id">
            <primary sortas="b-scsi_id">scsi_id</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="udevcontrol">
        <term><command>udevcontrol</command></term>
        <listitem>
          <para>Configures a number of options for the running
          <command>udevd</command> daemon, such as the log level.</para>
          <indexterm zone="ch-system-udev udevcontrol">
            <primary sortas="b-udevcontrol">udevcontrol</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="udevd">
        <term><command>udevd</command></term>
        <listitem>
          <para>A daemon that listens for uevents on the netlink socket,
          creates devices and runs the configured external programs in
          response to these uevents</para>
          <indexterm zone="ch-system-udev udevd">
            <primary sortas="b-udevd">udevd</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="udevinfo">
        <term><command>udevinfo</command></term>
        <listitem>
          <para>Allows users to query the Udev database for
          information on any device currently present on the system; it also
          provides a way to query any device in the <systemitem
          class="filesystem">sysfs</systemitem> tree to help create udev
          rules</para>
          <indexterm zone="ch-system-udev udevinfo">
            <primary sortas="b-udevinfo">udevinfo</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="udevmonitor">
        <term><command>udevmonitor</command></term>
        <listitem>
          <para>Prints the event received from the kernel and the environment
          which Udev sends out after rule processing</para>
          <indexterm zone="ch-system-udev udevmonitor">
            <primary sortas="b-udevmonitor">udevmonitor</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="udevtest">
        <term><command>udevtest</command></term>
        <listitem>
          <para>Simulates a uevent for the given device, and prints out the
          name of the node the real <command>udevd</command> would have created,
          or the name of the renamed network interface</para>
          <indexterm zone="ch-system-udev udevtest">
            <primary sortas="b-udevtest">udevtest</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="usb_id">
        <term><command>usb_id</command></term>
        <listitem>
          <para>Provides Udev with information about USB
          devices</para>
          <indexterm zone="ch-system-udev usb_id">
            <primary sortas="b-usb_id">usb_id</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="vol_id">
        <term><command>vol_id</command></term>
        <listitem>
          <para>Provides Udev with the label and uuid of a
          filesystem</para>
          <indexterm zone="ch-system-udev vol_id">
            <primary sortas="b-vol_id">vol_id</primary>
          </indexterm>
        </listitem>
      </varlistentry>

      <varlistentry id="etc-udev">
        <term><filename class="directory">/etc/udev</filename></term>
        <listitem>
          <para>Contains Udev configuation files,
          device permissions, and rules for device naming</para>
          <indexterm zone="ch-system-udev etc-udev">
            <primary sortas="e-/etc/udev">/etc/udev</primary>
          </indexterm>
        </listitem>
      </varlistentry>

    </variablelist>

  </sect2>

</sect1>