创建编辑文件 /etc/udev/rules.d/99-add-usb.rules

  • 一定不要换行

    1. # U盘自动挂载
    2. 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"
    3. # U盘自动卸载
    4. 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.cnblogs.com/hellokitty2/p/9521340.html

  • https://www.jianshu.com/p/68808f566017