Udev
From ArchWiki
| i18n |
|---|
| English |
| Русский |
| 繁體中文 |
| 简体中文 |
Note: If you are migrating from DevFS to Udev, see DevFS to Udev.
This document attempts to outline all the crazy changes that have been coming down the pipe with the latest udev updates. As of version 084, udev is responsible for all hotplug and coldplug events. The hotplug package has been deprecated and will eventually be removed from the Arch repos, since udev performs all these tasks now.
Contents |
[edit] The Number One Thing
... to remember is this. udev will not do any module loading for you (either at boot-up or later on) unless MOD_AUTOLOAD is enabled in your /etc/rc.conf. If it is disabled, then it's up to you, the admin, to manually load the modules you want. You can do this a number of ways. The favored ones are specifying them all in the MODULES array in rc.conf, or using the modprobe command for each module you require. Another method is to use the hwdetect --modules command to generate a MODULES suitable for your system. You can then put this array in your rc.conf to have them loaded at bootup.
[edit] General Requirements
- You will need a later kernel: Anything earlier than 2.6.15 will not work.
- You can no longer use DevFS style device names in your fstab or bootloader config! See DevFS to Udev for more info.
[edit] Recent Changes to Note
- The
startudevprogram has been removed. Use/etc/start_udevif you want to reload your udev rules. - Udev now replaces the functionality of both
hotplugandhwdetect. While we still providehwdetect, it is only typically used during the initrd generation withmkinitrd. - Udev will load modules simultaneously, which can provide a speed increase during bootup. However, the downside is that it doesn't always load modules in the same order each time, which can cause problems with things like sound cards and network cards (if you have more than one of them). See below for more info on this.
[edit] Blacklisting Modules
In rare cases, Udev can make mistakes and load the wrong modules. To prevent it from doing this, you can blacklist modules. Once blacklisted, udev will never load that module. Not at boot-time or later on when a hotplug event is received (ie, you plug in your USB flash drive).
To blacklist a module, just prefix it with a bang (!) in your MODULES array in rc.conf.
eg,
MODULES=(!moduleA !moduleB)
[edit] load_modules: A Helpful Boot Parameter
If you pass load_modules=off on your kernel boot line, then udev will skip all the auto-loading business. This is to provide you with a big ripcord to pull if something goes wrong. If udev loads a problematic module that hangs your system or something equally awful, then you can bypass auto-loading with this parameter, then go in and blacklist the offensive module(s).
[edit] Known Problems with Hardware
- BusLogic devices can be broken and will cause a freeze during startup.
This is a kernel bug and no fix has been provided yet.
- PCMCIA Card readers are not treated as removable devices.
To get access to them with hal's pmount backend add them to /etc/pmount.allow
[edit] Known Problems with Auto-Loading
[edit] CPUFreq modules
We don't have a good detection method for the various CPUFreq controllers out there, so this has been omitted from the auto-loading process for now. To use CPU frequency scaling, you should load the proper module explicitly in your MODULES array in rc.conf.
[edit] Sound Problems or Some Modules Not Loaded Automatically
Some users have traced this problem to old entries in /etc/modprobe.conf. Try cleaning that file out and trying again.
[edit] Mixed Up Devices, Sound/Network Cards Changing Order Each Boot
Because udev loads all modules at once, devices are sometimes initialized in a different order. For example, with two network cards, you may notice they switch designations between eth0 and eth1.
A general solution is to specify the module load order yourself by listing the modules in the MODULES array in rc.conf. Modules in this array are loaded before udev starts auto-loading stuff, so you have full control over the load order.
# Always load 8139too before e100 MODULES=(8139too e100)
Another method for network card ordering is to use the udev-sanctified method of statically-naming each interface. Create a file called /etc/udev/rules.d/10-network.rules and bind the MAC address of each of your cards to a certain interface name:
SUBSYSTEM=="net", ATTRS{address}=="aa:bb:cc:dd:ee:ff", NAME="lan0"
SUBSYSTEM=="net", ATTRS{address}=="ff:ee:dd:cc:bb:aa", NAME="wlan0"
A couple things to note:
- To get the MAC address of each card, use this command:
udevinfo -a -p /sys/class/net/<yourdevice> - Make sure to use the lower-case hex values in your udev rules. It doesn't like upper-case.
- Some people have problems naming their interfaces after the old style: eth0, eth1, etc. Try something like "lan" or "wlan" if you experience this problem.
Don't forget to update your /etc/rc.conf and other configfiles using the old ethX notation!
[edit] Known Problems for Custom Kernel Users
[edit] Udev doesn't start at all
Make sure you have a kernel version later than or equal to 2.6.15. Earlier kernels do not have the necessary uevent stuff that udev needs for auto-loading.
[edit] CD/DVD symlinks and permissions are broken
If you're using a 2.6.15 kernel, you'll need the uevent patch from ABS (which backports certain uevent functionality from 2.6.16). Just sync up your ABS tree with the abs command, then you'll find the patch in /var/abs/kernels/kernel26/.
[edit] Udev Tricks
[edit] Auto mounting USB devices
KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="usb%m", GROUP="users", OPTIONS="last_rule" ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usb%n", GROUP="users", NAME="%k" ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /mnt/usb%n" ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 /dev/%k /mnt/usb%n", OPTIONS="last_rule" ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /mnt/usb%n", OPTIONS="last_rule" ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /mnt/usb%n" ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /mnt/usb%n", OPTIONS="last_rule"
Place these udev rules in /etc/udev/rules.d/ with any file name ending in .rules For instance on my system this code is in /etc/udev/rules.d/sda.rules.
A version with symlinking /media to /mnt:
KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="usbhd-%k", GROUP="users", OPTIONS="last_rule" ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usbhd-%k", GROUP="users", NAME="%k" ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /media/usbhd-%k" ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/ln -s /media/usbhd-%k /mnt/usbhd-%k" ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 /dev/%k /media/usbhd-%k", OPTIONS="last_rule" ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /media/usbhd-%k", OPTIONS="last_rule" ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rm -f /mnt/usbhd-%k" ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /media/usbhd-%k" ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /media/usbhd-%k", OPTIONS="last_rule"
Important! If you are using any fixed devices (for example SATA hard disks - check your /etc/fstab) which are recognized as /dev/sdX change all occurrences of sd[a-z] to the first unused letter for a sd* device. For example if you have one SATA hard disk recognized as /dev/sda change all "sd[a-z]" to "sd[b-z]". It's a good idea to start the name of your custom udev rules file with a number for example: 10-my-udev.rules so udev will read it first before standard rules. These rules require no other setup in /etc/fstab. Review mount commands options to change permissions, syncing etc. (search forums for details about the consequences of different setups).