I have a Debian sid system (Wheezy), without any desktop environment (and no Xorg at all).
I can mount my SD-cards, USB sticks, external HDD by label into a specified directory in /media/ manually with mount / umount and the suitable entries in /etc/fstab, or automatically at boot time, but this is compelling, to restrictive and not dynamic enough for my needs: if I want them to be mounted in /media/<LABEL>, each device with a different <LABEL> needs its own entry, and each <LABEL> subdirectory needs to be created / removed manually in /media/ as well).
So, what is the best way to mount them automatically in /media/<LABEL> at insertion (and to unmount them from the filesystem as soon as they are unplugged no matter how risky it is for the data)?
The ideal solution would:
- detect when a removable media is plugged-in (i.e. when added in
/dev/assdax,sdbx, ... byudev) - create a directory in
/media/according to its label (label of the removable media) - mount it in the directory
/media/<LABEL>inRWmode (if it's filesystem supports that) withflushoption (for avfat) - detect if the media has been unplugged
- if then, unmout it from the filesystem
- remove the corresponding directory from
/media/
(the devices should be mounted in synchronous mode oviously, to avoid any data loss when hot unplugged because of caching edit: sync is way too much for vfat removable media so flush has been created as a compromise, less secure than sync, but less risky according to the life-cycles of flash memories)
I found some info about autofs, HAL, udisks, udisks2, usbmount etc., but it's unclear which one is deprecated or preferred, and anyway, I haven't figured out how to configure them easily on my system to do that, up to now ...

sync, a deamon can unmount the device from the fs if it detects that it has been unplugged with no data loss. All desktop distros do that. I want that in terminal. – cedbeu Aug 1 '12 at 9:18halevt. About unmount, generally DE expect you to eject the device from the file manager, before physically unplugging it. – enzotib Aug 1 '12 at 9:24fdisk -land thenmount- that's two commands, but OK, if you want it automatized, you'll have to parse thefdisk -loutput, and then put it in themount- I do such stuff withhead,tail,tr,cut, etc. but the pros usually do it withawkor, even better, look for the data in the correct place. About deletion, at least for me when I mount to/mnt, that's done automatically. About the trigger (when you plug in) I have no clue, but please tell us when you solve this. – Emanuel Berg Aug 1 '12 at 10:40