-
Notifications
You must be signed in to change notification settings - Fork 7
/
10-flash-mounts.rules
75 lines (49 loc) · 2.36 KB
/
10-flash-mounts.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! /bin/sh
#######################################
# USB Flash Drives automounting #
#######################################
# start at sdb to ignore the system hard drive
KERNEL!="sd[b-z]*", GOTO="exit"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="exit"
# import some useful filesystem info as variables
IMPORT{program}="/sbin/blkid -o udev -p %N"
# get the label if present, otherwise assign one based on device/partition
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="flash_drive_%k"
# create the dir in /media and symlink it to /mnt
ACTION=="add", RUN+="/bin/mkdir -p '/media/%E{dir_name}'"
# global mount options
#ACTION=="add", ENV{mount_options}="relatime"
# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat)
########
# vfat #
########
# vfat specific mount options
ACTION=="add", ENV{mount_options_vfat}="gid=100,dmask=000,fmask=111,utf8,flush,rw,noatime,users"
# add device to /etc/fstab
ACTION=="add", ENV{ID_FS_TYPE}=="vfat", RUN+="/bin/sed -i '$a\/dev/%k /media/%E{dir_name} vfat %E{mount_options_vfat} 0 0' /etc/fstab"
# mount device
ACTION=="add", ENV{ID_FS_TYPE}=="vfat", RUN+="/bin/mount -t auto -o %E{mount_options_vfat} /dev/%k '/media/%E{dir_name}'"
########
# ntfs #
########
# ntfs specific mount options
ACTION=="add", ENV{mount_options_ntfs}="gid=100,dmask=000,fmask=111,utf8,flush,rw,noatime,users"
# add device to /etc/fstab
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/sed -i '$a\/dev/%k /media/%E{dir_name} ntfs-3g %E{mount_options_ntfs} 0 0' /etc/fstab"
# mount device
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options_ntfs} /dev/%k '/media/%E{dir_name}'"
#####################
# other filesystems #
#####################
# ntfs specific mount options
ACTION=="add", ENV{mount_options_other}="gid=100,dmask=000,fmask=111,utf8,flush,rw,noatime,users"
# automount all other filesystems
ACTION=="add", ENV{ID_FS_TYPE}!="(ntfs|vfat)", RUN+="/bin/mount -t auto -o %E{mount_options_other} /dev/%k '/media/%E{dir_name}'"
#################################
# clean up after device removal #
#################################
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'", RUN+="/bin/rmdir '/media/%E{dir_name}'"
ACTION=="remove", ENV{ID_FS_TYPE}!="", RUN+="/bin/sed -i '/\/dev\/%k /d' /etc/fstab"
# exit
LABEL="exit"