日期:2014-05-16  浏览次数:20707 次

mdev u盘不能自动挂载和卸载
使用busybox提供的mdev进行设备节点和热拔插事件的管理
当把U盘插入时不能自动挂载,相关脚本如下:
JScript code

#mdev.conf
sd[a-z]      0:0 0660        @/etc/mdev/udisk_insert                        
sd[a-z]      0:0 0660        $/etc/mdev/udisk_remove                        
sdb[0-9]  0:6  660
hda[0-9]  0:6  660



fstab
JScript code

# /etc/fstab: static file system information.
#
# <file system> <mount pt>     <type>    <options>         <dump> <pass>
/dev/root /   ext2      rw,noauto  0  1
proc   /proc  proc     defaults    0  0
none   /tmp   ramfs    defaults    0  0
mdev   /dev   ramfs    defaults    0  0
sysfs  /sys   sysfs    defaults    0  0
tmpfs  /var   tmpfs    defaults    0  0
tmpfs  /tmp   tmpfs    defaults    0  0
tmpfs  /dev   tmpfs    defaults    0  0


启动脚本rcS为
C/C++ code

mount -t proc proc /proc
mount -t tmpfs mdev /dev
mount -t sysfs sysfs /sys
mkdir /dev/pts
mount -t devpts devpts /dev/pts
mount -a
/bin/echo /sbin/mdev >/proc/sys/kernel/hotplug 
mdev -s 



Udisk自动挂载脚本和卸载脚分别为:
#!/bin/sh

echo "this is $MDEV"
if [ -d /sys/block/$MDEV ] ; then
echo mount udisk to /mnt/udisk
mkdir -p /mnt/udisk
mount /dev/$MDEV /mnt/udisk -t vfat -o utf8=1
if [ -f /mnt/udisk ];then
echo "mount udisk successfully"
fi

fi

#!/bin/sh

echo remove udisk
umount -t /mnt/udisk
rm -rf /mnt/udisk
echo "remove your udisk safely!"



------解决方案--------------------
C/C++ code

#!/bin/sh

echo remove udisk
#umount -t /mnt/udisk
umount /mnt/udisk
#rm -rf /mnt/udisk
echo "remove your udisk safely!"