Mdev introduction and usage:
Mdev is a lite version of a udev Management Program in busybox. It can also automatically create device nodes and mount devices, but it is a little different in the implementation process, in the event of hot swapping, mdev is directly called by hotplug. In this case, mdev uses the ACTION and DEVPATH in the environment variable to determine the ACTION of the hot swapping event and the directory in/sys. Check whether the "dev" attribute file exists in the directory. If yes, use this information to create a device node file for the device under/dev.
1) Basic Introduction and usage of mdev
Mdev has two main applications: initialization object and dynamic update. Both applications require support from the kernel sysfs and must be mounted to/sys. To achieve dynamic updates, you must also add hotplugin support during Kernel configuration. \ below is a typical code snippet using mdev in the system initialization script.
[1] mount-t sysfs/sys
[2] echo/bin/mdev>/proc/sys/kernel/hotplug
[3] mdev-s
Of course, a more complete installation of mdev must also execute the following command before the above code snippet:
[4] mount-t tmpfs mdev/dev
[5] mkdir/dev/pts
[6] mount-t devpts/dev/pts
Briefly describe the above Code:
[1] You must mount/sys before executing mdev
[2] Then you [2] Run the command kernel to execute/bin/mdev when adding or deleting devices.
[3] Set mdev to create all the device nodes when the system starts.
[4] for more complete mdev installation, you must ensure that [4]/dev is tmpfs
[5] (assuming the file system runs outside flash), and you must [5] Create
2) mdev. conf rules
: [<@ | $ | *>]
Devic regex: indicates the device node using a regular expression.
Uid gid: uid and gid
Octal permissions: The octal permission bit.
Explanation of the special characters:
@ Run the command after creating the device Node
$ Run the command before deleting a device Node
* Commands run after the device node is created and before the device node is deleted
Example: Use mdev to implement automatic identification and mounting of SD cards for arm linux
1. When using busybox to create the root file system, select support for 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/sys
Mkdir/dev/pts
Mount-t devpts/dev/pts
Echo/sbin/mdev>/proc/sys/kernel/hotplug
Mdev-s
You can find these statements in the mdev manual.
3. Added responses to hot swapping events to enable automatic mounting of USB flash drives and SD cards.
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
The red part is a script. The script content can be customized according to our needs and can be mounted, detached, or other functions.
The following is a script for automatic mounting and unmounting:
/Etc/sd_card_inserting
#! /Bin/sh
Mount-t vfat/dev/mmcblk0p1/mnt/sd
/Etc/sd_card_removing
#! /Bin/sh
Sync
Umount/mnt/sd
Use mdev to create sub-directories under/dev/to place device nodes
Linux Device Model (hot swapping, mdev, and firmware)
Port Linux2.6.24.7 to botron 2410-S (including AX88796 driver and mdev Support)
How to solve the failure of automatic mounting of the USB flash disk and SD card in the Linux System of the mini2440 Development Board