12

I'm writing a backup script in which I need to mount a drive in the media bay of my laptop.

I know that I can get the job done by messing with fstab and the mount command. Perhaps that's the easiest way. Anyway, I'm interested in the following:

  1. Initially the media bay drive is unmounted.

  2. I click on the drive in the side-panel in a nautilus window and the drive is mounted.

  3. I can access it at /media/baydrive.


My question:

Is there an easy way of performing step 2 from the command line? I.e., mount the drive to /media/<device name> without messing with fstab.

5 Answers 5

13

Try udisks --mount <device name>

To mount by partition label, you can do

udisks --mount /dev/disk/by-label/baydrive
6
  • Nice command, but I get Cannot stat device file baydrive: No such file or directory
    – aioobe
    May 26, 2011 at 9:24
  • 1
    The device name needs to be the device file used for the baydrive - something like /dev/sdb1 May 26, 2011 at 9:34
  • Right. Then it works. You know of any way of referring to just baydrive instead?
    – aioobe
    May 26, 2011 at 9:36
  • 1
    No. But if the partion has a label "baydrive" you can use /dev/disk/by-label/baydrive May 26, 2011 at 20:03
  • whoaa,. I had no idea about that. great! Edited post to include this variant
    – aioobe
    May 26, 2011 at 20:12
6

The most equivalent (at least for ubuntu 14.4) is

udisksctl mount --block-device /dev/disk/by-label/baydrive
udisksctl unmount --block-device /dev/disk/by-label/baydrive

The difference between udisks and udisksctl is that udisks always mount under /media, while udisksctl mount where nautilus would, which is sometimes /media/${USER}

2

If you want this to be for your user and not root try this

udisksctl mount -b /dev/sdb2 

use the right name of your disk

0

automounted drives

/media/username/driveUUID/

nautilus samba mounted drives are found in

/run/user/1000/gvfs/smb-share:server=10.100.4.16,share=share-name/path-to-folder/

or for sftp mounts you can access at

/run/usr/1000/gvfs/sftp\:host\=10.100.4.16/
-1

You can alternatively mount the drive, it will then appear at the side panel.. you can right click that shortcut on the side panel and lock it on the launcher.. now you will be able to simply single click that icon to mount the drive without any command, startup script or opening nautilus.

1
  • 2
    The whole point of the question is how to do this without fiddling with the GUI. I want to put the backup script as a cron job.
    – aioobe
    Mar 17, 2014 at 21:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .