symlinks.xml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/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>Dealing with duplicate devices</title>
  12. <para>As explained in <xref linkend="ch-scripts-udev"/>, the order in
  13. which devices with the same function appear in
  14. <filename class="directory">/dev</filename> is essentially random.
  15. E.g., if you have a USB web camera and a TV tuner, sometimes
  16. <filename>/dev/video0</filename> refers to the camera and
  17. <filename>/dev/video1</filename> refers to the tuner, and sometimes
  18. after a reboot the order changes to the opposite one.
  19. For all classes of hardware except sound cards and network cards, this is
  20. fixable by creating udev rules for custom persistent symlinks.
  21. The case of network cards is covered separately in
  22. <xref linkend="ch-scripts-network"/>, and sound card configuration can
  23. be found in <ulink url="&blfs-book;postlfs/devices.html">BLFS</ulink>.</para>
  24. <para>For each of your devices that is likely to have this problem
  25. (even if the problem doesn't exist in your current Linux distribution),
  26. find the corresponding directory under
  27. <filename class="directory">/sys/class</filename> or
  28. <filename class="directory">/sys/block</filename>.
  29. For video devices, this may be
  30. <filename
  31. class="directory">/sys/class/video4linux/video<replaceable>X</replaceable></filename>.
  32. Figure out the attributes that identify the device uniquely (usually,
  33. vendor and product IDs and/or serial numbers work):</para>
  34. <screen role="nodump"><userinput>udevadm info -a -p /sys/class/video4linux/video0</userinput></screen>
  35. <para>Then write rules that create the symlinks, e.g.:</para>
  36. <screen role="nodump"><userinput>cat &gt; /etc/udev/rules.d/83-duplicate_devs.rules &lt;&lt; "EOF"
  37. <literal>
  38. # Persistent symlinks for webcam and tuner
  39. KERNEL=="video*", ATTRS{idProduct}=="1910", ATTRS{idVendor}=="0d81", \
  40. SYMLINK+="webcam"
  41. KERNEL=="video*", ATTRS{device}=="0x036f", ATTRS{vendor}=="0x109e", \
  42. SYMLINK+="tvtuner"
  43. </literal>
  44. EOF</userinput></screen>
  45. <para>The result is that <filename>/dev/video0</filename> and
  46. <filename>/dev/video1</filename> devices still refer randomly to the tuner
  47. and the web camera (and thus should never be used directly), but there are
  48. symlinks <filename>/dev/tvtuner</filename> and
  49. <filename>/dev/webcam</filename> that always point to the correct
  50. device.</para>
  51. </sect2>
  52. </sect1>