80-drivers.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. Purpose of rules file:
  2. The rules in this file allow Udev to fully replace the old /sbin/hotplug
  3. script. They automatically load kernel modules as devices are discovered.
  4. Description of rules:
  5. All rules in this file match ACTION=="add", so they only run when devices are
  6. being added.
  7. ENV{MODALIAS} is the value of the environment variable named MODALIAS. This
  8. environment variable is sent by the kernel when it sends a uevent for any
  9. device that has a modalias. Modaliases are strings that can be used to load
  10. the appropriate kernel module driver.
  11. Generally a modalias will contain information like vendor ID, device ID, and
  12. possibly other IDs depending on the bus the device is connected to. (USB, for
  13. instance, has the concept of a "device class" and a "device interface", which
  14. are basically just ways to standardize the USB protocol for various types of
  15. devices. This is what allows a single kernel module such as hid.ko to drive
  16. many different vendors' USB input devices: all devices that support the USB
  17. HID interface expose the HID interface number in their modalias, and so the
  18. hid.ko driver can be loaded for each device. When it loads, hid.ko attaches
  19. to the HID interface and does whatever is needed to work with each device.)
  20. Kernel modules that drive hardware expose a list of modaliases. These
  21. modaliases are matched against the device modalias by /sbin/modprobe (after
  22. shell-style expansion), with the help of /sbin/depmod's modules.alias file.
  23. The upshot of all this is, you can tell Udev to run "/sbin/modprobe modalias",
  24. and it will load the module that claims it can drive the "modalias" device.
  25. The rule that does this inspects ENV{MODALIAS} to ensure it is not empty. It
  26. does this by comparing it to "?*" -- inside a match, "*" would match *any*
  27. string, including the empty string, so to ensure MODALIAS is not empty, we need
  28. to match against "?*" instead. ("?" matches any one character.)
  29. The Udev RUN+="" option adds a program to run when the rule matches. In this
  30. case, we tell Udev to run "/sbin/modprobe $env{MODALIAS}". Note that Udev does
  31. not do path searches; if the executable is not specified with a fully-qualified
  32. path, it *must* be located under the /lib/udev directory. If it is not, you
  33. *must* specify a fully-qualified path, as we do here. Also, "$env{string}" is
  34. replaced by the value of the environment variable "string" when the command
  35. runs, so this adds the modalias to the modprobe command. The modprobe program
  36. will do the rest. Finally, the {ignore_error} option is added to the RUN key;
  37. this prevents Udev from failing the uevent if the modprobe command fails. (The
  38. modprobe command will fail when run during cold-plugging, if the driver was
  39. configured into the kernel instead of as a module, for instance.)
  40. There is still one feature of the old hotplug shell-script system that Udev
  41. cannot provide: blacklisting modules from being auto-loaded. To accomplish
  42. this, we must use module-init-tools. In /etc/modprobe.conf, if you use the
  43. "blacklist <module-name>" syntax, modprobe will not load <module-name> under
  44. any name except its real module name. Any modaliases exposed by that module
  45. will not be honored.
  46. There are also rules in this file for various other types of driver loading.
  47. PNP-BIOS devices, for instance, expose a list of PNP IDs in their sysfs "id"
  48. attribute, instead of exposing a single MODALIAS, so one rule loops through
  49. each ID and tries to load the appropriate module. Several other types of
  50. devices require an extra module before they will work properly; one example
  51. of this is IDE tapes, which require the ide-scsi module. Finally, whenever
  52. any SCSI device is found, the file uses the TEST key to check whether the
  53. /sys/module/sg directory exists. If not, then the "sg" module -- the SCSI
  54. generic driver -- is loaded. (That driver creates the module/sg directory,
  55. so the module/sg test is just to see whether the driver has already been
  56. loaded.)