symlinks.xml 5.9 KB

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