首先,需要在启动的时候rcS
mount -t usbfs none /proc/bus/usb
在busybox的mdev选项选择热插拔支持 rcS
echo "/sbin/stbhotplug" > /proc/sys/kernel/hotplug
mdev -s
最后,编辑stbhotplug文件
加入自动挂载函数
自动挂载函数如下:
#! /bin/sh
#
# Mount/Unmount a USB disk.
#
# Mount:
# We try to mount /dev/sda1 first, if failed, search /dev/sdb1, /dev/sdc1 ...,
# and try to mount the 1st one we found.
#
MOUNT_DIR=/mnt/usb
MOUNT_DIR1=/mnt/hd/HDD0
MOUNT_DIR2=/mnt/hd/HDD1
MOUNT_DEV=/dev/sda1
mount | grep $MOUNT_DIR
if [ "$?" = "0" ]
then
# Kill all process locked the USB disk
fuser -m -v -k -i $MOUNT_DIR
umount $MOUNT_DIR
if [ "$?" = "0" ]
then
echo USB disk at $MOUNT_DIR has been unmounted
else
echo Can not unmount $MOUNT_DIR
fi
else
mount -t vfat /dev/sda1 $MOUNT_DIR -o codepage=936,iocharset=cp936 2>/dev/null
if [ "$?" = "0" ]
then
echo USB disk $MOUNT_DEV has been mounted at $MOUNT_DIR
else
#
# Search all USB disk devices, and mount the first one
#
for MOUNT_DEV in $(fdisk -l | grep sd[b-z]1 | awk '{print $1}')
do
if [ "$?" = "0" ]
then
mount -t vfat $MOUNT_DEV $MOUNT_DIR -o codepage=936,iocharset=cp936 2>/dev/null
if [ "$?" = "0" ]
then
echo USB disk $MOUNT_DEV has been mounted at $MOUNT_DIR
exit 0
fi
fi
done
echo Can not mount $MOUNT_DEV to $MOUNT_DIR
fi
fi
exit 0
将上述内容加到stbhotplug中的usb add段落中。
补充内容
fdisk -l | grep sd[a-z]1 | awk '{print $1}' | wc -l
2
待优化改善