I am in search of a decent way of having removables like usb-sticks, cameras or CD/DVDs to be automounted. I do _not_ want any solution that demands graphical apps. I want something that works on a very basic system without X.
For some years i have used the following udev-rule (in Slack and Arch) that mount USB-storage devices in a folder using the partition label if present. Due to some recent change it got even uglier and nowadays i let rc.local mv it in place so it does not automunt all my HD partitions under /media (i actually deleted, by mistake, most of the root partition of an old backup version of Slack that i had laying around when the change occured), and of course rm it on shutdown.
I feel it all is a bit of an ugly hack and since the future life of udev is unceartain due to the systemd/udev mess, i am looking for a better way. From what i understand udev was not even meant to handle things like this.
Code:
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"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,shortname=lower,gid=100,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"
Actually, i have been looking for a good way to automount removables since 2002 when i started using Linux more seriously, back then i just wanted to have things accessible like in old DOS, just pop in a CD or floppy and have a place to CD to. Since then we have got many more things that we plug in and out of our machines, but 10 years later (20 compared to DOS) i still miss something simple on a basic system level that do not require megabytes of graphic related software.
Back in the days there was supermount that looked promising, Mandrake used it back then and i used it in Slackware for some years. But supermount required some attention to every new kernel version and development eventually died. It was probably a bad way of doing it anyway and it would probably not have worked for the gizmos of today.
So, has anyone heard of a better way today?