Udev is the device manager for the Linux 2.6 kernel that creates/removes device nodes in the /dev directory dynamically. Udev provides a persistent device naming system through the /dev directory, making it easier to identify the device.
/dev/disk/by-id: Contains persistent symbolic links created by Udev for the hard disks attached to a system. Persistent device naming helps to identify the hardware device without much trouble.
Flow
Kernel (uevent) .......> udevd ........> udev ........> modprobe [loads driver (kernel Module)]
udev daemon runs in user space. The udev daemon
(udevd) reads the rules files at system startup and stores the rules in memory.
If the kernel discovers a new device or an existing device goes offline, the
kernel sends an event action (uevent) notification to udevd, which matches the
in-memory rules against the device attributes in /sys to identify the device.
As part of device event handling, rules can specify additional programs that
should run to configure a device.
What is udev rules
Udev reads the rules and stores them in the memory. udev daemon parses the rules in /etc/udev/rules.d/ for every device state change in the kernel. It will create the device nodes and symbolic links for the devices as specified in the rules.
Rules path
a) /lib/udev/rules.d
Contains default
rules files. Do not edit these files.
b) /etc/udev/rules.d/*.rules
Contains customized
rules files. You can modify these files.
c) /dev/.udev/rules.d/*.rules
Contains temporary
rules files. Do not edit these files.
The data in the rules has the major/minor number pair and other device specific data such as device/vendor id, device serial number etc. The Udev rule can match all this data to change the name of the device node, create symbolic links or register the network link.
Why Do We Need It ?
In the older kernels, the /dev directory contained
statics device files. But with dynamic device creation, device nodes for only
those devices which are actually present in the system are created. Let us see
the disadvantages of the static /dev directory, which led to the development of
Udev.
In the static model of device node creation, no method
was available to identify the hardware devices actually present in the system.
So, device nodes were created for all the devices that Linux was known to
support at the time. The huge mess of device nodes in /dev made it difficult to
identify the devices actually present in the system.
Sample udev rule file
# Enter raw device bindings here.
#
# An example would be:
# ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"
# to bind /dev/raw/raw1 to /dev/sda, or
# ACTION=="add", ENV{MAJOR}=="8", ENV{MINOR}=="1", RUN+="/bin/raw /dev/raw/raw2 %M %m"
# to bind /dev/raw/raw2 to the device with major 8, minor 1.
The following example shows how a network device is getting renamed in a system.
[[root@test rules.d]# cat 70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:8c:37:88", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:8c:14:b9", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
[root@test rules.d]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:8C:37:88
eth1 Link encap:Ethernet HWaddr 00:50:56:8C:14:B9
No comments:
Post a Comment