Mounting from dolphin vs commandline

I have been wondering how this is possible (i.e. how this works internally). When you want to mount a directory you have to be root.

sudo mount /dev/something /mnt/somedir

I know you can get around that by adding a line in fstab.

Now, I’m wondering how come if I insert let’s say an usb stick and select it from within Dolphin (KDE’s filemanager), it mounts it without the need for a root password and gives me write/read access to what it has mounted? I’m guessing it is using dbus to monitor for new devices. I don’t see how (when it knows there is something it should be mounted) it can mount it without the need for root. I haven’t yet figured out how to manually mount some device without root and maybe I can learn something from how Dolphin does it.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

This is done by udisks.
There are two versions of udisks, “udisks” and “udisks2”. You have probably installed at least one of them. Both ship with commandline utilities.
Both should work when Dolphin works.

udisks mounts the filesystems into /media/<label>.

$ udisks --mount /dev/sdc1
Mounted /org/freedesktop/UDisks/devices/sdc1 at /media/<label>
$ udisks --unmount /dev/sdc1

The utility for udisks2 is called udisksctl.
It uses /run/media/$USERNAME/<label>

$ udisksctl mount -b /dev/sdc1
Mounted /dev/sdc1 at /run/media/t-8ch/<label>.
$ udisksctl unmount -b /dev/sdc1
Unmounted /dev/sdc1.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x