Introduction to device management in modern Linux systems

Source: Internet
Author: User
Article Title: describes the device management of modern Linux systems. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

The modern Linux release can identify a new hardware in a running system. There are many user-friendly releases, such as Ubuntu, which can automatically run specified applications, such as Rhythmbox, when a mobile device such as iPod is inserted into the system.

The hot swapping (used to describe the process of inserting a device into a running system) function in the Linux release is a combination of three components: Udev, HAL, and plugin.

Udev provides a dynamic Device directory for device nodes connected to the system. When a device is inserted or removed from the system, Udev creates or deletes the device node file under the/dev directory. The middleware is similar to the system bus and is mainly used for inter-process communication. HAL obtains information from the Udev service. When a device is connected to the system, it creates an XML description about the device. Then, it notifies the corresponding desktop application through the attachment. For example, Nautilus and Nautius will open the file above the new mounted device.

This article only focuses on Udev, which completes basic device identification.

What is Udev?

Udev is the Device Manager of Linux 2.6 kernel. It dynamically creates/removes device nodes under the/dev directory. It is the successor of devfs and hotplug and runs in the user space. You can use Udev rules to change the device name.

Udev depends on the sysfs file system introduced by the 2.5 kernel. Sysfs is visible to devices in user space. Every time a device is added or removed, a kernel event is generated to notify the Udev of the user space.

In early releases, an external binary file/sbin/hotplug was often used to notify Udev of device status changes. Now this tool has been replaced, and Udev can directly listen to these events through Netlink.

Why do we need it?

In earlier kernels, the/dev directory included some static device files. After a dynamic device is created, only the device nodes that actually exist in the system are created. Let's take a look at the shortcomings of the static/dev directory, which leads to Udev development.

Precisely identifies a hardware device in the/dev device Node

During system startup, the kernel allocates a primary/secondary device number pair to a recognized hardware device. Let's consider two hard disks. The connection/calibration method is one connection to the master interface and the other connection to the slave interface. In Linux, they are called/dev/hda and/dev/hdb. Now, if we switch two disks, their device names will change. This makes it difficult to locate an available dynamic device node to the correct device. When a bunch of hard disks are connected to the system, the situation becomes worse.

Udev provides a permanent device naming system through the/dev directory, making it easy to locate devices.

The following example shows the permanent symbolic link created by Udev for the hard disk connected to the system.

$ Ls-lR/dev/disk // dev/disk/by-id: lrwxrwxrwx 1 root 9 Jul 4 scsi-SATA_WDC_WD800JD-75M_WD-WMAM9UT48593-> .. /.. /sda lrwxrwxrwx 1 root 10 Jul 4 scsi-SATA_WDC_WD800JD-75M_WD-WMAM9UT48593-part1-> .. /.. /sda1lrwxrwxrwx 1 root 10 Jul 4 06:48 scsi-SATA_WDC_WD800JD-75M_WD-WMAM9UT48593-part2-> .. /.. /sda2lrwxrwxrwx 1 root 10 Jul 4 scsi-SATA_WDC_WD800JD-75M_WD-WMAM9UT48 593-part3-> .. /.. /sda3lrwxrwxrwx 1 root 10 Jul 4 06:48 scsi-SATA_WDC_WD800JD-75M_WD-WMAM9UT48593-part4-> .. /.. /sda4lrwxrwxrwx 1 root 10 Jul 4 scsi-SATA_WDC_WD800JD-75M_WD-WMAM9UT48593-part5-> .. /.. /sda5lrwxrwxrwx 1 root 10 Jul 4 06:48 scsi-SATA_WDC_WD800JD-75M_WD-WMAM9UT48593-part6-> .. /.. /sda6lrwxrwxrwx 1 root 10 Jul 4 scsi-SATA_WDC_WD800JD-75M_WD-WMAM9UT48593- Part7-> .. /.. /sda7/dev/disk/by-label: lrwxrwxrwx 1 root 10 Jul 4 1-> .. /.. /sda6lrwxrwxrwx 1 root 10 Jul 4 boot1-> .. /.. /sda2lrwxrwxrwx 1 root 10 Jul 4 project-> .. /.. /sda3lrwxrwxrwx 1 root 10 Jul 4 06:48 SWAP-sda7-> .. /.. /sda7/dev/disk/by-path: lrwxrwxrwx 1 root 9 Jul 4 06:48 pci-0000: 00: 1f. 2-scsi-0: 0: 0: 0-> .. /.. /sdalrwxrwxrwx 1 root 10 Jul 4 06: 48 pci-0000: 00: 1f. 2-scsi-0: 0: 0: 0-part1-> .. /.. /sda1lrwxrwxrwx 1 root 10 Jul 4 pci-0000: 00: 1f. 2-scsi-0: 0: 0: 0-part2-> .. /.. /sda2lrwxrwxrwx 1 root 10 Jul 4 pci-0000: 00: 1f. 2-scsi-0: 0: 0: 0-part3-> .. /.. /sda3lrwxrwxrwx 1 root 10 Jul 4 pci-0000: 00: 1f. 2-scsi-0: 0: 0: 0-part4-> .. /.. /sda4lrwxrwxrwx 1 root 10 Jul 4 pci-0000: 00: 1f. 2-scsi-0: 0: 0: 0-part5-> .. /.. /sda5 Lrwxrwxrwx 1 root 10 Jul 4 pci-0000: 00: 1f. 2-scsi-0: 0: 0: 0-part6-> .. /.. /sda6lrwxrwxrwx 1 root 10 Jul 4 pci-0000: 00: 1f. 2-scsi-0: 0: 0: 0-part7-> .. /.. /sda7/dev/disk/by-uuid: lrwxrwxrwx 1 root 10 Jul 4 06:48 18283DC6283DA422-> .. /.. /sda1lrwxrwxrwx 1 root 10 Jul 4 06:48 25a4068c-e84a-44ac-85e6-461b064d08cd-> .. /.. /sda6lrwxrwxrwx 1 root 10 Jul 4 06:48 3ea7cf15-0000b- 407a-a56b-c6bfa046fd9f-> .. /.. /sda5lrwxrwxrwx 1 root 10 Jul 4 06:48 8878a0a4-604e-4ddf-b62c-637c4fa84d3f-> .. /.. /sda2lrwxrwxrwx 1 root 10 Jul 4 e50bcd6d-61ea-4b05-81a8-3cbe17ad6674-> .. /.. /sda3 permanent device named as identifying hardware device saves a lot of trouble.

/Dev

In the static creation model of the device node, there is no way to identify whether the hardware device actually exists in the system. Therefore, all devices recognized by Linux have created device nodes. The large number of device nodes in/dev makes it difficult to identify devices in a system.

The primary/secondary device number is not enough

In recent years, the number of static device nodes to be included has increased too much, so that the previously used 8-Bit mode is not enough to process all devices. Therefore, the primary/secondary device number pair starts to use up.

Character devices and Block devices have a fixed allocation of primary/secondary device number pairs. The official organization for allocating the primary/secondary device Number pairs is Linux Assigned Name and Number Authority. However, a machine does not use all possible devices. Therefore, a system must have unused primary/secondary device numbers. In this case, the kernel of the machine can borrow the primary/secondary device numbers that are not using the device and give them to other required devices.

Sometimes this will cause problems. Because applications that operate on devices in a user space may not be aware of changes in device numbers. For user space programs, the device number allocated by LANANA is very important. Therefore, the applications must be notified of changes to the master/secondary device number. This is called the Dynamic Allocation of the master/sub device number. Udev has completed this task.

[1] [2] [3] Next page

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.