udev rules sample

touch /etc/udev/rules.d/51-blk-dev.rules

ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /mnt/%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount /dev/%k /mnt/%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/ntfs-3g /dev/%k /mnt/%k", OPTI
 
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/sync"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /mnt/%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rm -rf /mnt/%k", OPTI
 
ACTION=="add", KERNEL=="mmcblk[0-9]p[0-9]", RUN+="/bin/mkdir -p /mnt/%k"
ACTION=="add", KERNEL=="mmcblk[0-9]p[0-9]", RUN+="/bin/mount /dev/%k /mnt/%k"
ACTION=="add", KERNEL=="mmcblk[0-9]p[0-9]", RUN+="/bin/ntfs-3g /dev/%k /mnt/%k", OPTI
 
ACTION=="remove", KERNEL=="mmcblk[0-9]p[0-9]", RUN+="/bin/sync"
ACTION=="remove", KERNEL=="mmcblk[0-9]p[0-9]", RUN+="/bin/umount -l /mnt/%k"
ACTION=="remove", KERNEL=="mmcblk[0-9]p[0-9]", RUN+="/bin/rm -rf /mnt/%k", OPTI
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"  
# Import FS infos  
IMPORT{program}="/sbin/blkid -o udev -p %N"  
# Get a label if present, otherwise specify one  
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"  
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"  
# Global mount options  
ACTION=="add", ENV{mount_options}="relatime"  
# Filesystem-specific mount options  
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"  
# Mount the device  
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"  
# Clean up after removal  
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"  
# Exit  
LABEL="media_by_label_auto_mount_end"

https://www.andreafortuna.org/2019/06/26/automount-usb-devices-on-linux-using-udev-and-systemd/

http://www.reactivated.net/writing_udev_rules.html

https://github.com/raamsri/automount-usb/blob/master/usb-mount.sh

https://github.com/raamsri/automount-usb

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值