KERNEL!="mmcblk[0-9]p[0-9]", GOTO="sd_cards_auto_mount_end" ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="sd_cards_auto_mount_end" # 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}="sd-%k" # create the dir in /media ACTION=="add", RUN+="/bin/mkdir -p '/media/%E{dir_name}'" # Global mount options ACTION=="add", ENV{mount_options}="relatime" # Filesystem specific options ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N" ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=98,umask=002" # automount all other filesystems ACTION=="add", ENV{ID_FS_TYPE}!="ntfs", RUN+="/bin/mount -t auto -o %E{mount_options} /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}'" # exit LABEL="sd_cards_auto_mount_end"