udevの設定 USBオートマウント

なんか,どっかから拾ってきたファイルをそのまま利用していたみたい.

KERNEL=="sd[b-z]", NAME="%k", SYMLINK+="usb-%k", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[b-z][0-9]", SYMLINK+="usb-%k", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mkdir -p /media/usb-%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/ln -s /media/usb-%k /mnt/usb-%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 /dev/%k /media/usb-%k", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /media/usb-%k", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rm -f /mnt/usb-%k"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/umount -l /media/usb-%k"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rmdir /media/usb-%k", OPTIONS="last_rule"

なんか色々変じゃないか?

Archlinuxのwiki

udev – ArchWiki

を参考にして以下のように修正

/etc/udev/rules.d/11-media-auto-mount.rules

KERNEL!="sd[b-z][0-9]", GOTO="media_auto_mount_end"
ACTION=="add", RUN+="/bin/mkdir -p /media/usb-%k"
# Global mount options
ACTION=="add", ENV{mount_options}="relatime,users"
# Filesystem specific options
ACTION=="add", PROGRAM=="/lib/initcpio/udev/vol_id -t %N", RESULT=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"
ACTION=="add", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/usb-%k"
ACTION=="remove", RUN+="/bin/umount -l /media/usb-%k", RUN+="/bin/rmdir /media/usb-%k"
LABEL="media_auto_mount_end"