Score:3

Ubuntu-MATE: make USB Sticks automount available to every user (udev rules?)

in flag

I want every USB media (ext, ntfs, FAT…) inserted to be available with full read-writable to every user. Preferably under mnt and as group common.

( Ubuntu-MATE 21.04, though my issues actually date back even to Ubuntu-MATE 16.04...)

  1. I boot into my machine as user frank. When I mount an USB drive (FAT) it ends up under /media/frank/4C8C-E4BC – just fine, as it should. When I switch to another user (keeping the first session open, not logging off, i.e. dm-tool switch-to-user lisa) I get

Unable to mount 16 GB Volume Device /dev/sda1 is already mounted at /media/lisa/4C9C-xxxx

Making sense so far. But not what I want.

Sure, for individual drives I could change the mount location via gnome-disks or manually add a line to etc/fstab (which essentialy is what gnome-disks is doing). However I do not want to do this for each and every USB stick and SD card I posess...

Is there a better way for an all-user automount?

[ I understand/guess there's something called autofs handles the automatic mounting of USB sticks? But as far as I can tell, that's no part of my Ubuntu-MATE install... ]

And then there seems to be “udev-Rules”, is that, what I want? Apparently it's even an “inevitable” part of Ubuntu, as it is part of systemd (?)? There are rules on my machine under /etc/udev/rules.d although seemingly rather specific ones about brave and skype and signal...)

There's promising stuff MODE and GROUP and UDISKS_FILESYSTEM_SHARED but (provided this is the right approach) I can't set the ultimate puzzle pieces together. It should truly only apply to removable drives like USB sticks and memory cards, otherwise I get into deep trouble... this source mentions SUBSYSTEMS=="usb", that would be a good filter, if true...)

Is udev rulez the way?

If yes, can somebody set the puzzle pieces together? I am almost suspecting all I look for is a one-liner file in /etc/udev/rules.d.


addendum:

Not my main problem, but if it went away for the same reasons, I would be happy: Inserting a Windows Boot USB Stick (slightly more commplex, comes with an UEFI Boot FAT and a Windows Install NTSF partition) under the second user, I instantly get:

enter image description here

(and no, intense googling didn't get me anywhere) …switching back to first user frank (stick still inserted) I am welcomed by these authorization requests:

enter image description here


addendum:

Not a fix, but if those two users are essentially you, and the other one is not truly active (just switched-away from instead of logged-out) this is the quickest way before a trouble-free USB mount:

who -u
sudo kill <that other user's pid>
sudodus avatar
jp flag
I'm not running MATE, but other Ubuntu flavours. I don't know any way to use `udev` for this purpose, but I have used [`mount` for similar but simpler cases](https://askubuntu.com/questions/11840/how-do-i-use-chmod-on-an-ntfs-or-fat32-partition/956072#956072). So I am playing with a shellscript, than can do what you want, at least with Microsoft file systems. But 1. It needs `sudo` or running as `root`. You can allow using the shellscript or `mkdir` and `mount` without password via `visudo`; 2. It is a bad idea to tamper with the permissions in a Linux file system, e.g. `ext4`.
sudodus avatar
jp flag
You should not let an automatic tool tamper with the permissions in a Linux file system because changes are persistent and might destroy system directories and configurations.. If you want to make a Linux file system available to everybody, set the permissions with `chmod`; 3. It should work to start a shellscript manually, but it is also possible (maybe via `udev`) to watch for plugging in external devices; 4. Additinal shellscripts to unmount and clean up mountpoints should be easier to create. -- Are you interested of this `mount`way, or do you want to go the `udev` way?
Frank Nocke avatar
in flag
I have no intend of tampering with any user rights **but** those of the volume-to-be-mounted, which is [nothing unusual in `/etc/fstab` either](https://superuser.com/q/174776). Just for 'all USB drives that may be'. (if `fstab` had some kind of wildcard-support to match USB-drives, my problem would be solved. But it doesn't.) Und Udev rules indeed also [have a `MODE` attribute](https://www.clearpathrobotics.com/assets/guides/kinetic/ros/Udev%20Rules.html)...
sudodus avatar
jp flag
I am sorry, but I do not know `udev` well enough to help you with that. But my `mount` way *can* handle 'wild-card support'. However, you must initiate it somehow, via `cron` or `udev` or maybe some other way to watch for events. Do you want to see the script code?
Frank Nocke avatar
in flag
yes, sure... feel free to post as an answer (more writing/viewing comfort), same goal different method, after all
Score:2
jp flag

The following script may be called mounter or some [other] unique name. A for loop looks for the output of lsblk with suitable options. It will detect partitions in drives connected via USB and mount them (if not already mounted) at dedicated subdirectories of /mnt.

If you want to use the shellscript in your system, you will probably tweak it to manage already mounted partitions (unmount them in order to get them mounted like you wish).

#!/bin/bash

if [ "$(whoami)" != "root" ]
then
 echo "run with sudo or as root"
 exit
fi
for i in $(lsblk -lo name,fstype,hotplug,type|grep '1 part$'|tr -s ' ' ' '|sed 's/ 1 part$//'|grep ' ..*$'|tr ' ' '_')
do
 printf "$i\n"
 dev=/dev/${i%_*}
 fss=${i#*_}
# echo "$dev -- $fss"
 mkdir -p /mnt/"$i"
 if [ "$fss" == "ntfs" ] || [ "$fss" == "vfat" ] || [ "$fss" == "exfat" ]
 then
  mount -o rw,user,exec,umask=0000 "$dev" /mnt/"$i"
 else
  mount -o rw,user "$dev" /mnt/"$i"
 fi
done

This shellscript can do what you want, at least with Microsoft file systems.

  • It needs sudo or running as root. You can allow using the shellscript or mkdir and mount without password via visudo.

  • You may or may not want to modify the umask to keep 'others' from writing.

  • It is a bad idea to tamper with the permissions in a Linux file system, e.g. ext4. So this shellscript uses different mount options in this case. If you want to make a Linux file system available to everybody, set the permissions with chmod manually.

  • It should work to start a shellscript manually, but it is also possible via cron or udev or maybe some other way to watch for plugging in external devices.

  • Additional shellscripts (or command lines) to unmount and clean up mountpoints are neceasary and should be easier to create.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.