From ArchWiki
Revision as of 04:20, 3 April 2006 by Codemac (talk | contribs) (Auto mounting USB devices)
Jump to: navigation, search

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.

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.

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.

Recent Changes to Note

  • The startudev program has been removed. Use /etc/start_udev if you want to reload your udev rules.
  • Udev now replaces the functionality of both hotplug and hwdetect. While we still provide hwdetect, it is only typically used during the initrd generation with mkinitrd.
  • 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.

Blacklisting Modules

Udev can often 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.


MODULES=(!moduleA !moduleB)

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).

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 removabel devices.

 To get access to them with hal's pmount backend add them to /etc/pmount.allow

Known Problems with Auto-Loading

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.

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.

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", SYSFS{address}=="aa:bb:cc:dd:ee:ff", NAME="lan0"
SUBSYSTEM=="net", SYSFS{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!

Known Problems for Custom Kernel Users

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.

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/.

Udev Tricks

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=="/sbin/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,sync,dirsync,noexec,nodev,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.