usb多分区自动挂载实现方式1(脚本方式,非完美)

首先,需要在启动的时候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

待优化改善

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值