1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
How does udev work?
~~~~~~~~~~~~~~~~~~~
Short summary: when a driver is loaded it makes some information available
in /sys/ and a message is sent to udevd which reads them and creates the
appropriate devices.
This means that:
- modules cannot be loaded on demand when applications open their device,
because the device is not yet there!
- since modules are not loaded on demand, if for some reason the drivers
cannot be automatically loaded at boot time you will have to add them
to /etc/modules.
- some modules are not hardware drivers and cannot be loaded automatically
by udev, so they will have to be listed in /etc/modules as well.
- some modules for less usual bus types lack the sysfs data needed to be
automatically loaded and must be loaded manually.
(See #334238 and #337004 for details.)
udevd also manages the hotplug events and if needed dispatches them to
other programs using RUN rules, as a replacement of the old /sbin/hotplug.
Required kernel support
~~~~~~~~~~~~~~~~~~~~~~~
The running kernel must be not older than 2.6.26 and must support the
hotplug subsystem (CONFIG_HOTPLUG), tmpfs (CONFIG_TMPFS), inotify
(CONFIG_INOTIFY_USER) and signalfd (CONFIG_SIGNALFD).
CONFIG_PNP, CONFIG_ISAPNP, CONFIG_PNPBIOS and CONFIG_PNPACPI are highly
recommended to allow to automatically load some important drivers.
CONFIG_SYSFS_DEPRECATED and CONFIG_USB_DEVICE_CLASS must not be defined.
CONFIG_BLK_DEV_BSG must be defined if support for persistent tape
devices names is required.
Disabling udev
~~~~~~~~~~~~~~
You may configure in /etc/udev/udev.conf a directory other than /dev
or add UDEV_DISABLED=yes to the kernel command line.
Manually creating devices
~~~~~~~~~~~~~~~~~~~~~~~~~
Device nodes present in /lib/udev/devices/ will be copied to /dev/ at
boot time.
The /etc/udev/rules.d/ directory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The files are read and processed in alphabetical order, and the directives
of matching rules are applied in order.
If a file with the same name is present both in /etc/udev/rules.d/ and
/lib/udev/rules.d/ then the latter will be ignored.
Since the order may be important, files have a specific name which
must be considered when adding custom rules. So far have been defined:
- 50: the default names are set.
- 60: path_id and the other *_id programs are run. persistent links
are set.
- 70: network interfaces are renamed and generated rules for persistent
links are processed.
- 75: the rules generators are run if needed.
- 80: drivers are loaded.
- 91: the default permissions and owners are set.
- 95: $REMOVE_CMD is run, and then processing of tty devices
is stopped with last_rule.
The persistent-*.rules files are generated by the *-generator.rules files
using the /lib/udev/write_*_rules scripts when new devices are detected.
They set stable names for network interfaces and optical devices aliases.
MAINTAINERS BEWARE: the use of /etc/udev/rules.d/ by other packages is
discouraged, except when RUN rules or custom user/groups are used.
If you think your package needs to create a file there, then please
contact the udev package maintainer and explain your needs.
How to know the attributes of a device
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Try something like:
udevadm info --attribute-walk --path=/sys/class/sound/pcmC0D0c/
Devices timestamps
~~~~~~~~~~~~~~~~~~
Most devices will be created at the beginning of the boot process, and will
have the creation time of the kernel clock at that moment.
On systems whose system clock is set on local time instead of UTC, the
kernel clock will be updated in a later phase of the boot process and for
a few hours the devices will have a timestamp in the future.
This is usually not a problem, but if it bothers you it can be fixed by
running touch(1) in an init script.
SCSI block and generic devices
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When you create a custom rule which matches SCSI devices by some sysfs
attributes, do not forget that it will match not only the sdX device node
you are probably looking for but also the SCSI generic device node sgX.
To get the expected behaviour, you need to add KERNEL="sd*" to your rule.
A typical example for an USB pen drive is:
SUBSYSTEMS=="usb", KERNEL=="sd*", \
ATTRS{manufacturer}=="hardware vendor", ATTRS{product}=="model", \
SYMLINK+="pendrive%n"
If a device does not report media changes (like e.g. many SD card readers)
you will also need to add the OPTIONS+="all_partitions" attribute to the
rule. This is not needed if you are using HAL.
Network Interfaces
~~~~~~~~~~~~~~~~~~
After receiving events about network interfaces, net.agent will call
ifupdown using the --allow=hotplug option. This makes the program act
only on interfaces marked with the "allow-hotplug" statement.
E.g: "allow-hotplug eth0" instead of the usual "auto eth0".
The loopback interface must always be configured with "auto lo".
The persistent names of network interfaces by default are automatically
written to /etc/udev/rules.d/70-persistent-net.rules .
Users can add their own rules there or at any other place before 70.
MAC addresses matching is literal, so they must be written in lower case.
To disable persistent naming of network interfaces, create an empty
/etc/udev/rules.d/75-persistent-net-generator.rules file to override
the one in /lib/udev/rules.d/ and delete
/etc/udev/rules.d/70-persistent-net.rules.
Beware: programs which rename network interfaces like ifrename and nameif
will let udev relay events for the old names and should not be used.
Usually network interfaces are renamed after the root file system has
been mounted, so if the root file system is mounted over the network
then the 70-persistent-net.rules file must be copied to the initramfs.
In most cases this is done automatically, but some setups may require
explicitly setting NEED_PERSISTENT_NET=yes in a file in
/etc/initramfs-tools/conf.d/ .
If 70-persistent-net.rules is copied to the initramfs then it must be
updated every time a new interface is added.
Using udev with LDAP or NIS
~~~~~~~~~~~~~~~~~~~~~~~~~~~
If the rules files reference usernames or groups not present in the
/etc/{passwd,group} files and the system is configured to use a
network-based database like LDAP or NIS then udev may fail at boot time
because users and groups are looked up well before the network has been
initialized.
A possible solution is to configure /etc/nsswitch.conf like this:
passwd: files ldap [UNAVAIL=return]
group: files ldap [UNAVAIL=return]
The nsswitch.conf syntax is documented in the glibc manual.
Other documentation
~~~~~~~~~~~~~~~~~~~
http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html
http://www.reactivated.net/udevrules.php
http://www.kroah.com/linux/talks/suse_2005_driver_model/
|