udev 和mdev 是两个使用uevent 机制处理热插拔问题的用户空间程序,两者的实现机理不同。udev 是基于netlink 机制的,它在系统启动时运行了一个deamon 程序udevd,通过监听内核发送的uevent 来执行相应的热拔插动作,包括创建/删除设备节点,加载/卸载驱动模块等等。mdev 是基于uevent_helper 机制的,它在系统启动时修改了内核中的uevnet_helper 变量(通过写/proc/sys/kernel/hotplug),值为“/sbin/mdev”。这样内核产生uevent 时会调用uevent_helper 所指的用户级程序,也就是mdev,来执行相应的热拔插动作。udev 使用的netlink 机制在有大量uevent 的场合效率高,适合用在PC 机上;而mdev 使用的uevent_helper 机制实现简单,适合用在嵌入式系统中。另外要说明的一点是,uevent_helper 的初始值在内核编译时时可配置的,默认值为/sbin/hotplug。如果想修改它的值,写/proc/sys/kernel/hotplug 文件就可以了,例如:
echo “/sbin/mdev” > /proc/sys/kernel/hotplug
补充一点:如果使用的是udevd,那么uevent_helper变量应为空,即
echo “ ” > /proc/sys/kernel/hotplug
refer toroot@freescale /etc/rc.d$ cat rcS
#!/bin/sh
# minimal startup script, will work with msh (this is best available in
# MMUless format).
# load the configuration information
. /etc/rc.d/rc.conf //服务配置文件
mode=${1:-start}
if [ $mode = "start" ]
then
services=$cfg_services
else
services=$cfg_services_r
fi
cfg_services=${2:-$services}
echo "cfg:"
echo $cfg_services
# run the configured sequence
for i in $cfg_services
do
if [ -x /etc/rc.d/init.d/$i ]
then
/etc/rc.d/init.d/$i $mode //调用各个服务
fi
done
if [ $# -ge 2 ]
then
exit 0
fi
# show all kernel log messages
#echo 8 > /proc/sys/kernel/printk
# run rc.local if present and executable
if [ -x /etc/rc.d/rc.local ]
then
/etc/rc.d/rc.local $mode
fi
root@freescale /etc/rc.d$ cat rc.conf
all_services="mount-proc-sys mdev udev hostname devfsd depmod modules filesystems syslog network inetd portmap dropbear sshd boa smb dhcpd settime fslgnome watchdog bluetooth gtk2 pango"
all_services_r="pango gtk2 bluetooth watchdog fslgnome settime dhcpd smb boa sshd dropbear portmap inetd network syslog filesystems modules depmod devfsd hostname udev mdev mount-proc-sys"
cfg_services="mount-proc-sys hostname depmod modules filesystems inetd "
cfg_services_r=" inetd filesystems modules depmod hostname mount-proc-sys"
export HOSTNAME="freescale"
export NTP_SERVER=""
export MODLIST=""
export RAMDIRS="/tmp /var"
export TMPFS="tmpfs"
export TMPFS_SIZE="512k"
export READONLY_FS=""
export INETD_ARGS=""
export BOA_ARGS=""
export SMBD_ARGS=""
export NMBD_ARGS=""
export DHCP_ARG=""
export DEPLOYMENT_STYLE="JFFS2"
export SYSCFG_DHCPC_CMD="udhcpc -b -i "
export DROPBEAR_ARGS=""
root@freescale /etc/rc.d/init.d$ cat udev
#!/bin/sh
PATH=$PATH:/sbin:/bin
if [ ! -x /sbin/udevd ]
then
exit 0
fi
case "$1" in
start)
echo "" > /proc/sys/kernel/hotplug
mount -n -o mode=0755 -t tmpfs tmpfs /dev
# Create static device nodes in /dev
mknod /dev/console c 5 1
mknod /dev/null c 1 3
echo "Starting the hotplug events dispatcher udevd"
udevd --daemon
echo "Synthesizing initial hotplug events"
udevtrigger
udevsettle --timeout=300
mkdir /dev/pts
mount -n -t devpts devpts /dev/pts
mkdir /dev/shm
;;
stop)
;;
reload)
udevcontrol --reload_rules
;;
*)
echo "Usage: /etc/rc.d/init.d/udev {start|stop|reload}"
echo
exit 1
;;
esac
exit 0
http://blog.csdn.net/hugerat/article/details/3437099