创建编辑文件 /etc/udev/rules.d/99-add-usb.rules
一定不要换行
# U盘自动挂载ACTION=="add", KERNEL=="sd[b-z][1-9]", RUN+="/bin/sh /home/peach/log.sh %k", RUN{program}+="/usr/bin/systemd-mount --no-block --collect /dev/%k /mnt/%k"# U盘自动卸载ACTION=="remove", KERNEL=="sd[b-z][1-9]", RUN+="/bin/sh /home/peach/log.sh %p", RUN{program}+="/usr/bin/systemd-umount --no-block --collect /dev/%k /mnt/%k"
参考
- https://www.jianshu.com/p/68808f566017
