I am trying to automatically mount all readable internal and external drives on boot and on hot-plug if they are not already mounted, preferably as a non-root user.
I cannot use fstab
to do this because the drives change too frequently, and udisks2
does not appear to automount devices when the user is not actually logged in locally.
I found a udev
ruleset to accomplish something like this here, but I have read that mounting via udev
rules is a VERY bad idea and doesn't work anyway with systemd.
What would be the proper way to do this on a headless Debian (jessie) system?
Note: I've created this udev
rule, but I'm not sure if it's the right way to go about this:
KERNEL!="sd[a-z][0-9]", GOTO="automount_disks_END"
# Check if it is a mountable disk, skip if not
IMPORT{program}="/bin/udevadm info --query=property --name=%k"
ENV{ID_TYPE}!="disk", GOTO="automount_disks_END"
ENV{ID_FS_TYPE}=="", GOTO="automount_disks_END"
# Set mount options
ACTION=="add", ENV{mount_options}="nosuid,nodev"
ACTION=="add", ENV{ID_BUS}=="ata", ENV{mount_options}="$env{mount_options},rw,dmask=022,fmask=033"
ACTION=="add", ENV{ID_BUS}=="usb", ENV{mount_options}="$env{mount_options},ro,noatime,dmask=222,fmask=333"
# Mount the disk
ACTION=="add", RUN+="/bin/su - user -c \"/usr/bin/udisksctl mount --block-device /dev/%k --options $env{mount_options} --no-user-interaction\""
# Clean up after removal
ACTION=="remove", RUN+="/bin/su - user -c \"/usr/bin/udisksctl unmount --force --block-device /dev/%k --no-user-interaction\""
# Exit
LABEL="automount_disks_END"
This rule doesn't solve the authorization check issue for users who are not logged in locally, either.
CLARIFICATION:
What I'm basically looking for is the functionality of usbmount
that works for ATA devices and doesn't clutter up the /media
directory with unused folders, in short.