symlinks.xml 5.6 KB

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