LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Automount removables (http://www.linuxquestions.org/questions/slackware-14/automount-removables-4175437569/)

steelneck 11-17-2012 08:40 AM

Automount removables
 
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?

Snark1994 11-17-2012 08:49 AM

Have you looked at e.g. https://wiki.archlinux.org/index.php...disks_wrappers? The first item listed works on command line.

Hope this helps,

steelneck 11-17-2012 09:27 AM

Hmm.. The devmon bash script coming with udevil look promising, i will have a closer look on that. A bash script to accomplish this is KISS enough for me ;-)

steelneck 11-17-2012 12:57 PM

Udevil/devmon actually seem to do the job quite nice, i wonder how i can have missed it.. I will mess around with it for a while longer, so far i have only tried it on my Arch-box and i will probably not try in Slack until i put together my new box. Many thanks "Snark1994" for pointing me in this direction.

Snark1994 11-18-2012 10:43 AM

No problem at all. If you consider the issue resolved to your satisfaction, please mark the thread as 'SOLVED' (there's a link near the top of the page).

Regards,

lambo69 11-19-2012 07:03 AM

Have you tried autofs?

lambo

steelneck 11-20-2012 01:01 PM

Done some more testing today, though still not in slackware (on this machine i am using now i have Arch), but i think i can call my issue solved.

@lambo69: No i have not and so far udevil seem to do what i want in a way that i can live with.


All times are GMT -5. The time now is 11:34 AM.