Skip to content

Instantly share code, notes, and snippets.

@v1-wizard
Last active January 28, 2019 13:43
Show Gist options
  • Save v1-wizard/69e50067b6d24b02701309fcb5040335 to your computer and use it in GitHub Desktop.
Save v1-wizard/69e50067b6d24b02701309fcb5040335 to your computer and use it in GitHub Desktop.
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},uid=1000,gid=1000"
# Mount the device
ACTION=="add",RUN+="/bin/mkdir -p /tmp/media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /tmp/media/%E{dir_name}"
# Clean up after removal
ACTION=="remove",ENV{dir_name}!="", RUN+="/bin/umount -l /tmp/media/%E{dir_name}", RUN+="/bin/rmdir /tmp/media/%E{dir_name}"
# Exit
LABEL="media_by_label_auto_mount_end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment