Linux下/etc/mdev.conf学习

环境变量 ${MDEV} 为设备名 ;

环境变量${ACTION} 为设备状态"remove"、"add"。


/etc/mdev.conf配置:

<device regex> <uid>:<gid> <octal permissions> [<@|$|*> <command>]

特殊字符的意义如下:
    @ 在创建设备节点后运行命令。
    $ 在删除设备节点前运行命令。
    * 在创建设备节点后和删除设备节点前都运行命令。

command对应的shell一般位于/etc/mdev目录。


 例如:mmcblk[0-9]*p[0-9]* 0:6     660 */etc/mdev/automountsdcard.sh

automountsdcard.sh如下:

#! /bin/sh

destdir=/media/card

umount_partition()
{
    umount "${destdir}";
}

mount_partition()
{
    if ! mount -t auto "/dev/$1" "${destdir}"; then
        # failed to mount
        exit 1
    fi
}

case "${ACTION}" in
add|"")
    umount_partition ${MDEV}
    mount_partition ${MDEV}
    ;;
remove)
    umount_partition ${MDEV}
    ;;
esac

更详细内容请参考:https://blog.csdn.net/mybelief321/article/details/10048409

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章