Hot Plug and mdev mechanism in Linux __linux

Source: Internet
Author: User




hot-swappable and mdev mechanism in Linux

Little Wolf @http://blog.csdn.net/xiaolangyangyang


Mdev is a simplified version of the BusyBox Udev, the role is in the system startup and hot plug or dynamic loading of the driver, automatically generate the driver required node files, in the file system in the/dev directory of the device nodes are created by the Mdev Mdev scan/sys/ Class and/sys/block, if the directory contains a file named "Dev" and the file contains a device number, Mdev uses this information to create device node usage for this device under/dev:

1./sys to be mounted before performing Mdev
Mount-t Tmpfs Mdev/dev
Mount-t Sysfs Sysfs/sys

2. The command kernel performs/sbin/mdev when adding or deleting devices, so that the device nodes are created and deleted
Echo/sbin/mdev >/proc/sys/kernel/hotplug

3. Set Mdev to create all device nodes when the system starts
Mdev-s

about Hot-swappable:
Requires support in kernel HotPlug
Write Mdev configuration file:/etc/mdev.conf
The purpose of this file is to automatically execute custom commands when a matching device is found Mdev
The format is:: [<@$*>]
@ After the node is created
$ executed before deleting a node

* Run after creation and before deletion
such as automatically mount U disk and SD card script:
1. sd[a-z][0-9] 0:0 0660 @/etc/hotplug/usb/udisk_insert
2. sd[a-z] 0:0 0660 $/etc/hotplug/usb/udisk_remove
3. mmcblk[0-9]p[0-9] 0:0 0660 @/etc/hotplug/sd/sd_insert
4. mmcblk[0-9] 0:0 0660 $/etc/hotplug/sd/sd_remove
5. When a device such as SDA1 is detected, execute the script in/etc/hotplug/usb, the content of the script is to mount and uninstall U disk, and when a device like MMCBLK0P1 is detected, execute/ETC/HOTPLUG/SD script. The content of the script is to mount and uninstall the SD card.
Mdev is a busybox in a Udev management program of a streamlined version, he can also achieve the automatic device node creation and equipment automatic mount, only in the process of implementation of a little difference in the occurrence of hot plug time, Mdev is hotplug direct call, Then mdev the action and DEVPATH in the environment variable to determine the behavior of the hot-swappable event and the directory that affected the/sys. Then you will see if there is a "dev" attribute file in this directory, and if so, use this information to create a device node file for the device in/dev.
Here's how to get our system to support Mdev.

1. When using BusyBox to make the root file system, select Support Mdev
Linux System Utilities--->
[*] Mdev
[*] Support/etc/mdev.conf
[*] Support command execution at device Addition/removal

2. Add the following content to the file system
Vim/etc/init.d/rcs
Mount-t Tmpfs Mdev/dev
Mount-t Sysfs Sysfs/sys
Mkdir/dev/pts
Mount-t devpts devpts/dev/pts
Echo/sbin/mdev>/proc/sys/kernel/hotplug
Mdev–s
These statements are added to the Mdev manual.

3. Add the response to hot plug events to achieve the USB disk and SD card automatic mount.
Vim/etc/mdev.conf
MMCBLK[0-9]P[0-9] 0:0 666 @/etc/sd_card_inserting
MMCBLK[0-9] 0:0 666 $/etc/sd_card_removing
SD[A-Z] [0-9] 0:0 666 @/etc/usb/usb_inserting
SD[A-Z] 0:0 666 $/etc/usb/usb_removing
The Red section is a script that can be customized according to our needs and can be mounted, unloaded, or some other feature.

The following are the scripts that are automatically mounted and unloaded:
/etc/sd_card_inserting
#!/bin/sh
Mount-t VFAT/DEV/MMCBLK0P1/MNT/SD
/etc/sd_card_removing
#!/bin/sh
Sync
Umount/mnt/sd

module_device_table
Module_device_table is generally used in hot-swappable device drivers.
The xxx_driver_ids structure is a list of supported devices for the drive.
The role is: the xxx_driver_ids structure output to the user space, so that the module loading system in the loading module, we know what the module corresponds to what hardware equipment.
Usage: module_device_table (device type, equipment table), in which, the type of equipment, including USB,PCI, can also name themselves, the above code is for different platform class; The device table is also defined by itself, and its last item must be empty to identify the end.

References: Hot-swappable and mdev mechanisms in Linux

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.