Skip to content

Instantly share code, notes, and snippets.

@dimitrov-adrian
Last active September 18, 2017 10:15
Show Gist options
  • Save dimitrov-adrian/6e4cfa527d2dac5244b9848f878a0a60 to your computer and use it in GitHub Desktop.
Save dimitrov-adrian/6e4cfa527d2dac5244b9848f878a0a60 to your computer and use it in GitHub Desktop.
udev rules file that automatically mount usb devices on /media/upnp/<device>
# /etc/udev/rules.d/10-usb.rules
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"
IMPORT{program}="/sbin/blkid -o udev -p %N"
ENV{ID_FS_LABEL}!="", ENV{dir_name}="/media/upnp/%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="/media/upnp/usbhd-%k"
ACTION=="remove", ENV{dir_name}!="", RUN+="/usr/bin/udisksctl unmount -b /dev/%k"
ACTION=="change|add", ENV{mount_options}=""
#ACTION=="change|add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="-o gid=100"
ACTION=="change|add", RUN+="/usr/bin/udisksctl mount $env{mount_options} -b /dev/%k"
#ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l %E{dir_name}", RUN+="/bin/rmdir %E{dir_name}"
#ACTION=="change", ENV{dir_name}!="", RUN+="/bin/umount -l %E{dir_name}", RUN+="/bin/rmdir %E{dir_name}"
#ACTION=="add|change", ENV{mount_options}=""
#ACTION=="add|change", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="-o gid=100"
#ACTION=="add|change", RUN+="/bin/mkdir -p %E{dir_name}", RUN+="/bin/mount $env{mount_options} /dev/%k %E{dir_name}"
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