Transfer from http://www.cnblogs.com/OpenShiFt/p/6008562.html
Mdev Description
Mdev is a simplified version of Udev from BusyBox, suitable for embedded applications. It has the characteristics of simple use. Its role is to automatically generate the required node files for the driver when the system boots up and hot-swappable or dynamically loads the driver . When building an embedded Linux root file system based on BusyBox, the optimal choice is to use it. The mdev principle Mdev The use of hotplug mechanism to decide what kind of device files to create without parameters. The MDEV-S program uses this information to create device nodes under/dev by scanning all of the class device catalogs in the/sys/class and/sys/block. Mdev Use
Mdev in the use of the process is divided into two parts, because the system starts Mdev need to base on the information in the/sys directory to generate device nodes, so before using the system needs some configuration. The Mdev hotplug mechanism to create a device node is based on the/etc/mdev.conf file to generate the device node. System Settings
The following actions need to be performed before the system executes mdev-s:
Configuring the Kernel
Make Menuconfig General
setup---->
Configure-Kernel features (for small systems)---->
[*] Lo Ad all symbols to Debugging/ksymoops
[*] Include all symbols in kallsyms
[*] Support for hot-pluggable devices
[*] Enable support for PRINTK
Configure BusyBox
Make Menuconfig
Linux System Utilities---->
[*] Mdev
[*] support/etc/mdev.conf
[*] Support Subdirs /symlinks
[*] Support regular expressions substitutions when renaming device
[*] Support command execution at de Vice Addition/removal
[*] Support loading of firmwares
When the system starts
Vi /etc/init.d/rcs
mount-t tmpfs tmpfs/dev
mkdir/dev/pts
mount-t devpts devpts/dev/pts
MOUNT-T proc Proc/proc
mount-t sysfs sysfs/sys echo/sbin/mdev>/proc/sys/kernel/hotplug//
initiate hot-swap events;
Mdev–s
First mount the/dev,/dev/pts,/proc, and/sys file systems, Mdev need to use these file systems. Then tell the system to use Mdev to process when the device is hot-swappable. Finally, the mdev-s is executed to scan the system for devices and drivers. configuration file/etc/mdev.conf
The hotplug in the system is generated by the mdev.conf file to generate the device node, the configuration file format is as follows:
Basic format
<device regex> <uid>:<gid> <octal permissions>
<device regex> : Device name , support for regular expressions such as hd[a-z][0-9]*
<uid>:<gid> : User ID and Group ID
<octal permissions> : Device properties in octal representation
Execute script format
<device regex> <uid>:<gid> <octal permissions> [=|>path] [@|$|*]
[=|> Path]: This option can change the name and path of the device node, such as:
<1> =/driver: You can move the device node to the driver directory
<2> =newname: You can change the device node to NewName name
<3> >/driver/newname: You can create a link to a device node in the/driver directory and name it newname
[@|$|*]: This option, when the device is successfully matched, executes the instruction, which can be a script written by itself. The preceding symbol has the following meanings: <1>@: Execute <2>$ After the device node is created: Perform <3>* before the device node is
deleted
: Execute
before the device node is created and deleted In addition, two system variables $mdev and $action are set after the Mdev successfully matches the device. Where $mdev is used to store the matching device name, $ACTION used to store the device's plug-in state whose value is add and remove. These two variables can be used in scripts.
Script Instance
mdev.conf # system All-writable devices full 0:0 0666 null 0:0 0666 ptmx 0:0 0666 RA Ndom 0:0 0666 tty 0:0 0666 Zero 0:0 0666 # console devices tty[0-9]* 0:5 0660 vc/[0-9]* 0:5 0660 # serial Port D Evices s3c2410_serial0 0:5 0666 =ttysac0 s3c2410_serial1 0:5 0666 =ttysac1 s3c2410_serial2 0:5 0666 =ttySAC2 s3c2
410_serial3 0:5 0666 =ttysac3 # Loop devices loop[0-9]* 0:0 0660 =loop/# i²c devices i2c-0 0:0 0666 =i2c/0 I2c-1 0:0 0666 =I2C/1 # Frame buffer devices fb[0-9] 0:0 0666 # Input devices mice 0:0 0660 =input/mouse.* 0:0 0660 =input/event.* 0:0 0660 =input/ts.* 0:0 0660 =input/# RTC Devices rtc0 0:0 0644 >RTC RTC [1-9] 0:0 0644 # misc Devices mmcblk0p1 0:0 0600 =sdcard */bin/hotplug.sh mmcblk0 0:0 0600 =mmcblk0 */BIN/HOTP lug.sh sda1 0:0 0600 =udisk */bin/hotplug.sh
/bin/hotplug.sh
#!/bin/sh case
$MDEV in
sda1)
devname=udisk
mountpoint=/udisk
;;
MMCBLK0P1)
Devname=sdcard
mountpoint=/sdcard
;;
MMCBLK0)
devname=mmcblk0
mountpoint=/sdcard
;;
*)
exit 0
;;
ESAC case
$ACTION in
Remove)
/bin/umount $MOUNTPOINT | | true
rmdir $MOUNTPOINT >/dev/null 2> &1 | | True
;;
*)
/bin/mkdir $MOUNTPOINT >/dev/null 2>&1 | | true
/bin/mount-o sync-o noatime-o nodiratime-t vfat /dev/$DEVNAME $MOUNTPOINT >/dev/null 2>&1 | | True
;;
Esac
Exit 0