Following the question (and answer) that @arrange shows in his comment, let's create a new file
/etc/udev/rules.d/11-media-by-label-auto-mount.rules
and write into it the following content (see udev::Mount under /media; use partition label if present)
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,sync"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,uid=1000,gid=1000,umask=002"
# Mount the device
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"
# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
# Exit
LABEL="media_by_label_auto_mount_end"
I have done some little modifications with respect to that reported on the website
- added the
sync
option to ENV{mount_options}
- modified the
gid=100
option to uid=1000,gid=1000
, where the number are relative to your used-id and group-id, as returned by id -u
and id -g
The second one make you the owner of all files on the mounted partition, so no permission problem can arise. Obviously this is not the case if more than a single user should access the files, but this can be handled in other ways.
For non-windows filesystems, owner and group are metadata on the filesystem, and cannot be changed by a mount option.
The new rule is immediately active (udev uses inotify to detect new and modified rule files).
The mounted drive is not automatically opened in a file manager window, as you can see, and this is difficult to achieve, given that the mounting process is owned by root, and do not have access to your graphical login session. But the drive is on your desktop, so a simple double-click will open it.
Unfortunately I cannot get the desktop right-click unmount to work, but this is not a big problem: having the sync
option in place, you can simply unplug the device, and the udev rule take care of removing the entry from /proc/mounts
and removing the mount-point.
sync
option when mounting the partition. This is not recommended though as it dramatically increases the number of writes to the thumbdrive.sync
as default, so I don't need to do this in a terminal every time? And I'm aware that it'll dramatically increase the number of writes, still is what I want. Thanks!