0

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

USER="masi"
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

3 Answers3

7

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).

Graipher
  • 1,191
5

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

gvfs-mount -d device

or

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)
  ids:
   unix-device: '/dev/sdb'

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

gvfs-mount --unmount /media/steeldriver/KINGSTON
steeldriver
  • 142,475
0

@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