From ArchWiki
Revision as of 08:33, 2 September 2012 by AlexanderR (Talk | contribs) (updated status, proposed merge)

Jump to: navigation, search

Merge-arrows-2.pngThis article or section is a candidate for merging with Systemd.Merge-arrows-2.png

Notes: Subject of article is developed as part of Systemd and goes in the same package. (Discuss in Talk:Udev#)

udev replaces the functionality of both hotplug and hwdetect.

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

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.


Udev is now part of systemd in [core].

About udev rules

udev rules written by the administrator go in /etc/udev/rules.d/, their file name has to end with .rules. The udev rules shipped with various packages are found in /usr/lib/udev/rules.d/. If there are two files by the same name under /usr/lib and /etc, the ones in /etc take precedence.

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

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

# udevadm info -a -n [device name]

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

udev automatically detects changes to rules files, so changes take effect immediately without requiring udev to be restarted. However, the rules are not re-triggered automatically on already existing devices, so hot-pluggable devices, such as USB devices, will probably have to be reconnected for the new rules to take effect.


Simply install the udisks package, and all of your media should be automatically mounted in GNOME and KDE SC 4.6. There is no need for any additional rules this way. Be aware that udisks2 is a compatibility-breaking rewrite of udisks and is the version currently required by GNOME, whereas XFCE and KDE seem to still require udisks.

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.

  • udevil - udevil "mounts and unmounts removable devices without a password, shows device info, and monitors device changes". It is written in C and can replace UDisks and includes devmon, which can be installed separately from the AUR (devmonAUR). It can also selectively automatically start applications or execute commands after mounting, ignore specified devices and volume labels, and unmount removable drives.
  • ldmAUR - A lightweight daemon that mounts usb drives, cds, dvds or floppys automagically. [1]
  • udiskie - Written in Python. Enables automatic mounting and unmounting by any user.
  • udisksevtAUR - Written in Haskell. Enables automatic mounting by any user. Designed to be integrated with traydeviceAUR.
  • udisksvmAUR - A GUI UDisks wrapper which uses the udisks2 dbus interface. It calls a 'traydvm' script, included in the package. The 'traydvm' GUI utility is a script which displays a systray icon for a plugged-in device, with a right-click menu to perform simple actions on the device. As the automount function can be disabled, this tool should work with other automounting tools, to show system tray icons. It is independent of any file manager.
  • You can easily automount and eject removable devices with the combination of pmount, udisks2 and spacefm. Note you have to run spacefm in daemon mode with spacefm -d & in your startup scripts, ~/.xinitrc or ~/.xsession, to get automounting. You can also mount internal disks by adding them to /etc/pmount.allow.

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.

Tips and tricks

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 and the Atmel AVR Dragon programmer. Adjust the permissions accordingly. Verified as of 22-06-2012.

# USBtinyISP Programmer rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c9f", GROUP="users", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="0479", GROUP="users", MODE="0666"
# USBasp Programmer rules http://www.fischl.de/usbasp/
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05dc", GROUP="users", MODE="0666"

# Mdfly.com Generic (SiLabs CP2102) 3.3v/5v USB VComm adapter
SUBSYSTEMS=="usb", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", GROUP="users", MODE="0666"

#Atmel AVR Dragon (dragon_isp) rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2107", GROUP="users", MODE="0666"

SUBSYSTEM=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2103", GROUP="users", MODE="0666"

Execute on USB Insert

See the Execute on USB insert article or the devmon wrapper script.

Mount drives as a normal user

If you want to mount an internal drive in your Desktop Environments as a normal user (without the need to type your superuser password), you just have to create one of the following file in PolicyKit Local Authority depending on whether you use udisks (KDE, XFCE) or udisks2 (newer GNOME) (if in doubt run a pacman -Qi udisks2 to see). The setting extends the privilege to all members of the 'users' group but you can substitute unix-user:USERNAME for the group setting for individual privileges. See PolicyKit for details.

This example configuration allows any member of the users group to mount and unmount disks with udisks or udisk2. If it doesn't already exist, create the file /etc/polkit-1/localauthority/50-local.d/10-udisks.pkla with these contents:


 [Local Users]


 [Local Users]

Internal drives only


[Mount a system-internal device]


[Mount a system-internal device]

Mark internal SATA-Ports as eSATA-Ports

If you connected a eSATA bay or an other eSATA adapter the system will still recognize this disk as an internal SATA drive. Gnome and KDE will ask you for your root password all the time. The following rule will mark the specified SATA-Port as an external eSATA-Port. With that, a normal Gnome user can connect their eSATA drives to that port like a USB drive, without any root password and so on.

DEVPATH=="/devices/pci0000:00/0000:00:1f.2/host4/*", ENV{UDISKS_SYSTEM_INTERNAL}="0"
Note: The DEVPATH can be found after connection the eSata drive with the following command (replace sdb to your needs):
# find /sys/devices/ -name sdb

Setting static device names

Because udev loads all modules asynchronously, they are initialized in a different order. This can result in devices randomly switching names. A udev rule can be added to use static device names, but preferably names other than "ethX" and "wlanX".

For block devices, see Persistent block device naming.

Network device

For example, with two network cards, you may notice a switching of designations between eth0 and eth1 between reboots.

One 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:

SUBSYSTEM=="net", ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="net0"
SUBSYSTEM=="net", ATTR{address}=="ff:ee:dd:cc:bb:aa", NAME="wifi0"

A couple things to note:

  • To get the MAC address of each card, use this command: udevadm info -a -p /sys/class/net/<yourdevice> | grep address | tr [A-Z] [a-z]
  • Make sure to use the lower-case hex values in your udev rules. It doesn't like upper-case.
  • When choosing the static names it should be avoided to use "ethX" and "wlanX", because this may lead to race conditions between the kernel und udev during boot. Instead better use interface names that are not used by the kernel as default, e.g. "net0, net1, wifi0, wifi1"

Don't forget to update your /etc/rc.conf and other configuration files using the old ethX notation!

See also Rename network interfaces.

iscsi device

Test the output from scsi_id:

/usr/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/sdb
 # the iscsi device rules
 # this will create an iscsi device for each of the targets
 KERNEL=="sd*", SUBSYSTEM=="block", PROGRAM="/usr/lib/udev/scsi_id --whitelisted --replace-whitespace /dev/$name", RESULT=="3600601607db11e0013ab5a8e371ce111",


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/ /usr/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. /etc/nsswitch.conf 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.

Some devices, that should be treated as removable, are not

Create a custom udev rule, setting UDISKS_SYSTEM_INTERNAL=0. For more details, see the manpage of udisks.

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 MODULES array in /etc/rc.conf. Further reading: rc.conf.

Sound Problems or Some Modules Not Loaded Automatically

Some users have traced this problem to old entries in /etc/modprobe.d/sound.conf. Try cleaning that file out and trying again.

Note: Since udev>=171, the OSS emulation modules (snd_seq_oss, snd_pcm_oss, snd_mixer_oss) are not automatically loaded by default.

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.32. Earlier kernels do not have the necessary uevent stuff that udev needs for auto-loading.

IDE CD/DVD-drive support

Starting with version 170, udev doesn't support CD-ROM/DVD-ROM drives, which are loaded as traditional IDE drives with the ide_cd_mod module and show up as /dev/hd*. The drive remains usable for tools which access the hardware directly, like cdparanoia, but is invisible for higher userspace programs, like KDE.

A cause for the loading of the ide_cd_mod module prior to others, like sr_mod, could be e.g. that you have for some reason the module piix loaded with your initramfs. In that case you can just replace it with ata_piix in your /etc/mkinitcpio.conf.

Optical Drives Have Group ID Set To Disk

If the group ID of your optical drive is set to disk and you want to have it set to optical you have to create a custom udev rule:

# permissions for IDE CD devices
SUBSYSTEMS=="ide", KERNEL=="hd[a-z]", ATTR{removable}=="1", ATTRS{media}=="cdrom*", GROUP="optical"

# permissions for SCSI CD devices
SUBSYSTEMS=="scsi", KERNEL=="s[rg][0-9]*", ATTRS{type}=="5", GROUP="optical"

See also