我已经能够在以前的 Raspbian 版本上自动挂载,但规则不是在拉伸时执行“挂载”。
规则:
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+="/home/pi/11-media-by-label.sh /bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"
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"
注意它运行了ACTION=="add", RUN+="/home/pi/11-media-by-label.sh /bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"
其中包含:
`pi@tv:~ $ cat /home/pi/11-media-by-label.sh
#!/bin/sh
echo "11-media-by-label-auto-mount.rules: $@" >> /tmp/11-media-by-label-auto-mount.rules.log
` 它运行并产生:
pi@tv:~ $ cat /tmp/11-media-by-label-auto-mount.rules.log 11-media-by-label-auto-mount.rules: /bin/mount -o relatime,utf8,gid=100,umask=002 /dev/sda1 /media/USB_DISK
前一行的“mount”操作看起来具有正确的格式,因为当我将其手动粘贴到终端窗口时:
pi@tv:~ $ sudo /bin/mount -o relatime,utf8,gid=100,umask=002 /dev/sda1 /media/USB_DISK
它工作得很好。
之后sudo udevadm control --log-priority=info
,系统日志包含:
/var/log/syslog:Jun 10 17:34:54 tv systemd-udevd[121]: Process '/bin/mount -o relatime,utf8,gid=100,umask=002 /dev/sda1 /media/USB_DISK' failed with exit code 32.
这只是解决“安装失败”。
(我还使用 mkdir -p 得到退出代码 1,这看起来像是权限问题,但日志文件是由 root 创建的,所以我知道它确实是 root。
有任何想法吗?