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