Monday, April 29, 2024
17
rated 0 times [  17] [ 0]  / answers: 1 / hits: 5928  / 2 Years ago, sat, october 29, 2022, 7:31:20

On Ubuntu 12.10, when I want to mount a hard drive, I can just click on the unmounted drive and everything works fine (by mounting to /media/username/partitionlabel).



Basically, I would like to do exactly that via command line (for a script I'm working on).



Since I do not want to automount on boot, fstab is out of the question (right?).



When I use mount on CLI, I need to specify a mountpoint (which needs to have a previously created mountpoint; also, I need to take care of permissions and whatnot) -- what I don't understand is where does the GUI take all its infos from? The mountpoint seems to depend on the partition's label, but such a directory doesn't exist before mounting. Also, the GUI way doesn't seem to care too much about a user not being root.



Is there an "easy" way to mount via CLI, just like it does on the GUI by clicking on an unmounted drive?


More From » command-line

 Answers
5

Nautilus and other file managers that mount drives (i.e., the GUI) use the udisks command.



This provides a dynamic mount, where the mount point is created for the drive on-the-fly, and when the drive is unmounted, the mount point goes away.



See man 1 udisks for details on how to use this command (either manually, or called from a script/application). To learn more about how udisks works, see man 7 udisks.



To mount a device with udisks, you must specify a valid device name for the device. Specifying the device's volume name will not work. So, you can use udisks like this:



udisks --mount /dev/sdb1


When manually using udisks from the command-line, you might be best off to simply plug in a device, then run dmesg | tail shortly thereafter (see man dmesg and man tail) to discover the device name of the newly attached device.



This may not be the best way to write a script that mounts devices with udisks, however. I don't know exactly how you should do it, and it would be difficult to know since you haven't told us precisely what you want this script to do and when you want it to mount devices.


[#32097] Saturday, October 29, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
exceeeelh

Total Points: 21
Total Questions: 109
Total Answers: 120

Location: Marshall Islands
Member since Wed, Jan 5, 2022
2 Years ago
exceeeelh questions
Sun, Nov 20, 22, 17:08, 1 Year ago
Sat, Jan 1, 22, 08:04, 2 Years ago
Wed, May 12, 21, 05:11, 3 Years ago
;