From ArchWiki
Revision as of 04:35, 26 April 2011 by Liquen (Talk | contribs) (About udev rules)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی



"udev is the device manager for the Linux 2.6 kernel series. Primarily, it manages device nodes in Template:Filename. It is the successor of devfs and hotplug, which means that it handles the Template:Filename directory and all user space actions when adding/removing devices, including firmware load." Source: Wikipedia

udev replaces the functionality of both Template:Codeline and Template:Codeline.

udev loads kernel modules by utilizing coding parallelism to provide a potential performance advantage versus loading these modules serially. The modules are therefore loaded asynchronously. The inherent disadvantage of this method is that udev does not always load modules in the same order on each boot. If the machine has multiple block devices, this may manifest itself in the form of device nodes changing designations randomly. For example, if the machine has two hard drives, /dev/sda may randomly become /dev/sdb. See below for more info on this.

About modules auto-loading

udev will not do any module loading for you unless Template:Codeline is enabled in Template:Filename. If you disable auto-loading you must manually load the modules you want/need by putting the list in the Template:Codeline array in Template:Filename, you can generate this list with the Template:Codeline command.

About udev rules

udev rules go in Template:Filename, their file name has to end with Template:Filename.

If you want to learn how to write udev rules see Writing udev rules.

To get a list of all the attributes of a device you can use to write rules:

# udevadm info -a -p $(udevadm info -q path -n [device name])

Replace [device name] with the device present in the system, such as '/dev/sda' or '/dev/ttyUSB0'.

To restart the udev system once you create or modify udev rules, run the following command. Hotpluggable devices, such as USB devices, will probably have to be reconnected for the new rules to take effect.

# udevadm control --reload-rules

Tips & Tricks


Simply install UDisks:

pacman -S udisks

and all your media should be auto mounted in GNOME and KDE SC 4.6. There is no need for any additional rules this way. As an extra bonus you can remove HAL if you were only using that for auto mounting purposes.

Automounting UDisks Wrappers

A UDisks wrapper has the advantage of being very easy to install and needing no (or minimal) configuration. The wrapper will automatically mount things like CDs and flash drives.

  • devmon - devmon (AUR) is a configuration-less bash wrapper script for udisks which automounts optical discs and removable drives. It can also selectively autostart apps or execute commands after mounting, ignore specified devices and volume labels, and unmount removable drives.
  • udiskie - Written in Python. Allows auto mount and unmount by any user.
  • udisksevt - Written in Haskell. Allows auto mount by any user. Designed to be integrated with traydevice.
  • The udisksvm bash script uses udisks and Traydevice to automount removable media and to control in GUI, with mouse clicks in systray, the un-mounting and re-mounting of disks or the ejection of optical disks.

UDisks Shell Functions

While UDisks includes a simple method of (un)mounting devices via command-line, it can be tiresome to type the commands out each time. These shell functions will generally shorten and ease command-line usage.

Auto mounting USB devices

Note: In the following rules the mount options are defined as Template:Codeline, see Template:Codeline (and possibly Template:Codeline) for all available options and Maximizing Performance#Mount options for performance-related options.
Note: The Template:Codeline mount option will not allow users to unmount the filesystem.
Tip: The Template:Codeline mount option prevents execution of binaries on the mounted filesystem.

Mount under Template:Filename; use partition label if present

The following udev rule set automatically mounts devices/partitions that are represented by /dev/sd* (USB drives, external hard drives and sometimes SD cards). If a partition label is available, it mounts the device to /media/<label> and otherwise to /media/usbhd-sd* (ex: /media/usbhd-sdb1): Template:File

Mount under Template:Filename; use partition label if present; support LUKS encryption

Similar to the above rule set, but if the device is a LUKS-encrypted partition it will open an xterm window to ask for the passphrase (provided that xterm is installed). Also see this post and the follow-ups.

Note: You may need to modify the path to cryptsetup, depending on the version installed (e.g., < 1.1.1_rc2-1).


Mount under Template:Filename; use partition label if present; support user un-mounting

This is a variation on the above rule set. It uses pmount (which will need to be installed) instead of mount, allowing a non-root user to unmount udev-mounted devices. The required username must be hard-coded in the RUN command, so this rule set may not be suitable for multi-user systems. LUKS support has also been removed from the example, but can be easily reinstated as above. You must edit the /bin/su invocation to run as the correct user for your system. Template:File

Mount under Template:Filename; create symbolic link under Template:Filename

The following rule set does not make use of partition labels; instead it mounts devices as usbhd-sdXY under the /mnt directory (ex: /mnt/usbhd-sdb1) and creates a symbolic link under /media. Template:File

Mount under Template:Filename only if the partition has a label


Mount under Template:Filename; use partition label if present; ntfs-3g

Yet another example, this time making use of ntfs-3g read/write drivers for NTFS filesystems:


Mount SD cards

The same rules as above can be used to auto-mount SD cards, you just need to replace Template:Codeline by Template:Codeline: Template:File

Mount CDs

To auto mount a CD a simple UDisks wrapper will get the job done properly.

Note: Maybe this should be merged to the Udisks wrapper section.

Accessing Firmware Programmers and USB Virtual Comm Devices

The following ruleset will allow normal users (within the "users" group) the ability to access the USBtinyISP USB programmer for AVR microcontrollers and a generic (SiLabs CP2102) USB to UART adapter. Adjust the permissions accordingly. Verified as of 2010-02-11.


Speed Up udev

Performance gains can be realized by bypassing the blacklisting logic present in the Template:Filename script. See Speed_Up_udev for additional details.

Execute on USB Insert

See execute on usb insert article or the devmon wrapper script.

Mount external drives as a normal user

If you want to mount a external drive on KDE or Gnome (maybe on other Desktop Environments too) as a normal user (without the need to type your superuser password) you just have to edit the Template:Filename (remember to backup first) and change the line <allow_active>auth_admin_keep</allow_active> on <action id="org.freedesktop.udisks.filesystem-mount-system-internal"> to <allow_active>yes</allow_active>.


Disabling modules auto-loading with the load_modules boot parameter

If you pass Template:Codeline 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).

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. See blacklisting. Not at boot-time or later on when a hotplug event is received (eg, you plug in your USB flash drive).

udevd hangs at boot

After migrating to LDAP or updating an LDAP-backed system udevd can hang at boot at the message "Starting UDev Daemon". This is usually caused by udevd trying to look up a name from LDAP but failing, because the network is not up yet. The solution is to ensure that all system group names are present locally.

Extract the group names referenced in udev rules and the group names actually present on the system:

# fgrep -r GROUP /etc/udev/rules.d/ /lib/udev/rules.d | perl -nle '/GROUP\s*=\s*"(.*?)"/ && print $1;' | sort | uniq > udev_groups
# cut -f1 -d: /etc/gshadow /etc/group | sort | uniq > present_groups

To see the differences, do a side-by-side diff:

# diff -y present_groups udev_groups
network							      <
nobody							      <
ntp							      <
optical								optical
power							      |	pcscd
rfkill							      <
root								root
scanner								scanner
smmsp							      <
storage								storage

In this case, the pcscd group is for some reason not present in the system. Add the missing groups:

# groupadd pcscd

Also, make sure local resources are looked up before resorting to LDAP. Template:Filename should contain the line

group: files ldap

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 Template:Filename

Known Problems with Auto-Loading

CPU frequency modules

The current detection method for the various CPU frequency controllers is inadequate, so this has been omitted from the auto-loading process for the time being. To use CPU frequency scaling, load the proper module explicitly in your Template:Codeline array in Template:Filename.

Sound Problems or Some Modules Not Loaded Automatically

Some users have traced this problem to old entries in Template:Filename. Try cleaning that file out and trying again.

Mixed Up Devices, Sound/Network Cards Changing Order Each Boot

Because udev loads all modules asynchronously, they are initialized in a different order. This can result in devices randomly switching names. For example, with two network cards, you may notice a switching of designations between Template:Codeline and Template:Codeline.

Arch Linux provides the advantage of specifying the module load order by listing the modules in the Template:Codeline array in Template:Filename. Modules in this array are loaded before udev begins auto-loading, 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-sanctioned method of statically-naming each interface. Create the following file to bind the MAC address of each of your cards to a certain interface name: Template:File

A couple things to note:

  • To get the MAC address of each card, use this command: Template:Codeline
  • 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 Template:Filename and other configuration files using the old ethX notation!

Another method for setting network interface names is described in the Configuring Network wiki entry. http://wiki.archlinux.org/index.php/Configuring_Network

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 Template:Codeline command, then you'll find the patch in Template:Codeline.

Other Resources