I am used to macOS, where external drives are mounted under /Volumes and are accessible to all users. I would like to mimic this behavior on Ubuntu so I can configure a samba share for another user and so I can give Plex access to all externally mounted media. What is a good way to do this?
1 Answer
Note: I know nothing about Plex. The only thing I keep seeing in posts is that it runs as the user plex but that is my extent of knowledge.
In my test box when I ( user = tester ) attach a USB HDD it mounts to /media/tester/$UUID - accessible to tester but no one else.
One way to have universal access to any USB media is to use bindfs to create a "view" that allows it.
[1] Install bindfs:
sudo apt install bindfs
[2] Create a mount point for this "view":
sudo mkdir /MyMedia
[3] Temporarily remount /media/tester to /MyMedia using bindfs:
sudo bindfs /media/tester /MyMedia -o force-user=tester,force-group=tester,perms=666:+X
If I attach a USB HDD to the system it will now appear to be mounted twice:
** Once where Linux wants it to be mounted:
$ ls -al /media/tester ... drwxr-xr-x 3 tester tester 4096 Dec 31 1969 03E9-7C8D
** And again where bindfs mounts the "view" with a new set of permissions:
$ ls -al /MyMedia ... drwxrwxrwx 3 tester tester 4096 Dec 31 1969 03E9-7C8D
When I create the samba share I point it to /MyMedia
To undo the bindfs mount:
sudo umount /MyMedia
If it does what you want it to do you can have this bindfs "view" created at every boot by adding a line at the end of /etc/fstab - with a change of syntax:
/media/tester /MyMedia fuse.bindfs force-user=tester,force-group=tester,perms=666:+X,nonempty 0 0
Then unmount it if you still have it mounted:
sudo umount /MyMedia
Then make systemd happy:
sudo systemctl daemon-reload
Then mount it:
sudo mount /MyMedia
It should now mount that "view" at every boot.
Like I said at the top of this post I know nothing of Plex but it it wants all files to be owned by the user "plex" replace "force-user=tester" with "force-user=plex" in the bindfs mounts.
-
Thank you for this solution. It would surprise me, though, if there were not a native way to do this on Ubuntu. Do you know if there is? Jul 24, 2021 at 17:41
-
The problem is the /media/$USER folder. It is created by default in Linux with a special permissions setting that allows only the user that attached the device to gain access to it. It was deemed a security / privacy feature when it was introduced a decade or so ago. You would have to find a way to override this default mechanism, or if it were an internal or always known HDD mount it someplace else in fstab, or in the case of Plex have it run as you instead of "plex", or use something like bindfs.– Morbius1Jul 24, 2021 at 19:21