美文网首页
n1刷armbian自动挂载usb设备

n1刷armbian自动挂载usb设备

作者: 崔小聪 | 来源:发表于2019-08-07 10:45 被阅读0次

    使用devmon

    apt-get install -y udevil
    # 修改默认挂载路径到/media
    sed -i 's/allowed_media_dirs\ =\ \/media\/$USER,\ \/run\/media\/$USER/allowed_media_dirs\ =\ \/media,\ \/media\/$USER,\ \/run\/media\/$USER/' /etc/udevil/udevil.conf
    systemctl start devmon@your-username.service
    systemctl enable devmon@your-username.service
    

    udev直接mount

    使用mount

    # /etc/udev/rules.d/10-usb-mount.rules
    暂无,mount测试失败
    

    或使用system-mount

    #  /etc/udev/rules.d/10-usb-mount.rules
    KERNEL!="sd*", GOTO="exit"
    SUBSYSTEM!="block", GOTO="exit"
    
    IMPORT{builtin}="blkid"
    ENV{ID_FS_LABEL}=="EFI|BOOT|Recovery|RECOVERY|SETTINGS|boot|root0|share0", GOTO="exit"
    
    ENV{DEVTYPE}!="partition", GOTO="exit"
    ENV{ID_FS_USAGE}!="filesystem", GOTO="exit"
    
    ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
    ENV{ID_FS_LABEL}=="", ENV{dir_name}="Untitled-%k"
    ACTION=="add", PROGRAM="/bin/sh -c '/bin/grep -E ^/dev/%k\  /proc/mounts || true'", RESULT=="", RUN+="/usr/bin/systemd-mount --no-block --automount=yes --collect /dev/%k /media/%E{dir_name}"
    ACTION=="remove", ENV{dir_name}!="", RUN+="/usr/bin/systemd-mount --umount /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
    GOTO="exit"
    
    LABEL="exit"
    
    #执行命令重新加载配置
    udevadm control --reload
    

    udiskie配合udisk2

    # 依赖python
    apt-get install -y  udiskie udisk2
    
    # add to /etc/rc.local
    ...
    udiskie &
    ...
    

    udev配合udisk2

    安装udisk2

    apt-get install -y udisk2
    

    配置udisk挂载到/media/目录下
    /etc/udev/rules.d/99-udisks2.rules

    # UDISKS_FILESYSTEM_SHARED
    # ==1: mount filesystem to a shared directory (/media/VolumeName)
    # ==0: mount filesystem to a private directory (/media/$USER/VolumeName)
    # See udisks(8)
    ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{UDISKS_FILESYSTEM_SHARED}="1"
    

    /etc/udev/rules.d/99-udisks2-mount.rules

    # check for blockdevices, /dev/sd*, /dev/sr* and /dev/mmc*
    SUBSYSTEM!="block", KERNEL!="sd*|sr*|mmc*", GOTO="exit"
    
    # check for special partitions we dont want mount
    IMPORT{builtin}="blkid"
    ENV{ID_FS_LABEL}=="EFI|BOOT|Recovery|RECOVERY|SETTINGS|boot|root0|share0", GOTO="exit"
    
    # /dev/sd* and /dev/mmc* ith partitions/disk and filesystems only and /dev/sr* disks only
    KERNEL=="sd*|mmc*", ENV{DEVTYPE}=="partition|disk", ENV{ID_FS_USAGE}=="filesystem", GOTO="harddisk"
    GOTO="exit"
    
    # mount or umount for hdds
    LABEL="harddisk"
    ACTION=="add", RUN+="/usr/bin/sh -c '/etc/udev/rules.d/99-udisks2-mount.sh %k'"
    GOTO="exit"
    
    # Exit
    LABEL="exit"
    

    /etc/udev/rules.d/99-udisks2-mount.sh

    #!/bin/sh
    nohup /usr/bin/udisksctl mount --block-device /dev/$1 --no-user-interaction >/dev/null 2>&1 &
    

    相关文章

      网友评论

          本文标题:n1刷armbian自动挂载usb设备

          本文链接:https://www.haomeiwen.com/subject/snpndctx.html