Situation: Ubuntu-mount USB drive on the system by a terminal command, same as Ubuntu's GUI mount Configurations

# http://askubuntu.com/q/648159/25388
gsettings set org.gnome.desktop.media-handling automount-open false
  • Command ls /media/masi gives blank.
  • You see the disk icon in the panel. If you click it, the file-manager opens. Now, you can ls /media/masi and you see the disk.

My unsuccessful script

LABEL="MasiWeek" # https://unix.stackexchange.com/q/297425/16920
PARTION="sdb" #$(basename $(readlink $LABEL))
sudo mkdir -p /media/"$USER"/"$LABEL"
sudo mount /dev/"$PARTITION" /media/"$USER"/"$LABEL"
  • Output

    mount:  /dev is not a block device

System: Linux Ubuntu 16.04 64 bit
Hardware: Macbook Air 2013-mid
Related: Find kernel name for a partition when only the label is known


Your script is not working because of a spelling error in the definition of PARTITION.

Because of this, PARTITION is empty (while PARTION contains what you want) and /dev/$PARTITION becomes /dev/.

Note that the variable $USER already contains the username, so no need to set it (unless you want to do the mounting from a different user).

  • This is not what I mean by Ubuntu's mount. It is the GUI mount, not the terminal mount explicitly. – Léo Léopold Hertz 준영 Jul 27 '16 at 13:02
  • 1
    To get exactly the same thing as ubuntu's mount, see @steeldriver's answer. This was just to point out the flaw in your script (which should work with that fix, but require sudo privileges, in contrast to gvfs-mount) – Graipher Jul 27 '16 at 13:35
  • What do you think about mount -L MasiWeek /media/masi/MasiWeek? I cannot think that Ubuntu's mount works without label. – Léo Léopold Hertz 준영 Jul 27 '16 at 13:43
  • But again, the GUI mounting does not need any additional privileges, so it cannot be the normal mount, which does. – Graipher Jul 27 '16 at 13:45
  • I am not sure if there is a way for it. – Léo Léopold Hertz 준영 Jul 27 '16 at 13:45

The equivalent to the Ubuntu GUI's mount action for removable media would be

gvfs-mount -d device


gvfs-mount --device=device

where device is a block device such as /dev/sdb. Note that this command is executed as the owner of the current desktop session, and will mount the device into a directory such as /media/<user>/<label> rather than to a system-wide mount point like /mnt/<label>. For example, mounting a USB stick:

$ gvfs-mount --device=/dev/sdb
Mounted /dev/sdb at /media/steeldriver/KINGSTON

To determine the block device to use in the gvfs-mount command, you could use blkid however the cache may not accurately reflect removable devices, so you'd need to run

sudo blkid -c /dev/null

which clears the cache before enumerating the devices - but that requires administrative privileges. For a non-privileged method, you could examine the output of gvfs-mount --list --detail for a string identifying the volume - such as

Drive(2): Kingston DT Elite 3.0
  Type: GProxyDrive (GProxyVolumeMonitorUDisks2)
   unix-device: '/dev/sdb'

To unmount, you can use gvfs-mount -u or gvfs-mount --unmount e.g.

gvfs-mount --unmount /media/steeldriver/KINGSTON
  • 1
    The advantage of gvfs-mount over mount is that the former does not need sudo rights, correct? – Graipher Jul 26 '16 at 10:45
  • @cas says to use mount -L MasiWeek /media/masi/MasiWeek where label and UUID. Is it the same as gvfs-mount --device=/media/masi/MasiWeek? There is no label option in gvfs-mount. – Léo Léopold Hertz 준영 Jul 27 '16 at 13:01
  • @Masi AFAIK the --device option of gvfs-mount only takes a block device argument - I've never tried it with a label. – steeldriver Jul 27 '16 at 13:04
  • @steeldriver There is no label in gvfs-mount. What do you mean by a block device argument? – Léo Léopold Hertz 준영 Jul 27 '16 at 13:06

@cas' comment in comments is more strict than gvfs-mount because it has also label option, thus avoiding possible complications better; I think Ubuntu use's the label option for stability so I doubt if gvfs-mount --mount is used at all by default

mount -L MasiWeek /media/masi/MasiWeek

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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