通过mdev实现Linux下U盘自动挂载(笔记)

开发板:exynos4412(super4412) 

内核:Linux 3.0.15

 
通过mdev工具实现u盘自动挂载步骤如下:
一、配置内核

配置内核支持USB大容量存储
#make menuconfig
选择Device Drivers --> 
             USB support -->
                   <*> Support for Host-side USB
                   <*> OHIC HCD support
                   <*> UHCI HCD (most Intel and VIA) support
                   <*> SL811HS HCD support
                   <*> USB Mass Storage support

开启内核热插拔,在内核根目录下

#vim .config
CONFIG_KALLSYMS=y
CONFIG_HOTPLUG=y  
CONFIG_PRINTK=y  
CONFIG_NET=y  


二、配置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 device addition/removal
             [*]     Support loading of firmwares

三、添加对热插拔事件响应,实现u盘自动挂载与卸载
1) 创建mdev.conf文件:
#vi /etc/mdev.conf
写入:
sd[a-z][0-9]  0:0  666  @/etc/hotplug/udisk_insert
sd[a-z]  0:0  666 $/etc/hotplug/udisk_remove
 
2) 创建udisk_insert文件
#mkdir -p /etc/hotplug
#vi /etc/hotplug/udisk_insert
写入:
#!/bin/sh
mkdir -p /mnt/usb
mount /dev/sd[a-z][0-9] /mnt/usb
 

3) 创建udisk_remove文件

#vi /etc/hotplug/udisk_insert

写入:

#!/bin/sh

umount -l /mnt/usb
rm /mnt/usb -rf
 
4)修改脚本权限
#chmod 755 /etc/hotplug/*


OK,配置完毕,插上u盘试试吧!

你可能感兴趣的:(通过mdev实现Linux下U盘自动挂载(笔记))