Ads 468x60px

##EasyReadMore##

18 10月, 2017

Automatically mount USB

把下面內容存成 10-automount.rules 放到  /etc/udev/rules.d

然後執行 udevadm control --reload-rules

# Start at sdb to avoid system harddrive.
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"

# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"

# Create a label
ENV{dir_name}="usbhd-%k"

# Global mount options
ACTION=="add", ENV{mount_options}="defaults,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"

Warning:

copy /usr/lib/systemd/system/systemd-udevd.service to /etc/systemd/system/systemd-udevd.service and replace MountFlags=slave to MountFlags=shared

Refer:

Auto-mounting USB storage with udev » Axllent.org - https://goo.gl/oiRgjy

udev (简体中文) - ArchWiki - https://goo.gl/WZkhUq

Automatically mount USB storages when plugged - https://goo.gl/hhegWA

0 意見:

張貼留言

 
Blogger Templates