You are not logged in.

#1 2019-07-20 12:32:26

pgoetz
Member
From: Austin, Texas
Registered: 2014-02-21
Posts: 341

Using USB sticks without root privileges?

Using USB sticks with linux continues to be problematic, so this post is aimed at understanding what subsystems are responsible for the default behavior.  I'm not sure how much this is related, but I've been using the Mate Desktop exclusively for a while now.

1. Where an inserted USB stick is mounted -- what changed?

I frequently have more than one person logged in on my workstation.  Until recently, my Mate-based system would exhibit the following annoying behavior.  I would plug a (FAT32) USB stick in and it would mount on the desktop of the last person who logged in rather than on my (currently active) desktop.  I would have to unmount the device and remount manually, which requires superuser intervention:

# umount /run/media/sven/ARCH_201907
# mkdir /run/media/pgoetz/usb
# mount -o gid=1001,uid=1001 /dev/sdf1 /run/media/pgoetz/usb

At some point in (... the last year?) that behavior changed, and USB sticks now mount on the currently active desktop.  Does anyone know when/how this was fixed?


2: Eject

When I insert a USB stick formatted with a known filesystem, it's automatically mounted to

/run/media/pgoetz/device_label

.  More often than not this isn't what I want because I'm using it to create a bootable linux ISO, and the command

# dd bs=4M if=./archlinux-2019.07.01-x86_64.iso of=/dev/sdf

simply fails if /dev/sdf1 is mounted.  Or I should say, it creates partitions and writes something, but not what you want. However, if I eject the device, it disappears completely from the block device list and isn't visible using either lsblk or blkid.  So instead of using Eject, I have to use umount from a terminal.  This is fine for me, but I'm hard pressed to see how someone who isn't a linux admin would go about creating a bootable USB device.  What is Eject doing that completely removes the block device from the system rather than just unmounting it, which would appear to be the sensible behavior here?

3. The Filesystem matters -- but it shouldn't?

This is the issue that finally prompted me to post this.  I rarely use ext4-formatted USB devices, but recently had occasion to use one when I needed to transfer pacman packages to a system which didn't have network access. If you insert an ext4-formatted USB stick, it mounts to the user desktop, but in an unusable way:

[root@frog pgoetz]# pwd
/run/media/pgoetz
[root@frog pgoetz]# ls -l
total 4
drwxr-xr-x 3 root root 4096 Jul 20 06:44 ARCH_201907

You can see that the device is automatically mounted to my desktop, but only root can write to it.  Sure, it's standard for block devices to be mounted by root, and I can write to folders on the device that are owned by my username, but all this requires superuser interaction; i.e. sudo privileges.  I can't hand a user without sudo privileges a freshly formatted ext4 USB stick and expect them to be able to write to it.

If I relabel and reformat the partition as FAT32, the behavior reverts to what one would expect:

[root@frog pgoetz]# pwd
/run/media/pgoetz
[root@frog pgoetz]# ls -l
total 4
drwxr-xr-x 2 pgoetz pgoetz 4096 Dec 31  1969 ARCH_201907

(Note that I'm using the same USB stick reformatted from ext4 to FAT32.

So, what would be the user friendly way for all this to work?  Eject should just unmount removable block devices (which can then safely be removed) rather than obliterating them, and a removable block device that I insert should be writeable by me no matter what filesystem it is formatted with.  There is room for debate here, but the bottom line is that if I'm handling a removable block device, I ultimately control what's on it anyway, as I can just plug it into a system I do have sudo privileges if I don't on this one.

Thoughts?  Is there any way to achieve the functional behavior I'm looking for without having to rewrite a bunch of OS/Desktop software?

Offline

#2 2019-07-20 12:49:23

seth
Member
Registered: 2012-09-03
Posts: 51,230

Re: Using USB sticks without root privileges?

Using USB sticks with linux continues to be problematic

wtf?

https://wiki.archlinux.org/index.php/Udisks
If you're looking for integration in some GUI FM, many rely on gvfs.

You cannot "eject" a usb key, that program (and term) is for optical drives (and floppies, which we'll ignore)

Online

#3 2019-07-20 20:12:58

pgoetz
Member
From: Austin, Texas
Registered: 2014-02-21
Posts: 341

Re: Using USB sticks without root privileges?

seth wrote:

You cannot "eject" a usb key, that program (and term) is for optical drives (and floppies, which we'll ignore)

Yeah, maybe that's a Caja thing.  If you right click on the device in the file manager it gives you the option of Eject, which in this case should just be unmount.

Thanks for the Udisks link; was not aware of that, but most of the stuff I'm talking about is automatic and most likely gvfs based, so I'm not entirely sure how this is relevant.  Are you suggesting that if I install udisks2 this will all just work better automatically?  If it comes down to requiring a DE switch to gnome or KDE, I'll happily stick with the headaches of the status quo.  Every time I try either of those DEs for a bit or even XFCE I always go back to Mate as the DE that is fairly lightweight and just stays out of my way.

Offline

#4 2019-07-20 20:18:37

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Using USB sticks without root privileges?

pgoetz wrote:

So, what would be the user friendly way for all this to work?

As seth has said, udisks just works.


Moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2019-07-20 20:19:38

cynicfm
Banned
From: Home
Registered: 2019-05-31
Posts: 96

Re: Using USB sticks without root privileges?

I am not sure if this is similar but i been having same issue now on Arch... If i instert cd to cd-rom it won't show up in for example i use thunar device list. Well it does show but i click on it nothing happens. I downloaded gvfs but well... That was ok till i rebooted... I want to say that when i connect mtp android device i can upload stuff like music if i log in with root. But if i log in with user i have created no luck... The mount is not automated but i wish it was...
The cd rom installation is not possible when i try to install some multiple cd's windows game using wine liek Call of Duty. I mount the device with mkdir /cdrom mount /dev/cdrom /cdrom but then when it asks me for 2nd cd the device is busy so i cant unmount it therefore i cant finish installation ;-(. I wish i could know how solve this issue, i have got some gnome-polkit but no luck.
I can't access penstick as well and it's fresh arch install

Perhaps gnome and kde are taking over the linux world and soon everybody will have to use either of those xD.


Have a good day

Offline

#6 2019-07-20 20:49:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,530
Website

Re: Using USB sticks without root privileges?

pgoetz wrote:

3. The Filesystem matters -- but it shouldn't?

Yes, it should.  Your concerns/symptoms (under this #3) have nothing to do with access to the mount point or device node, but just the content on the removable device.  If the filesystem on the device has ownership and access metadata, it is respected.  If the filesystem does not have such data, then - of course - it cannot be respected.  When an ext4 device is mounted, the ownership and permissions of the mount point do not (normally, without special mount options) impact the permissions of the content of the mounted filesystem.

Last edited by Trilby (2019-07-20 21:04:04)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2019-07-20 21:01:16

pgoetz
Member
From: Austin, Texas
Registered: 2014-02-21
Posts: 341

Re: Using USB sticks without root privileges?

cynicfm wrote:

The cd rom installation is not possible when i try to install some multiple cd's windows game using wine liek Call of Duty. I mount the device with mkdir /cdrom mount /dev/cdrom /cdrom but then when it asks me for 2nd cd the device is busy so i cant unmount it therefore i cant finish installation ;-(. I wish i could know how solve this issue, i have got some gnome-polkit but no luck.
I can't access penstick as well and it's fresh arch install

Yeah, I have 2 optical drives in my system which Caja identifies correctly except when I try to eject a disk, at which point it always opens the other (empty) drive tray.  I use optical drives so rarely these days that it wasn't worth worrying about, but is plenty annoying when I do.

I don't think this is related, though.  I would post this as a separate question.

Offline

#8 2019-07-20 21:13:39

seth
Member
Registered: 2012-09-03
Posts: 51,230

Re: Using USB sticks without root privileges?

udisks is one way to manually mount w/o the requirement for root permissions
Since your automount stuff *was* an issue, but is no longer (thus just pointless text) I'm gonna say your only actual problem is addressed in post #6

Online

#9 2019-07-20 21:35:07

pgoetz
Member
From: Austin, Texas
Registered: 2014-02-21
Posts: 341

Re: Using USB sticks without root privileges?

seth wrote:

Since your automount stuff *was* an issue, but is no longer (thus just pointless text) I'm gonna say your only actual problem is addressed in post #6

Yes, true.  I'm just interested in understanding how this works under the hood and was hoping someone would say something like "oh yeah, this is due to this change in ...".

It's nice to know about udisks2, but the Mate DE pretty much takes care of this for me, and otherwise I'm perfectly comfortable just using sudo [un]mount when necessary.  The one annoying thing is that Caja affords an Eject for USB sticks which does something other than unmount that I frankly don't understand (nothing shows up in dmesg, for example*), since the block device just disappears until I unplug and replug it.  I have to support a ton of linux workstation users (scientists) who are generally not actually linux users, so have to worry about how they interact with these things.

* Looking in /proc/scsi/scsi, I do still see the device there; also in /sys/block, so the mystery is just why lsblk and blkid can't find it.

Anyway, thanks for your help with this.

Offline

#10 2019-07-20 21:50:07

loqs
Member
Registered: 2014-03-06
Posts: 17,372

Re: Using USB sticks without root privileges?

Offline

#11 2019-07-20 22:00:22

pgoetz
Member
From: Austin, Texas
Registered: 2014-02-21
Posts: 341

Re: Using USB sticks without root privileges?

That's it!  Caja Eject must also power off the USB device.  The only remaining mystery is why it still shows up in /proc/scsi/scsi and /sys/block while powered off.

Last edited by pgoetz (2019-07-20 22:00:40)

Offline

Board footer

Powered by FluxBB