mirror of
https://git.linuxfromscratch.org/lfs.git
synced 2025-01-20 05:57:43 +00:00
84dbfdac1d
git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@7923 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689
144 lines
7.0 KiB
XML
144 lines
7.0 KiB
XML
<?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-scripts-symlinks">
|
|
<?dbhtml filename="symlinks.html"?>
|
|
|
|
<title>Creating Custom Symlinks to Devices</title>
|
|
|
|
<sect2>
|
|
|
|
<title>CD-ROM symlinks</title>
|
|
|
|
<para>Some software that you may want to install later (e.g., various
|
|
media players) expect the <filename class="symlink">/dev/cdrom</filename>
|
|
and <filename class="symlink">/dev/dvd</filename> 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 <filename>/etc/fstab</filename>. 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.</para>
|
|
|
|
<para>First, the script can operate in <quote>by-path</quote> mode, where
|
|
the rules it creates depend on the physical path to the CD or DVD device.
|
|
Second, it can operate in <quote>by-id</quote> mode, where the rules it
|
|
creates depend on identification strings stored in the CD or DVD device
|
|
itself. The path is determined by Udev's <command>path_id</command> script,
|
|
and the identification strings are read from the hardware by its
|
|
<command>ata_id</command> or <command>scsi_id</command> programs, depending
|
|
on which type of device you have.</para>
|
|
|
|
<para>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
|
|
<quote>by-id</quote> 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
|
|
<quote>by-path</quote> mode.</para>
|
|
|
|
<para>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.</para>
|
|
|
|
<!-- If you use by-id mode, the symlinks will survive even the transition
|
|
to libata for IDE drives, but that is not for the book. -->
|
|
|
|
<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.</important>
|
|
|
|
<para>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
|
|
<filename class="directory">/sys</filename> (e.g., this can be
|
|
<filename class="directory">/sys/block/hdd</filename>) and
|
|
run a command similar to the following:</para>
|
|
|
|
<screen role="nodump"><userinput>udevtest /sys/block/hdd</userinput></screen>
|
|
|
|
<para>Look at the lines containing the output of various *_id programs.
|
|
The <quote>by-id</quote> 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 <quote>by-path</quote> mode will use the ID_PATH value.</para>
|
|
|
|
<para>If you choose the <quote>by-path</quote> mode, then the rules files
|
|
installed by default with Udev will work. If you choose the <quote>by-id</quote>
|
|
mode, then you will have to modify the
|
|
<filename>/etc/udev/rules.d/75-cd-aliases-generator.rules</filename> file,
|
|
as follows:</para>
|
|
|
|
<screen><userinput>sed -i -e 's/write_cd_aliases/& by-id/' \
|
|
/etc/udev/rules.d/75-cd-aliases-generator.rules</userinput></screen>
|
|
|
|
<para>Note that it is not necessary to create the rules files or symlinks
|
|
at this time, because you have bind-mounted the host's
|
|
<filename class="directory">/dev</filename> directory into the LFS system,
|
|
and we assume the symlinks exist and are correct on the host. The rules
|
|
will be created, along with the symlinks, the first time you boot your LFS
|
|
system.</para>
|
|
|
|
</sect2>
|
|
|
|
<sect2>
|
|
|
|
<title>Dealing with duplicate devices</title>
|
|
|
|
<para>As explained in <xref linkend="ch-scripts-udev"/>, the order in
|
|
which devices with the same function appear in
|
|
<filename class="directory">/dev</filename> is essentially random.
|
|
E.g., if you have a USB web camera and a TV tuner, sometimes
|
|
<filename>/dev/video0</filename> refers to the camera and
|
|
<filename>/dev/video1</filename> 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
|
|
<xref linkend="ch-scripts-network"/>, and sound card configuration can
|
|
be found in <ulink url="&blfs-root;">BLFS</ulink>.</para>
|
|
|
|
<para>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
|
|
<filename class="directory">/sys/class</filename> or
|
|
<filename class="directory">/sys/block</filename>.
|
|
For video devices, this may be
|
|
<filename
|
|
class="directory">/sys/class/video4linux/video<replaceable>X</replaceable></filename>.
|
|
Figure out the attributes that identify the device uniquely (usually,
|
|
vendor and product IDs and/or serial numbers work):</para>
|
|
|
|
<screen role="nodump"><userinput>udevinfo -a -p /sys/class/video4linux/video0</userinput></screen>
|
|
|
|
<para>Then write rules that create the symlinks, e.g.:</para>
|
|
|
|
<screen role="nodump"><userinput>cat > /etc/udev/rules.d/83-duplicate_devs.rules << EOF
|
|
<literal>
|
|
# Persistent symlinks for webcam and tuner
|
|
KERNEL=="video*", SYSFS{idProduct}=="1910", SYSFS{idVendor}=="0d81", \
|
|
SYMLINK+="webcam"
|
|
KERNEL=="video*", SYSFS{device}=="0x036f", SYSFS{vendor}=="0x109e", \
|
|
SYMLINK+="tvtuner"
|
|
</literal>
|
|
EOF</userinput></screen>
|
|
|
|
<para>The result is that <filename>/dev/video0</filename> and
|
|
<filename>/dev/video1</filename> devices still refer randomly to the tuner
|
|
and the web camera (and thus should never be used directly), but there are
|
|
symlinks <filename>/dev/tvtuner</filename> and
|
|
<filename>/dev/webcam</filename> that always point to the correct
|
|
device.</para>
|
|
|
|
<para>More information on writing Udev rules can be found in
|
|
<filename>/usr/share/doc/udev-&udev-version;/index.html</filename>.</para>
|
|
|
|
</sect2>
|
|
|
|
</sect1>
|