symlinks.xml 5.7 KB

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