source: chapter07/symlinks.xml@ 3a234c0a

Last change on this file since 3a234c0a was 76f695d, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Splitted some commands to fit into PDF page size.

git-svn-id: http://svn.linuxfromscratch.org/LFS/branches/6.2/BOOK@7716 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 5.7 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="ch-scripts-symlinks">
9 <?dbhtml filename="symlinks.html"?>
10
11 <title>Creating custom symlinks to devices</title>
12
13 <sect2>
14
15 <title>CD-ROM symlinks</title>
16
17 <para>Some software that you may want to install later (e.g., various
18 media players) expect the /dev/cdrom and /dev/dvd symlinks to exist.
19 Also, it may be convenient to put references to those symlinks into
20 <filename>/etc/fstab</filename>. For each of your CD-ROM devices,
21 find the corresponding directory under
22 <filename class="directory">/sys</filename> (e.g., this can be
23 <filename class="directory">/sys/block/hdd</filename>) and
24 run a command similar to the following:</para>
25
26<screen role="nodump"><userinput>udevtest /block/hdd</userinput></screen>
27
28 <para>Look at the lines containing the output of various *_id programs.</para>
29
30 <para>There are two approaches to creating symlinks. The first one is to
31 use the model name and the serial number, the second one is based on the
32 location of the device on the bus. If you are going to use the first
33 approach, create a file similar to the following:</para>
34
35<screen role="nodump"><userinput>cat &gt;/etc/udev/rules.d/82-cdrom.rules &lt;&lt; EOF
36<literal>
37# Custom CD-ROM symlinks
38SUBSYSTEM=="block", ENV{ID_MODEL}=="SAMSUNG_CD-ROM_SC-148F", \
39 ENV{ID_REVISION}=="PS05", SYMLINK+="cdrom"
40SUBSYSTEM=="block", ENV{ID_MODEL}=="PHILIPS_CDD5301", \
41 ENV{ID_SERIAL}=="5VO1306DM00190", SYMLINK+="cdrom1 dvd"
42</literal>
43EOF</userinput></screen>
44
45 <para>This way, the symlinks will stay correct even if you move the drives
46 to different positions on the IDE bus, but the
47 <filename>/dev/cdrom</filename> symlink won't be created if you replace
48 the old SAMSUNG CD-ROM with a new drive.</para>
49<!-- The symlinks in the first approach survive even the transition
50 to libata for IDE drives, but that is not for the book. -->
51
52 <para>The SUBSYSTEM==&quot;block&quot; key is needed in order to avoid
53 matching SCSI generic devices. Without it, in the case with SCSI
54 CD-ROMs, the symlinks will sometimes point to the correct
55 <filename>/dev/srX</filename> devices, and sometimes to
56 <filename>/dev/sgX</filename>, which is wrong.</para>
57
58 <para>The second approach yields:</para>
59
60<screen role="nodump"><userinput>cat &gt;/etc/udev/rules.d/82-cdrom.rules &lt;&lt; EOF
61<literal>
62# Custom CD-ROM symlinks
63SUBSYSTEM=="block", ENV{ID_TYPE}=="cd", \
64 ENV{ID_PATH}=="pci-0000:00:07.1-ide-0:1", SYMLINK+="cdrom"
65SUBSYSTEM=="block", ENV{ID_TYPE}=="cd", \
66 ENV{ID_PATH}=="pci-0000:00:07.1-ide-1:1", SYMLINK+="cdrom1 dvd"
67</literal>
68EOF</userinput></screen>
69
70 <para>This way, the symlinks will stay correct even if you replace drives
71 with different models, but place them to the old positions on the IDE
72 bus. The ENV{ID_TYPE}==&quot;cd&quot; key makes sure that the symlink
73 disappears if you put something other than a CD-ROM in that position on
74 the bus.</para>
75
76 <para>Of course, it is possible to mix the two approaches.</para>
77
78 </sect2>
79
80 <sect2>
81
82 <title>Dealing with duplicate devices</title>
83
84 <para>As explained in <xref linkend="ch-scripts-udev"/>, the order in
85 which devices with the same function appear in
86 <filename class="directory">/dev</filename> is essentially random.
87 E.g., if you have a USB web camera and a TV tuner, sometimes
88 <filename>/dev/video0</filename> refers to the camera and
89 <filename>/dev/video1</filename> refers to the tuner, and sometimes
90 after a reboot the order changes to the opposite one.
91 For all classes of hardware except sound cards and network cards, this is
92 fixable by creating udev rules for custom persistent symlinks.
93 The case of network cards is covered separately in
94 <xref linkend="ch-scripts-network"/>, and sound card configuration can
95 be found in <ulink url="&blfs-root;">BLFS</ulink>.</para>
96
97 <para>For each of your devices that is likely to have this problem
98 (even if the problem doesn't exist in your current Linux distribution),
99 find the corresponding directory under
100 <filename class="directory">/sys/class</filename> or
101 <filename class="directory">/sys/block</filename>.
102 For video devices, this may be
103 <filename
104 class="directory">/sys/class/video4linux/video<replaceable>X</replaceable></filename>.
105 Figure out the attributes that identify the device uniquely (usually,
106 vendor and product IDs and/or serial numbers work):</para>
107
108<screen role="nodump"><userinput>udevinfo -a -p /sys/class/video4linux/video0</userinput></screen>
109
110 <para>Then write rules that create the symlinks, e.g.:</para>
111
112<screen role="nodump"><userinput>cat &gt;/etc/udev/rules.d/83-duplicate_devs.rules &lt;&lt; EOF
113<literal>
114# Persistent symlinks for webcam and tuner
115KERNEL=="video*", SYSFS{idProduct}=="1910", SYSFS{idVendor}=="0d81", \
116 SYMLINK+="webcam"
117KERNEL=="video*", SYSFS{device}=="0x036f", SYSFS{vendor}=="0x109e", \
118 SYMLINK+="tvtuner"
119</literal>
120EOF</userinput></screen>
121
122 <para>The result is that <filename>/dev/video0</filename> and
123 <filename>/dev/video1</filename> devices still refer randomly to the tuner
124 and the web camera (and thus should never be used directly), but there are
125 symlinks <filename>/dev/tvtuner</filename> and
126 <filename>/dev/webcam</filename> that always point to the correct
127 device.</para>
128
129 <para>More information on writing Udev rules can be found in
130 <filename>/usr/share/doc/udev-&udev-version;/index.html</filename>.</para>
131
132 </sect2>
133
134</sect1>
Note: See TracBrowser for help on using the repository browser.