Udev/es

udev es el gestor de dispositivos para el núcleo Linux. Gestiona los nodos de dispositivo en y también todos las acciones en espacio de usuario cuando se añaden o eliminan dispositivos. El lector debería también echar un vistazo a [Project:Eudev|eudev] una bifurcación de udev.

El directorio /dev
When Linux users talk about the hardware on their system in the vicinity of people who believe Linux is some sort of virus or brand of coffee, the use of "slash dev slash foo" will return strange looks for sure. But for the fortunate user (and that includes the reader of this article) using is just a fast way of referring to the primary master SATA, first partition. That's pretty easy, right?

Most Linux users know what a device file is. Some even know why device files have special numbers. Take a close look at device list when ls -l is issued in the folder. What users take for granted is that the primary SATA disk is referred to as Some users might not see it this way, but this is a flaw by design.

Think about hotpluggable devices like USB, IEEE1394, hot-swappable PCI, etc. What is the first device? And for how long? What will the other devices be named when the first one disappears? How will that affect ongoing transactions? Wouldn't it be fun that a printing job is suddenly moved from a super-new laser printer to an almost-dead matrix printer because someone's mom decided to pull the plug of the laser printer which just so happened to be the first printer?

Entra en escena udev. Los objetivos del proyecto udev son a la vez interesantes y necesarios. Udev:


 * Corre en espacio de usuario
 * Crea y borra archivos de dispositivo dinámicamente
 * Proporciona nombres consistentes
 * Proporciona un interfaz de aplicación (API) en el espacio de usuario.

Every time a change happens within the device structure, the kernel emits a uevent which gets picked up by udev. udev then follows the rules as declared in the, and  directories. Based on the information contained within the uevent, it finds the rule or rules it needs to trigger and performs the required actions. These actions can be creating or deleting device files, but can also trigger the loading of particular firmware files into kernel memory.

Núcleo
udev necesita las siguientes opciones del núcleo:

Software
Portage knows the global USE flag  for enabling support for udev in other packages. Enabling this USE flag (default in all Linux profiles) will pull in automatically:

Después de definir esto, seguramente desee actualizar el sistema para que los cambios tengan efecto:

Servicio
To start udev at boot time, add it to the sysinit runlevel. This can be done by issuing the following command with root privileges:

Reglas
udev provides a set of rules that match against exported values of uevents (events sent by the kernel) and properties of the discovered device. A matching rule will possibly name and create a device node and run configured programs to setup and configure the device.

The rule definitions are stored in two locations:


 * 1) . Las reglas en este directorio son instaladas por determinados paquetes, normalmente los usuarios no deberían cambiarlas.
 * 2) . Este directorio es para las reglas especificadas por los usuarios finales. Cualquier nueva regla se debe añadir en este directorio.

En estos directorios se recorren en orden alfabético múltiples ficheros de reglas (con el sufijo ), udev buscará expresiones que concuerden con un uevent y con el estado definido (es el uevent debido que se ha añadido o retirado un dispositivo) y la orden a ejecutar.

The event matching is based on information such as:


 * The SUBSYSTEM of the uevent (for which type of device is the uevent fired);
 * The ACTION that is taken (add, change or remove);
 * One or more attributes (through ATTR or ATTRS), such as the device class, vendor or other device information;
 * The kernel-provided name (through KERNEL), such as sd* (for SCSI/SATA disks) or input* (for input devices such as mice and keyboards);
 * One or more environment settings (through ENV), used to send information between multiple rules.

Based on this information, the rule can then state if:


 * 1) Some information needs to be shared with later events (through environment variables)
 * 2) Links need to be created in
 * 3) Commands need to be executed

Udev does this for every rule that matches (it does not stop after the first match) to allow a flexible device management approach.

Nombres persistentes de dispositivos
El núcleo detecta los dispositivos de forma asíncrona. Udev crea un reflejo del sistema de ficheros del núcleo sysfs y por lo tanto los dispositivos se nombran y numeran en el orden de su detección. Así, por defecto udev no ofrece nombres persistentes de los dispositivos. Sin embargo, existen mecanismos de algunas clases de dispositivo para ofrecerlos:


 * Udev creates for storage devices additional symlinks based on the device's ID, label, UUID and path. See the directory. So instead of using e.g. the device file  use the file.


 * Lo mismo aplica para los dispositivos de entrada en el directorio.


 * Using custom rules enablers users to create their own device files.

Utilización
Algunas órdenes útiles son las siguientes:


 * Mostrar todos los mensajes sobre un determinado fichero de dispositivo: :


 * Monitorizar las actividades de udev:

Lea la página del manual de udevadm para más información.

Registrar mensajes del monitor
To log all message when udevadm monitor is ran modify the following configuration file:

It will create the new log file located at

Modo depuración
Enabling debug mode will output more log messages:

Defina la prioridad del registro:

The log file will be created but no messages will be logged to it. The most recent versions of udev will log all messages to dmesg.

Faltan los ficheros de dispositivo y
Some udev versions need the and  files in order to work properly, but can not create them on their own. To manually create these files for udev run the following commands with root privileges:

NIC asignada a eth0 pero se mueve a eth1
Those having dual network cards on their motherboards may run into a situation where ifconfig may show no eth0 or eth1. dmesg</tt> may show their NIC detected as eth0, and later moved to eth1. Performing a ifconfig -a</tt> will also show the NIC as eth1. This is caused by using the kernel assigned names in the first place. Users should write custom rules like to use free names like lan0 or wireless0 or use predictable interface names (which have been enabled by default since udev version 197).

Recuerde también eliminar los ficheros antiguos de las versiones anteriores de udev:

Ver también
eudev. Un derivado de udev mantenido por Gentoo.

Recursos externos

 * Código fuente de udev