Http://hi.baidu.com/zkheartboy/item/28ae757710624b2bd7a89c28udev details if you use Linux for a long time, then you know, in the treatment of the device file this, Linux has changed several times the policy. In the early days of Linux, the device file was just a common file with an appropriate property set. It was created by the mknod command and stored in the/dev directory. Later, devfs, a kernel-based dynamic device file system, first appeared in the 2.3.46 kernel. This method is used for distribution in linux such as Mandrake and Gentoo. The device files created by devfs are dynamic. However, devfs has some serious restrictions
2.6.13 is removed. At present, it is replaced by the udev mentioned in the text-a user space program.
At present, many Linux distribution versions adopt the udev method because it is accessed on Linux devices, especially those sites that have extreme requirements on devices (such as the need to control thousands of hard disks) and hot swapping devices (such as USB cameras and MP3 players. Next let's take a look at how to manage udev devices.
In fact, you do not need to modify the standard configuration files for disks, devices, and other devices. However, you need to understand the udev configuration to use new or external devices. If you do not modify the configuration, these devices may not be accessible, or Linux may use an inappropriate name, group or permission to create these device files. You may also want to know how to modify the group or permissions of files such as RS-232 serial ports and audio devices. This is encountered in the actual implementation of Linux.
Why udev?
The methods for managing Device Files (static files and devfs) have the following Disadvantages:
* Uncertain device ing. In particular, the mappings between dynamic devices, such as USB devices and device files to the actual devices, are not reliable and definite. For example, if you have two USB printers. One may be/dev/USB/lp0, and the other is/dev/USB/lp1. However, it is unclear which one is the specific device. lp0 and lp1 have no one-to-one relationship with the actual device, because it may be due to the order of the device, this ing is not determined due to reasons such as printer shutdown. The ideal way is to map two printers to a unique backup file based on their serial number or other identification information. But neither static files nor devfs can do this.
* There are not enough primary/secondary device numbers. We know that each device file has two 8-digit numbers: one is the master device number, and the other is allocated by the auxiliary device number. The two eight-digit numbers plus the device type (Block device or character device) uniquely identify a device. Unfortunately, there are not enough numbers associated with these.
* The/dev directory contains too many files. If a system uses static Device File Association, there must be enough files in this directory. At the same time, you do not know which device files are activated on your system.
* The name is not flexible enough. Although devfs solves some previous problems, it also brings some problems. One of them is that the name is not flexible enough; you can modify the name of the device file without thinking about it. The default devfs command mechanism is also strange. It needs to modify a large number of configuration files and programs .;
* For kernel memory usage, another problem exclusive to devfs is that as the kernel driver module, devfs consumes a large amount of memory, especially when there are a large number of devices on the system (for example, the system we mentioned above has thousands of magnetic disks on one)
Udev aims to solve these problems. It manages the/dev/directory tree using the user-space tool, which is separated from the file system. Know how to change the default configuration so that you can customize your system, such as creating device character connections, changing device file groups, permissions, and so on.
Udev configuration file
The main udev configuration file is/etc/udev. conf. This file is usually very short. It may only contain comments starting with "#" and there are several options:
Udev_root = "/dev /"
Udev_rules = "/etc/udev/rules. d /"
Udev_log = "Err"
The second line above is very important because it indicates the directory stored by udev rules, which stores files ended with. Rules. Each file processes a series of rules to help udev allocate names to device files to ensure that they can be recognized by the kernel.
There may be several udev rule files under your/etc/udev/rules. D. Some of these files are installed in the udev package, while others may be generated by other hardware or software packages. For example, on the Fedora Core 5 system, the sane-backends package will install the 60-libsane.rules file. In addition, the initscripts package will install the 60-net.rules file. The names of these rule files usually start with two numbers, which indicates the order in which the rule is applied by the system.
The rules in the Rule file consist of a series of key/value pairs, which are separated by commas. Each key is a user-matching key, or an assignment key. Match the key to determine whether the rule is applied, and assign a value to the key. These values will affect the device files created by udev. The value assignment key can process a multi-value list. The following table describes the matching key and value assignment key operators:
Udev key/value pair Operator
Operator matching or value assignment t Interpretation
----------------------------------------
= Matching equal comparison
! = Unequal matching comparison
= Assign a specific value to the key, which can overwrite the previous value.
+ = Assign a value to append a specific value to an existing key.
: = Assign a specific value to the key, and the subsequent rules cannot overwrite it.
This is a bit similar to our common programming languages, such as C language. Only the key here can process multiple values at a time. Some keys often appear in udev rule files. The values of these keys can use wildcards (*,?, For example, [0-9]). These common keys are listed as follows:
Common udev keys
Key description
Action: The name of a time activity, such as ADD. When a device is added
The name of the device that the kernel sees in the kernel. For example, SD * indicates any SCSI disk device.
Enter the devpath kernel device, such as/devices /*
Subsystem name, such as sound, Net
Bus name, such as IDE, USB
Driver device driver name, such as ide-CDROM
The device ID is independent of the kernel name.
Sysfs {value} sysfs attribute value, which can represent any
Env {key} environment variable, which can represent any
An executable program of the program. If the program returns 0, the key is considered true)
The standard output returned by the previous program call of result.
Name of the device file created according to this rule. Note: Only the name description in the first line is valid and is ignored later.
If you want to use more than two names to access a device, consider the symlink key.
The character connection name created by symlink according to the rule.
Owner device file owner
The group where the group device file is located.
The permission of the Mode Device File in octal format.
List of programs run for the device
Label used for internal control in the configuration file (the following goto Service)
Goto jumps to matching rules (identified by label ).
Import {type} import the Rule Set generated after a file or program is executed to the current file
Wait_for_sysfs waits for the creation of a specific device file. It is mainly used for timing and dependency issues.
Ptions-specific options: last_rule executes the terminal rule for such devices; ignore_device ignores the current rule; ignore_remove ignores the next and removes the request.
All_partitions creates device files for all disk partitions.
We provide a column to explain how to use these keys. The following example is from the standard configuration file of the Fedora Core 5 system.
Kernel = "*", owner = "root" group = "root", mode = "0600"
Kernel = "tty", name = "% K", group = "tty", mode = "0666", Options = "last_rule"
Kernel = "SCD [0-9] *", symlink + = "CDROM-% K"
Kernel = "HD [A-Z]", bus = "ide", sysfs {removable} = "1 ", sysfs {Device/media }== "CDROM", symlink + = "CDROM-% K"
Action = "add", subsystem = "scsi_device", run + = "/sbin/modprobe SG"
The preceding example provides five rules, each starting with the kernel or action key:
* The first rule is the default rule. It matches any device identified by the kernel and sets the owner group of these devices as root and the group as root, access permission mode is 0600 (-RW -------). This is also a safe default setting to ensure that only the root user can read and write all devices by default.
* The second rule is also a typical rule. It matches the terminal device (TTY) and then sets the new permission to 0600. The group is TTY. It also sets a special device file name: % K. In this example, % K indicates the kernel name of the device. This means that the kernel identifies the names of these devices and creates the file names.
* The kernel = "SCD [0-9] *" starting from line 3 indicates the SCSI CD-ROM driver. It creates a pair of device symbolic connections: CDRom and CDROM-% K.
* In the fourth line, the starting kernel = "HD [A-Z]" indicates the ata cdrom Drive. This rule creates a symbolic connection with the above rule. The ata cdrom driver requires sysfs value to distinguish other ata devices, because scsi cdrom can be uniquely identified by the kernel ..
* The fifth line starts with action = "add". It tells udev to add/sbin/modprobe SG to the command list. When any SCSI device is added to the system, these commands will be executed. The result is that the computer should add the SG kernel module to detect new SCSI devices.
Of course, the above is just a small example. If your system adopts the udev method, you should be able to see more rules. If you want to modify the device permission or create a symbolic connection, you need to read these rules carefully, especially those devices related to the change.
Modify Your udev Configuration
Before modifying the udev configuration, we must be careful. The general consideration is: You 'd better not modify the rules preset by the system, especially do not specify the configuration with a very wide impact, for example, the first line in the example above. Incorrect configuration may cause serious system problems or the system cannot access the device correctly.
The correct method is to create a rule file for a letter under/etc/udev/rules. d. Make sure that the suffix of your file is the number sequence given by the Rules file name, which should be higher than that of the standard configuration file. For example, you can create a rule file named 99-my-udev.rules. In your rule file, you can specify any configuration You Want To modify. For example, if you modify the group where the floppy device is located, you are also preparing to create a letter symbolic connection/dev/floppy, so you can write it like this:
Kernel = "FD [0-9] *", group = "users", symlink + = "Floppy"
Some release versions, such as fedora, use external scripts to modify the group, group relationship, and permissions of certain devices. Therefore, the above changes may not take effect. If you encounter this problem, you need to track and modify this script to achieve your goal. Or you can modify the value of the program or run key to do this.
Modifications to some rules may require further exploration. For example, you may want to use sysfs information on a device to uniquely identify a device. You are advised to use the udevinfo command to obtain the information.
$ Udevinfo-a-p $ (udevinfo-Q path-N/dev/hda)
The preceding command uses udevinfo twice: returns the sysfs device path (which is usually different from the path of the Linux Device File name we see --/dev/hda ); the second query is the device path, and the result is a summary of non-common syfs information. You can find the most adequate information to uniquely identify your device. You can replace the sysfs option in the udev configuration file with appropriate information. The following result is the preceding command output.
[Root @ localhost rules. d] # udevinfo-a-p $ (udevinfo-Q path-N/dev/hda1)
Udevinfo starts with the device specified by the devpath and then
Walks up the chain of parent devices. It prints for every device
Found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
And the attributes from one single parent device.
Looking at device '/block/hda/hda1 ':
Kernel = "hda1"
Subsystem = "Block"
Driver = ""
ATTR {stat }= = "1133 2268 2 4"
ATTR {size }== "208782"
ATTR {start }= = "63"
ATTR {Dev }= = "3:1"
Looking at Parent device '/block/hda ':
Kernels = "hda"
Subsystems = "Block"
Drivers = ""
Attrs {stat }= = "28905 18814 1234781 302540 34087 133247 849708 981336 0 218340 1283968"
Attrs {size }= = "117210240"
Attrs {removable} = "0"
Attrs {range }= = "64"
Attrs {Dev }== "3:0"
Looking at Parent device '/devices/pci0000: 00/0000: 00: 1f. 1/ide0/8080 ':
Kernels = "0.0"
Subsystems = "ide"
Drivers = "ide-disk"
Attrs {modalias }== "Ide: M-disk"
Attrs {drivename} = "hda"
Attrs {media }= = "disk"
Looking at Parent device '/devices/pci0000: 00/0000: 00: 1f. 1/ide0 ':
Kernels = "ide0"
Subsystems = ""
Drivers = ""
Looking at Parent device '/devices/pci0000: 00/0000: 00: 1f. 1 ':
Kernels = "0000: 00: 1f. 1"
Subsystems = "PCI"
Drivers = "piix_ide"
Attrs {broken_parity_status} = "0"
Attrs {enable} = "1"
Attrs {modalias }= = "pci: v20178086d201724casv2017144dsd2017c009bc01sc01i8a"
Attrs {local_cpus} = "1"
Attrs {IRQ} = "11"
Attrs {class }== "0x01018a"
Attrs {subsystem_device} = "0xc009"
Attrs {subsystem_vendor }== "0x144d"
Attrs {Device} = "0x24ca"
Attrs {vendor} = "0x8086"
Looking at Parent device '/devices/pci0000: 00 ':
Kernels = "pci0000: 00"
Subsystems = ""
Drivers = ""
For example, suppose you want to modify the configuration of the USB scanner. Through a series of attempts, you have identified the Linux device file for the scanner (the name will change every time you open the scanner ). You can use the above command to replace the correct Linux device file name, and then locate the output lines using sysfs {idvendor} And sysfs {idproduct. Finally, you can use this information to create new options for the scanner.
Sysfs {idvendor }== "0686 ",\
Sysfs {idproduct }== "400e ",\
Symlink + = "Courier", mode = "0664 ",\
Group = "external"
In the preceding example, the scanner group is set to allow, the access permission is set to 0664, and A/dev/configure symbolic connection is created.
Udev (Simplified Chinese)
From archwiki
Jump to: navigation, search
I18n
English
When there are too many other users
Traditional Chinese
Simplified Chinese
Note: If you upgraded from devfs to udev, see devfs to udev.
This document introduces some new udev changes. From version 084, udev can replace all functions of hotplug and coldplug. Because of this, the hotplug package has been removed from the arch repository.
Contents
[Hide]
* 1 Important Note
* 2 Basic Requirements
* 3 latest updates
* 4. Module disabling list
* 5 load_modules: Useful startup parameters
* 6 known hardware problems
* 7 problems caused by automatic loading
O 7.1 cpufreq Module
O 7.2 sound problems and some modules that cannot be automatically loaded
O more than 7.3 devices of the same type (NIC and Sound Card) Start differently each time
* 8 some known problems caused by self-compiling the kernel
O 8.1 udev cannot be started
O 8.2 CD/DVD symbols and permission errors
* 9 udev tips
O 9.1 automatically loaded USB device
Important
... Remember, before using udev to load any modules (kernel module) (whether it is automatically loaded at startup or not), you must go to/etc/rc. conf sets the mod_autoload option to yes. Otherwise, you must manually load these modules. You can modify the modules in RC. conf or use the modprobe command to manually load the required modules. Another way is to use hwdetect -- modules to generate the modules list of system hardware, and then add this list to RC. conf so that the modules will be automatically loaded when the system starts.
Basic Requirements
* Kernel: 2.6.15 or later.
* You will not be able to use the devfs format device name in fstab and bootloader settings! For more information, see devfs to udev.
Latest update
* The startudev program is removed. To reload the udev rule, use/etc/start_udev.
* Udev replaces hotplug and hwdetect functions. At the same time, hwdetect is saved and used only when the mkinitrd program generates initrd.
* Udev can load multiple modules at the same time, which can accelerate the startup speed. However, the result is that she cannot guarantee the order of loading each time, therefore, when you use multiple sound cards or NICs, problems may occur. This issue will be discussed later.
Module disabled list
Udev also makes mistakes or loads wrong modules. To prevent errors, you can disable the list using modules. Once added to the list of modules, udev will not load these modules at startup or Runtime (such as USB hard disk.
You only need to add an exclamation point (!) to the module in the modules of RC. conf (!) You can disable this module.
For example,
Modules = (! Modulea! Moduleb)
Load_modules: Useful startup parameters
If you add load_modules = off to the kernel startup parameters, udev stops automatic loading. This function is very useful when a system problem occurs. If udev loads faulty modules, causing system suspension or other serious problems, you can use this parameter to disable automatic loading to prevent loading of faulty modules.
Known hardware problems
-The buslogic device is damaged and crashes upon startup.
This is a kernel bug that has not been fixed yet.
-The PCMCIA card reader is considered a Removable device.
Add them to/etc/pmount. Allow and use Hal's pmount to read them.
Problems caused by automatic loading
Cpufreq Module
We haven't found a good way to load different cpufreq controllers, So we removed it from the auto-loading process. If you need to measure the CPU frequency, you must explicitly add the appropriate modules in the RC. conf modules queue.
Sound problems and some modules that cannot be loaded automatically
Some User tracking finds that the problem lies in some old parts in/etc/modprobe. conf. Try to remove these old parts and try again.
Multiple devices of the same type (NIC and Sound Card) Start differently each time.
Because udev loads all modules at the same time, some devices may have different initialization sequence. For example, if two NICs exist at the same time, they are always changed between eth0 and eth1.
The common solution is to specify the order by modifying the modules queue in your RC. conf file. The modules in this queue will be loaded by the system before udev is automatically loaded. Therefore, you can control the loading sequence of the modules at startup.
# Load 8139too before E100
Modules = (8139too E100)
Another solution to the NIC is to use the udev-sanctified method to statically name each Nic. Create the file/etc/udev/rules. d/10-network.rules and bind different NICs to different names through the MAC address:
Subsystem = "Net", sysfs {address} = "AA: BB: CC: DD: EE: FF", name = "lan0"
Subsystem = "Net", sysfs {address} = "FF: EE: DD: CC: BB: AA", name = "wlan0"
Note the following:
* You can use the following command to obtain the MAC address of the NIC: udevinfo-a-p/sys/class/NET/<your Nic>
* Note that the udev rule file uses lowercase hexadecimal MAC addresses because udev cannot recognize uppercase MAC addresses.
* Some users may encounter problems when using the old naming method, such as eth0 and eth1. If this problem occurs, try using names such as "Lan" or "WLAN.
Do not forget to modify your/DEC/rc. conf and other configuration files named after ethx.
Some known problems caused by self-compiling the kernel
Udev cannot start
Make sure that your kernel version is later than or equal to 2.6.15. Earlier kernels did not have the uevent function required for udev to automatically load.
Incorrect CD/DVD symbols and permissions
If you use kernel 2.6.15, install the uevent patch of ABS (which extracts some uevent functions from kernel 2.6.16 ). You can use the ABS command to synchronize the ABS tree, and then you can find the ABS patch under/var/ABS/kernels/kernel26.
Udev tips
Automatically attach USB device
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 = "/lib/udev/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"
Put these udev rules in any file name ending with. Rules under/etc/udev/rules. d/, such as/etc/udev/rules. d/SDA. Rules.
If you want to establish a/media to/mnt symbolic connection at the same time, you can use the following version:
Kernel = "SD [A-Z]", name = "% K", symlink + = "usbhd-% K", group = "users", Options = "last_rule"
Action = "add", kernel = "SD [A-Z] [0-9]", symlink + = "usbhd-% K", group = "users ", name = "% K"
Action = "add", kernel = "SD [A-Z] [0-9]", run + = "/bin/mkdir-P/Media/usbhd-% K"
Action = "add", kernel = "SD [A-Z] [0-9]", run + = "/bin/ln-S/Media/usbhd-% K/mnt/usbhd-% K"
Action = "add", kernel = "SD [A-Z] [0-9]", program = "/lib/udev/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/Media/usbhd-% K ", 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/Media/usbhd-% K ", Options =" last_rule"
Action = "Remove", kernel = "SD [A-Z] [0-9]", run + = "/bin/Rm-F/mnt/usbhd-% K"
Action = "Remove", kernel = "SD [A-Z] [0-9]", run + = "/bin/umount-L/Media/usbhd-% K"
Action = "Remove", kernel = "SD [A-Z] [0-9]", run + = "/bin/rmdir/Media/usbhd-% K", Options = "last_rule"
Note! If you are using other fixed devices (such as SATA hard disks, you can view them in/etc/fstab, you must remove your sdx from SD [A-Z. For example, if your SATA hard drive is identified as/dev/SDA, you need to replace all "SD [A-Z]" with "SD [B-Z]". Adding numbers (for example, 010. udev. Rules) before the file name of the Rule file is a good idea, so that udev will read the rule file before reading the standard rule. You do not need to modify the/etc/fstab file after setting these rules. View the parameters of the mount command to modify permissions and other features (you can search and view the parameters of the mount command from the Forum, and then modify them as needed ).