Linux文件系统u盘自动挂载(修改)

时间:2021-01-16 05:54:31

系统环境:Loongson-1B开发板(mips32指令集)、busybox1.19.2、Linux2.6.21、文件系统配置参照本博客文章《移植Busybox与构建根文件系统》
编译环境:ubuntu10.04、gcc-3.4.6-2f
 
u盘自动挂载功能实现步骤如下:
1、配置内核
a)配置内核支持热插拔:
#cd linux.2.6.21
#vi .config
CONFIG_KALLSYMS=y
CONFIG_HOTPLUG=y  //确保此项为y
CONFIG_PRINTK=y 
CONFIG_NET=y  //确保此项为y
确保以上两项均设置为y,否则/proc/sys/kernel/目录下不会出现huotplug文件。
b)配置内核支持
#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
 
2、配置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
3、添加对热插拔事件响应,实现u盘自动挂载与卸载
a) 创建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
 
b) 创建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
 
c) 创建udisk_remove文件
#vi /etc
umount -l /mnt/usb
rm /mnt/usb -rf
 
d)修改脚本权限
#chmod 755 /etc/hotplug/*
配置文件系统u盘自动挂载功能完成。