Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 manually with mount / umount with the suitable entries in /etc/fstab but this is compelling, and to restrictive: if I want them to be mounted in /media/<LABEL> each device with a different <LABEL> needs its own entry, and each <LABEL> directory 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)?

The ideal solution would:

  1. detect when a removable media is plugged-in (added in /dev/ as sdax, sdbx, ... by udev)
  2. create a directory in /media/ according to its label (label of the removable media)
  3. mount it in the directory /media/<LABEL> in RW mode (if it's filesystem is supported)
  4. detect if the media has been unplugged
  5. if then, unmout it from the filesystem
  6. 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)

I found some info about autofs, HAL, udisks, udisks2, 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 ...

Minimalism, elegance, KISS, *nix-minded, no crazy unbearable XML policies files, and up-to-date highly appreciated.

edit: trying to make my question more clear

share|improve this question
I posted my questions on unix.stackexchange.com/questions/44454, maybe I'll have some more answers ... I'm not sure whether it should be deleted from here or not? – cedbeu Aug 1 '12 at 8:46

1 Answer

You might want to check your /dev/disk/by-uuid directory while those specific drives are plugged-in. Using ls -l it will show you the devices (e.g. /dev/sdb1) along with their uuids. Having found the matches, update your /etc/fstab accordingly, replacing /dev/sd* with the corresponding /dev/disk/by-uuid/* entry.

For details, see my answer to How do I prevent USB flash drive from getting a new Linux device name after wake from sleep?.

share|improve this answer
Actually, as I said, the devices are plugged in, I know their UUID/LABEL through either blkid or the /dev/disk/by-uuid directory. And I can mount them manually as well. Now, I already have them in /etc/fstab, actually eiter by label or by UUID, both work correctly. That doesn't really help though, since they are mounted at boot time only (as long as I do not specify noauto). But if I remove them and if I reinsert them while the system is running, they are not automatically unmounted / mouted in the directories I specified in fstab... This is my problem. – cedbeu Jul 31 '12 at 12:17
Looks like something weird -- as I use it for years for removables (e.g. SD-cards from my cameras, mobile devices as MP3 player, smartphones, tablets... And they all mount correctly at the designated mountpoint. If you remove them: do you unmount before, and mount again when re-inserting? You should do so, and then it should work. – Izzy Jul 31 '12 at 12:22
If I unmount them and mount them manually, everything works fine obviously. But my problem is that I want them to unmount (sync option in fstab) and mount them automatically (and as user as well as root) when I remove / insert them. That's why I guess either AutoFS, HAL, udisks, udisks2 (or hotplug, maybe ...?) or something similar is involved... But don't know what I'm missing exactly. – cedbeu Jul 31 '12 at 12:27
You probably miss that you still must unmount them manually -- or how shall the system know you're about to do that? Obvioulsy, once you unplugged it cannot be sync'd anymore, and neither cleanly unmounted. So the system assumes some drive-error -- but many times only discards the "old drive" after you plugged in the "new drive" again. So on auto-mount, the old mount point is still occupied -- which makes the "new" drive mount elsewhere. – Izzy Jul 31 '12 at 12:39
The hot plug / unplug system like hal (amongst others mentionned) should take care of unmounting the device of the fs if it's not plugged anymore. The sync option in /etc/fstab is used in this case for syncing the files of the device without caching, though avoiding data loss when hot-unplugging (w/o unmounting manually before). – cedbeu Jul 31 '12 at 13:31
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.