Examples of simple uses of Udev

Source: Internet
Author: User

Udev is a new approach to device management in kernel2.6, and Udev can find information about the device through the/sys directory under SYSFS, so there is no need to create all of the device files in/dev in advance, but to dynamically and flexibly support hot-swappable functions. Automatically create device files for related devices, very resilient.

The configuration files in Udev are under/etc/udev/, where the rule.d/directory is a specific rule file (which will focus on the writing of the rules later), and udev.conf is the UDEV global configuration file.

When you open the udev.conf file with vim, you will find that there is only one content about Udev's log level.

650) this.width=650; "title=" QQ picture 20150401132151.png "Src=" http://s3.51cto.com/wyfs02/M01/5C/26/ Wkiom1ubga2chhe6aadnovijxni127.jpg "alt=" Wkiom1ubga2chhe6aadnovijxni127.jpg "/>

Of course, we can write other content in this conf file, such as Udev_root=/dir, on behalf of our device files can be in their own definition of the directory, the default is under the/dev/, no special needs, generally do not add this entry.

The following focuses on how Udev rules are written, before we consider a scenario such as we find a ip-san device, such as iSCSI, because the iSCSI device is not on the local service, so there may be every time the iSCSI device is connected, Our device name is not the same (the first discovery may be/dev/sdb, the second discovery may be called/DEV/SDC), this will cause users to use the time of the device is not inconsistent, or when we insert a USB flash drive, I hope the name of the U disk is called Myusb, Instead of being a system-assigned name, you need to write the rules, which is the benefit of udev. Then all of our default rules are stored in the/etc/udev/rule.d/directory we just mentioned.

650) this.width=650; "title=" QQ picture 20150401132919.png "Src=" http://s3.51cto.com/wyfs02/M02/5C/21/ Wkiol1ubgwxczq2naadguhjva1g196.jpg "alt=" Wkiol1ubgwxczq2naadguhjva1g196.jpg "/>

This rule can be found named by the number-rule name. Rules, so our custom rule names can put numbers bigger, but not more than 100, for example, we can write a rule called 99-myusb.rules

Here are some of the formatting and symbols of the writing rules that need to be understood

Format: 650) this.width=650; "title=" QQ picture 20150401145037.png "Src=" http://s3.51cto.com/wyfs02/M01/5C/23/ Wkiol1ublhbafw9caaa9mz7oatw423.jpg "alt=" Wkiol1ublhbafw9caaa9mz7oatw423.jpg "/>

Symbol: = = Match key value pair

= assigned value

+ = Append Assignment

: = cannot be overwritten after assignment

Let's take a moment to hide the example, when inserting a USB flash drive, the default system generates a/DEV/SDX device name

By writing your own rules so that the USB stick is inserted, you can generate a custom device name such as/dev/myusb

Then there is a question to consider, why does the system think that the USB stick you inserted is the MYUSB device, not the other one? This will require a special USB stick to find a (some) only its own properties (uniqueness)

To view the properties of a device by Udevadm Info-a (all properties)-P (PATH) command

Udevadm Info-a-p/sys/block/sdb

Find a few special properties

Here's a simple rule message:

650) this.width=650; "title=" QQ picture 20150401145909.png "Src=" http://s3.51cto.com/wyfs02/M00/5C/28/ Wkiom1ublutxna0kaabbdpltavw161.jpg "alt=" Wkiom1ublutxna0kaabbdpltavw161.jpg "/>

Re-inserting the USB drive will generate a/DEV/MYUSB device

650) this.width=650; "title=" QQ picture 20150401150201.png "Src=" http://s3.51cto.com/wyfs02/M02/5C/23/ Wkiol1ubmmishvcfaabqjcxsp18446.jpg "alt=" Wkiol1ubmmishvcfaabqjcxsp18446.jpg "/>

Of course, we can add more content in our rules, for example, when the USB drive is inserted, the system automatically recognizes the name/dev/sdb, and also gives the device a link, named/dev/myusb

650) this.width=650; "title=" QQ picture 20150401151411.png "Src=" http://s3.51cto.com/wyfs02/M02/5C/29/ Wkiom1ubmmmsbtrwaaa7vqryrw0823.jpg "alt=" Wkiom1ubmmmsbtrwaaa7vqryrw0823.jpg "/>

Reinsert the USB drive, observe the/DEV/SDB, and have a link to the/DEV/MYUSB on the SDB

650) this.width=650; "title=" QQ picture 20150401151548.png "Src=" http://s3.51cto.com/wyfs02/M00/5C/29/wKiom1Ubmr_ Aiuqsaabicez2snm991.jpg "alt=" Wkiom1ubmr_aiuqsaabicez2snm991.jpg "/>

Of course, we can also add more content, Udev provides a wealth of resources, such as the added device can be added to the owner and the ability to have a group, you can add a device, and immediately run a script and other functions.

This article is from the "Sir Teng" blog, please be sure to keep this source http://naturelong1989.blog.51cto.com/627491/1627327

Examples of simple uses of Udev

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.