#/etc/udev/rules.d/11-media-by-label-auto-mount.rules 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 already mounted somewhere else to avoid entries for all your local partitions in /media ACTION=="add", PROGRAM=="/bin/grep -q ' /dev/%k ' /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}!="", PROGRAM=="/usr/bin/xterm -display :0.0 -e 'echo Password for /dev/%k; /sbin/cryptsetup luksOpen %N %k'" ACTION=="add", ENV{crypto}!="", TEST!="/dev/mapper/%k", GOTO="media_by_label_auto_mount_end" # 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" # Das Verzeichnis per default auf /media/easyvdr01/ setzen ACTION=="add", ENV{mount_path}="/media/easyvdr01/" #wenn Label = "Archiv" dann Ordner ueberschreiben ACTION=="add", ENV{dir_name}=="Aufnahmearchiv" ENV{mount_path}="/media/easyvdr01/video0" # Mount the device ACTION=="add", ENV{dir_name}!="", RUN+="/bin/mkdir -p '%E{mount_path}%E{dir_name}'", RUN+="/bin/mount -o %E{mount_options} /dev/%E{crypto}%k '%E{mount_path}%E{dir_name}'" # Clean up after removal ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '%E{mount_path}%E{dir_name}'" ACTION=="remove", ENV{crypto}!="", RUN+="/sbin/cryptsetup luksClose %k" #ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/rmdir '%E{mount_path}%E{dir_name}'" # Exit LABEL="media_by_label_auto_mount_end"