0

I'm trying to make Raspbian automatically mount all available paritions on USB devices under a certain folder.

I heard of fstab rules but those seem to require knowing the UUID of all devices meaning I'd have to pre-define what USB devices I can use which is not ideal.

I want the OS to automatically mount any plugged in USB device (both present at boot or not) under the folder /storage each partition on its own mount point (the names of the mounts can be anything, but should ideally not change between boots. This isn't a requirement however)

Thanks in advance

1

The normal approaches to this would be (presuming you're not using a desktop environment where it's built-in) one of:

  1. udiskie with udisks2. This is more common, especially the udisks2 part which is what handles it under the "normal" desktop environments).
  2. udevil. This is intended as a lighter-weight alternative.
  3. More specialized: code in your application interfacing with udisks2.

Note that the normal place these will be mounted is /media, not /storage. I'm not sure there is an easy way to override this; /media is the standard directory.

You'll also need to consider how the disks will be unmounted (before removing them); in the case of #3, your application would generally provide the option, or do it automatically when no longer in use. #1 or #2, you need to find some other way.

4
  • I had a look at udiskie but it only allows mounting to /media/$USER/$DEV or /media/$DEV which I eventually solved using symlinks. However, other users don't have write access to these devices which is a problem. Any ideas how to get around that? – user9123 Nov 12 '19 at 18:46
  • @user9123 Unfortunately you can't change the options udisks2 mounts with, it's hard-coded. There have been patches to change that (bugs.freedesktop.org/show_bug.cgi?id=33461 and lists.freedesktop.org/archives/devkit-devel/2015-April/…) but AFAICT they went nowhere. You'd want to change the umask flag if it were possible :-( You should be able to get it mounted as your user, though, if you only need one user to be able to write. – derobert Nov 12 '19 at 19:36
  • I tried udevil instead and it works great. The included daemon (devmon) can be easily run on startup (I used systemd for that) and you can set the permissions, mount locations, accepted filesystems etc. in the config (/etc/udevil/udevil.conf on Debian distros). Thanks! Marked as accepted. – user9123 Nov 12 '19 at 19:37
  • @user9123 glad udevil worked out – derobert Nov 12 '19 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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