-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-media-by-label-auto-mount.rules
25 lines (25 loc) · 1.15 KB
/
11-media-by-label-auto-mount.rules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Credit for Axllent.org
# See: https://www.axllent.org/docs/view/auto-mounting-usb-storage/
#
# Updated: 5/7/2017
# Rev.: 1.01
# By: Robert S. Rau
# Changes: Changed directory from /media to /media/pi since a fresh boot with USB FLASH drive installed ended up at /media/pi with our without this rule.
#
#
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+="/bin/mkdir -p /media/pi/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/pi/%E{dir_name}"
# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/pi/%E{dir_name}", RUN+="/bin/rmdir /media/pi/%E{dir_name}"
# Exit
LABEL="media_by_label_auto_mount_end"