KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end" ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end" # Do not mount devices on boot because otherwise fsck may fail ACTION=="add", PROGRAM!="/bin/grep ' / / rw[, ]' /proc/self/mountinfo", GOTO="media_by_label_auto_mount_end" # Open LUKS partition if necessary PROGRAM=="/sbin/blkid -o value -s TYPE %N", RESULT=="crypto_LUKS", ENV{crypto}="mapper/", ENV{device}="/dev/mapper/%k" ENV{crypto}=="", ENV{device}="%N" ACTION=="add", ENV{crypto}!="", ENV{mount}="%N %k " # Global mount options ACTION=="add", ENV{mount_options}="noatime" # Filesystem-specific mount options ACTION=="add", PROGRAM=="/sbin/blkid -o value -s TYPE %E{device}", RESULT=="vfat|ntfs", ENV{mount_options}="%E{mount_options},utf8,gid=100,umask=002" # Get label if present, otherwise assign one PROGRAM=="/sbin/blkid -o value -s LABEL %E{device}", ENV{dir_name}="%c" # Use basename to correctly handle labels such as ../mnt/foo PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c" ENV{dir_name}=="", ENV{dir_name}="usbhd-%k" # Mount the device ACTION=="add", ENV{dir_name}!="", RUN+="/scripts/media-mount.sh a '/dev/%E{crypto}%k' '/media/%E{dir_name}' '%E{mount_options}' '%E{mount}'" ACTION=="remove", ENV{dir_name}!="", RUN+="/scripts/media-mount.sh r '/dev/%E{crypto}%k' '/media/%E{dir_name}'" # Exit LABEL="media_by_label_auto_mount_end"