LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Mounting a USB drive using udisks (https://www.linuxquestions.org/questions/linux-software-2/mounting-a-usb-drive-using-udisks-4175622096/)

linuxbawks 01-21-2018 11:07 AM

Mounting a USB drive using udisks
 
I've been mounting removable drives by giving a usergroup sudo privileges to /bin/mount and /bin/umount.

I now want to use udisks. I have Dbus installed and I also have p11-kit installed through dependency resolution for some other apps. I have now installed policykit.

In /etc/polkit-1/rules.d, there is this file:

20-plugdev-group-mount-override.rules
Code:

polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.udisks2.filesystem-mount" &&
        subject.isInGroup("plugdev")) {
        return polkit.Result.YES;
    }
});

polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.udisks2.eject-media" &&
        subject.isInGroup("plugdev")) {
        return polkit.Result.YES;
    }
});

Now the user is part of %plugdev but I'm still only able to mount a drive using sudo:

Code:

sudo udisksctl mount -b /dev/sd**
It's my understanding that I should be able to mount without sudo as the user is in the correct group and polkit should return YES.

Code:

$ udisksctl mount -b /dev/sd**
Error mounting /dev/sdd1: GDBus.Error:org.freedesktop.UDisks2.Error.NotAuthorized: Not authorized to perform operation (polkit authority not available and caller is not uid 0)


linuxbawks 01-21-2018 01:04 PM

pkaction or pkexec gives me:

Code:

Error getting authority: Error initializing authority: Error calling StartServiceByName for org.freedesktop.PolicyKit1: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Launch helper exited with unknown return code 127

Habitual 01-22-2018 12:06 PM

I have used this for years, as is. no sudo or polkit anything.
Just edit for your device and mount point and run by the user(s). (one script per user)
Tip: Mount under /media/<user>/mount_point or else.
mount_point need not exist prior to the mount.

Code:

#!/bin/bash
cd $HOME ; sync
/usr/bin/udisksctl mount -b /dev/sdc1 /media/jj/external  > /dev/null 2>&1
/usr/bin/ionice -c 3 /usr/bin/rsync -avz  . /media/jj/external/LM17/ --delete # --exclude Videos
#EOF

Everything is user:user and
DIRs are 755
files = 644

Good luck.

m.a.l.'s pa 01-22-2018 01:16 PM

Yes, I think you should be able to mount them without sudo; I've been doing it this way for a long time now, on various systems -- Debian, Arch, whatever. I thought it worked the same for everone. I don't have to do anything to set it up and I don't even understand the details. I don't use a script or anything, I simply pull the commands from bash history.

Check with lsblk to make sure the flash drive is detected:

Code:

$ lsblk
NAME  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
[...]
sdb      8:16  1  14.9G  0 disk
└─sdb1  8:17  1  14.9G  0 part

Mount:

Code:

$ udisksctl mount -b /dev/sdb1
Mounted /dev/sdb1 at /run/media/steve/5166-59C0.


linuxbawks 01-22-2018 01:28 PM

Thanks for replying.

In order to run this command you still need sudo or polkit:

Code:

$ udisksctl mount -b /dev/sdb1
If I do this (without sudo) I still get:

Code:

Error mounting /dev/sdd1: GDBus.Error:org.freedesktop.UDisks2.Error.NotAuthorized: Not authorized to perform operation (polkit authority not available and caller is not uid 0)


All times are GMT -5. The time now is 01:57 PM.