44

On my Ubuntu linux box I can easily mount USB connected drives or CDROM clicking on devices icons that I can found on the Desktop.

For example if I click on a USB connected drive icon the following things happen:

  • a /media/LABEL directory is automatically created (where LABEL is the label of the disk and may vary from disk to disk)
  • the filesystem on the device is mounted on /media/LABEL

This process is significantly different from mounting using the mount command. In particular:

  • you don't need to be root (or you don't need to modify /etc/fstab to allow ordinary user to mount the device)
  • the /media/LABEL directory is automatically created
  • the name of the directory changes according the volume label.

There is a command line command that behaves like the Gnome GUI mounting facilities does?

Andrea Francia
  • 9,737
  • 16
  • 56
  • 70
  • I decided to use `/etc/fstab` to mount my disk at boot, probably not what you want, but it works reliably when the SO thread is locked and none of the options seem to work. – ThorSummoner Dec 24 '16 at 04:44

9 Answers9

46

What you are looking for is gio mount (it recently replaced gvfs-mount, which replaced gnome-mount).

There is a man page here or you can just type gio help mount for the details

The basic usage is:

gio mount --list --detail to get a list of mounted and mountable volumes

gio mount [-u] <volume> to [un]mount it, e.g. gio mount smb://server/share or gio mount WINDOWS.

Sadly, there seems to be a bug that results in a "Error mounting location: volume doesn't implement mount" message trying to mount by volume name, but gvfs-mount -d /dev/<devicename> might work.

Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103
mwx
  • 554
  • 1
  • 4
  • 4
  • 1
    On Oneiric and Natty gvfs-mount smb://server/share seems to work out of the box. You might want to ensure you have gvfs-fuse installed. – Greg Sep 23 '11 at 01:22
  • [`gvfs-mount` also requires DBus](http://unix.stackexchange.com/a/44318/13308). – palswim Dec 28 '16 at 19:15
  • How I mounted my camera: `gio mount --list --detail` there was a line like `activation_root=gphoto2://Name_of_Company_Model_Name_SomeNumbers` then I did `gio mount gphoto2://Name_of_Company_Model_Name_SomeNumbers`. Now I can see my camera's files in `"/run/home/$UID/gvfs/gphoto2:host=Name_of_Company_Model_Name_SomeNumbers/DCIM"` (need quotes because of the `ghoto2:host=`), where [$UID](https://en.wikipedia.org/wiki/User_identifier) is probably `1000`. – Boris Verkhovskiy Jul 20 '19 at 04:33
26

In modern distributions, HAL is no longer used. The pmount still exists, but it is deprecated. Use:

udisks --mount /dev/sdXN

Answer Update:

The udisksctl command is being used as an alternative to the udisks command. This can be used the same way, -b is just to be appended to define the block device.

udisksctl mount -b /dev/sdXN
Rohan Bari
  • 7,482
  • 3
  • 14
  • 34
noname
  • 269
  • 3
  • 2
11

See the pmount command for usage information

Jake88
  • 955
  • 1
  • 19
  • 39
phihag
  • 278,196
  • 72
  • 453
  • 469
  • pmount doesn't have few features of nautilus. 1) nautilus lists available drives. when i press tab pmount doesn't list my windows partition. and if it would, i doubt it would list it as "Windows7_OS", but this is not that important. 2) when i pmount something, i have to create a directory for the mounting point. nautilus does it automatically. it seems that nautilus has its own database for mounting, is there a way to access it? – kirill_igum Apr 21 '11 at 19:44
  • pmount uses HAL, which is being depreciated, so I would recommend looking at the post by @mwx below – Jake88 Sep 11 '12 at 15:05
  • 1
    @kirill_igum *"when i press tab pmount doesn't list my windows partition"* *smile* you are a funny one. Yes, I guess you could do that by writing you own *bash-expand rule function*. I guess what you want is `udisks`, see another answer below. – towi Aug 07 '13 at 11:28
  • pmount doesnt work for non removable devices :( – Aquarius Power Oct 27 '21 at 00:27
1

Yes there is. It's called ivman and handles all HAL events. I start it when running ion3. I simply start ivman as a daemon process, but has added the program to my sudoers file:

cat /etc/sudoers
[...]
ivman {hostname}=(root) NOPASSWD: /sbin/init, /usr/sbin/hibernate
[...]

so that it can manage power settings as well.

Steen
  • 6,573
  • 3
  • 39
  • 56
0

That would be "devkit-disks --mount /dev/sdxx" where xx is the letter and number of the partition to mount...

akjoshi
  • 15,374
  • 13
  • 103
  • 121
0

I have a script to do what you want.

#!/bin/bash
#====================================================================
# udmount.sh - mounts partitons by volume label.
#  usage: udmount.sh <label> [rw|ro|u]
#   rw - mount read-only (default) 
#   rw - mount read-write 
#   u  - unmount
# 
# Mounts on /media/<label>. Tested on Mint 13 and Fedora 19.
# Use and/or modify at your own risk. Your mileage may vary.
# Caveats:
#   * No spaces in volume label. Won't work.
#   * If the mount point (/media/<label>) already exists,
#     (usually from an unclean shutdown), udmount will mount
#     the volume on /media/<label>_  
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You can view the GNU General Public License for this program at
# http://www.gnu.org/licenses/gpl.txt
# Copyright 2013 maxdev137@sbcglobal.net
#====================================================================

BEEP=$'\a'
VLABEL="$1"     # volume label
MPOINT="/media" # default mount point for gnome-mount/udisks
YN=""           # yes/no string

c_red() { echo -n $(tput setaf 1)$1$(tput sgr0) ; }
c_grn() { echo -n $(tput setaf 2)$1$(tput sgr0) ; }
c_yel() { echo -n $(tput setaf 3)$1$(tput sgr0) ; }
c_blu() { echo -n $(tput setaf 4)$1$(tput sgr0) ; }
c_pur() { echo -n $(tput setaf 5)$1$(tput sgr0) ; }
c_aqu() { echo -n $(tput setaf 6)$1$(tput sgr0) ; }
c_wht() { echo -n $(tput setaf 7)$1$(tput sgr0) ; }

Y="YEP " ; Y_c=$(c_grn "$Y")
N="NOPE" ; N_c=$(c_red "$N")
SNAME=`echo "$0" | sed -e 's|.*/\(.*\)$|\1|'`

#--------------------------------------------------
AMV_LABEL=""    # already mounted volume label
MMSG=""         # "is mounted on" msg
AMF=0           # already mounted flag
AMV=""          # already mounted volume (from "mount -l")
AMV_DETAILS=""  # already mounted volume details
AMV_HELPER=""   # "uhelper" subsystem for mount/unmount ("hal" or "udisks")
COPT="$2"       # command line option
MOPT="ro"       # user input for mount option
UOPT="ro"       # udisk mount options

#--------------------------------------------------
_usage ()      { echo "usage: $SNAME LABEL [rw|ro|u]" ; }
_error()       { echo "!!! Error: $1. !!!" >&2 ; echo -n "$BEEP"; _usage ; exit 1 ; }
_error_parm()  { _error "$2 Parameter Missing [$1]" ; }
_error_parm2() { _error "Command is wrong (only \"rw, ro, or u\") is alowed, not \"$1\"" ; }

_unmount () {
  ### unmount ###
  if [ "$COPT" = "u" ] ; then
    MPOINT=`echo "$AMV" | grep "\[$VLABEL\]" |sed -e 's|^.* \(/.*\) type.*$|\1|'`
    #echo "unmount MPOINT = [$MPOINT]"
    if [ -z "$MPOINT" ] ; then
      echo "$N_c - $VLABEL not mounted."
    else
      _MSG=`umount "$MPOINT" 2>&1`
      _STATUS=$?
      if [ "$_STATUS" -eq 0 ] ; then
        echo "$Y_c - \"$MPOINT\" is now unmounted"
      else echo "$N_c - unmount \"$MPOINT\" failed ($_MSG)"
      fi
    fi
  fi
}

#--------------------------------------------------
[ -n "$VLABEL" ]  || _error_parm "$VLABEL" "Volume Label"

### command line option checck
case "$COPT" in
  "ro" ) ;;
  "rw" ) ;;
  "u"  ) ;;
     * ) _error_parm2 "$COPT" ;;
esac

### is VLABEL already mounted?
AMV=$(mount -l | grep "\[$VLABEL\]")
AMF=$?

### VLABEL is mounted somewhere
if  [ $AMF -eq 0 ] ; then
  AMV_LABEL=$(echo "$AMV" | sed 's/^.* \[\(.*\)\]$/\1/')
  AMV_DETAILS=$(echo $AMV | sed 's|^.*on \(.*\) \[.*$|on \"\1\"|')
  AMV_UHELPER=$(echo $AMV | grep uhelper | sed 's/^.*uhelper=\(.*\)).*$/\1/')
  #echo "AMV = [$AMV]"
  #echo "AMV_LABEL = [$AMV_LABEL]"
  #echo "AMV_DETAILS = [$AMV_DETAILS]"
  #echo "AMV_UHELPER = [$AMV_UHELPER]"

  ### unmount ###
  [ "$COPT" = "u" ] && _unmount && exit $?

  ### mounted on MPOINT (usually /media)
  if [ -d "$MPOINT/$VLABEL" ] ; then
    MOPT="ro" ; YN="$N_c"
    [ -w "$MPOINT/$VLABEL" ] && MOPT="rw"
    [ "$MOPT" = "$COPT" ]     && YN="$Y_c"
  ### mounted somewhere else
  else
    MOPT=$(echo "$AMV_DETAILS" | sed 's/^.*(\(.*\)).*$/\1/')
  fi
  echo "$N_c - $VLABEL is already mounted \"$MOPT\" $AMV_DETAILS"

### $VLABEL is not mounted anywhere, decide on "rw" or "ro"
else
  if [ "$COPT" = "u" ] ; then
    echo "$N_c - \"$VLABEL\" is not mounted"
  else
    MOPT="ro"
    [ "$COPT" = "rw" ] && MOPT="rw"
    echo "udisks --mount /dev/disk/by-label/$VLABEL $UOPT"
    udisks --mount /dev/disk/by-label/"$VLABEL" --mount-options "$MOPT"
    _STATUS=$?
    [ $_STATUS -eq 0 ] && echo "$Y_c - $MPOINT/$VLABEL mounted ($MOPT)"
    [ $_STATUS -ne 0 ] && echo "$N_c - \"$VLABEL\""
  fi
fi
#====================================================================
maxdev137
  • 59
  • 2
0

I don't believe Gnome itself handles the mounting—it's HAL. So if HAL is running, you should be able to automount. I assume that pmount talks to HAL somehow, and that would be the way to handle unmounting. I hope this gets you started, at least.

Paul Fisher
  • 9,618
  • 5
  • 37
  • 53
  • 1
    The gnome nautilus mounts are found here `/run/user/1000/gvfs/smb-share/path-to-mount/` – CRTLBREAK Jun 09 '19 at 08:09
  • and for existing mounts it would be as follows `run/user/1000/gvfs/smb-share:server=192.168.1.100,share=share-name/path-to-folder/` – CRTLBREAK Jun 09 '19 at 08:23
0

You can also use gnome-mount for mounting / unmounting from the command line.

bluebrother
  • 8,636
  • 1
  • 20
  • 21
0

I plug in my USB device, type "gnome-volume-manager" and this seems to do what you require.

vinc456
  • 2,862
  • 5
  • 23
  • 30