linux SD卡自动挂载

参考
http://blog.sina.com.cn/s/blog_5f8665e701016le6.html
http://blog.chinaunix.net/uid-20620288-id-3180843.html

环境:内核2.6.35 busybox-1.15.2

(1)busybox配置mdev
Linux System Utilities->
   [*] mdev                                                                         
   [*]   Support /etc/mdev.conf                                                        
   [*]     Support subdirs/symlinks                                                       
   [*]       Support regular expressions substitutions when renaming device              
   [*]     Support command execution at device addition/       | |
   [*]   Support loading of firmwares
   
(2)支持VFAT文件系统

    File systems ->
      DOS/FAT/NT Filesystems  --->
         <*> MSDOS fs support                                                             
         <*> VFAT (Windows-95) fs support                                                 
            (437) Default codepage for             
            (iso8859-1) Default iocharset for FAT
    
     Native language support  --->
       <*>   Codepage 437 (United States, Canada)
       <*>   NLS ISO 8859-1  (Latin 1; Western European Languages)
(3)SD驱动支持
    <*> MMC/SD/SDIO card support  --->  
    
(4)支持热插拔
    在以下文件添加内容
  Vim /etc/init.d/rcS
    #!/bin/sh    
    /bin/mount -t proc none /proc
    /bin/mount -t sysfs sysfs /sys
    /bin/echo > /dev/mdev.seq
    /bin/echo /sbin/mdev > /proc/sys/kernel/hotplug
    
 Vim /etc/mdev.conf
    mmcblk([0-9]+)p([0-9]+) 0:0 660 */sbin/hotplug.sh $MDEV
    mmcblk([0-9]+)          0:0 660 */sbin/hotplug.sh $MDEV
    sd([a-z]+)([0-9]+)      0:0 660 */sbin/hotplug.sh $MDEV
    sd([a-z]+)              0:0 660 */sbin/hotplug.sh $MDEV
    
 Vim /sbin/hotplug.sh
    #! /bin/sh
    echo "lqj auto mount sd"
    if [ "$1" == "" ]; then
        echo "parameter is none" > /tmp/error.txt
        exit 1
    fi

    MNT=$1
    if echo "$1" | grep mmcblk; then
        if echo "$1" | grep p[25]; then
            MNT=sdcard2
        else
            MNT=sdcard
        fi
    else
        if echo "$1" | grep sd; then
            if echo "$1" | grep [25]; then
                MNT=nandcard2
            else
                MNT=nandcard
            fi
        fi
    fi

    mounted=`mount | grep $1 | wc -l`
    #echo "par=$1,mounted=$mounted,MNT=$MNT" > /dev/console

    # mounted, assume we umount
    if [ $mounted -ge 1 ]; then
        echo "R/mnt/$1" >> /tmp/usbmnt.log
        echo "R/mnt/$1" > /tmp/fifo.1
        if ! umount -l "/mnt/$1"; then
            exit 1
        else
            rm -f "/mnt/$MNT"
            echo "[Umount FS]: /dev/$1 -X-> /mnt/$MNT" > /dev/console
        fi

        if ! rmdir "/mnt/$1"; then
            exit 1
        fi
    # not mounted, lets mount under /mnt
    else
        if ! mkdir -p "/mnt/$1"; then
            exit 1
        fi

    #try jffs2 first
        if ! mount -t jffs2 "/dev/$1" "/mnt/$1"; then
    #try vfat
            if ! mount -t vfat -o noatime,shortname=mixed,utf8 "/dev/$1" "/mnt/$1"; then
    # failed to mount, clean up mountpoint
                if ! rmdir "/mnt/$1"; then
                    exit 1
                fi
                exit 1
            else
                ln -s /mnt/$1 /mnt/$MNT
                echo "[Mount VFAT]: /dev/$1 --> /mnt/$MNT" > /dev/console
                echo "A/mnt/$1" >> /tmp/usbmnt.log
                echo "A/mnt/$1" > /tmp/fifo.1
            fi
        else
            echo "[Mount JFFS2]: /dev/$1 --> /mnt/$MNT" > /dev/console
            echo "A/mnt/$1" >> /tmp/usbmnt.log
            echo "A/mnt/$1" > /tmp/fifo.1
        fi
    fi

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值