Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

4 Answers 4

Use

udisks --mount /dev/sdb1

(replace /dev/sdb1 with the device you want to mount)

share|improve this answer
add comment

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.

share|improve this answer
    
Thanks a lot -- udisks is exactly what I was looking for! For whatever reason, I'm getting "Mount failed: Not Aouthorized" when running it via ssh; if I'm not pushing my luck, pointers would be appreciated as to how to fix it. ^^ –  NicApicella Mar 21 '13 at 11:44
1  
@NicolaApicella How are you running it? You'll get a not authorized message if you try to run it from a remote session (including SSH) or from a crontab; by default non-root users can only mount volumes with udisks from local interactive logins. (They can still run a script from a local interactive login that uses udisks, though.) –  Eliah Kagan Mar 21 '13 at 11:49
    
Yes, sorry, just noticed (and edited) my previous comment: I'm indeed running it from ssh. (And currently googling a fix.) –  NicApicella Mar 21 '13 at 11:49
add comment

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

Nope. noauto keyword makes it skip mounting at boot time.

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

Easiest would be to add it to /etc/fstab with noauto and use ...

mount /dir

This will have mount probe for a mountpoint and if not found then for a device in /etc/fstab. /dir needs to exist though.

If either device or UUID are provided /etc/fstab is not probed. Like so ...

mount /dev/sda1 /media/directory

Or use udisks (I will let Eliah handle that >:-) )


mount generally is super user only.

Example options:

  • rw,noauto,user mounts it as read+write but not at boot and you can do it as a user.

  • You can also add in permissions for a user in /etc/fstab for files. You can use umask for that.

  • umask=0444 : everyone read, no write, no execute.

  • umask=0333 : everyone read, execute.
  • umask=0338 : owner, group read and execute; others, nothing
share|improve this answer
    
OK, I'll probably go ahead and try that, since it seems to be the "way to do it" anyway. :-) So I guess I'll have to create a mountpoint-directory (with correct rights) anyway. ;-) –  NicApicella Mar 21 '13 at 11:41
    
@Rinzwind Will a non-root user be able to mount the device? –  Eliah Kagan Mar 21 '13 at 11:49
1  
@EliahKagan Yes, if you set the appropriate options in fstab (uid, user, ...). –  NicApicella Mar 21 '13 at 12:09
    
@NicolaApicella I'm hoping this answer might be expanded to include information about that. :) –  Eliah Kagan Mar 21 '13 at 12:10
    
@NicApicella he likes to boss me around :=) –  Rinzwind Mar 21 '13 at 13:10
add comment

In one of the comments, you said:

For whatever reason, I'm getting "Mount failed: Not Aouthorized" when running it via ssh

I use pmount instead of udisks. It works over ssh.

If I remember correctly, this is the syntax/etc I use with it - most of mine are hidden behind aliases at this point:

pmount /dev/sdb1 my_usb
ls /media/my_usb/
eject /media/my_usb
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.