How to unmount MTP USB device from command line
I have both the Bus and Device numbers for a USB device I want to unmount.
I tried resetting the USB device like so
How do you reset a USB device from the command line?
but it doesn't unmount it from the desktop.
14 Answers
MTP devices are mounted via gvfs (gnome virtual filesystem).
You'll need to use the propper tools for managing gvfs, like gvfs-mount or fusermount.
First use
lsusbto get your mtp device number and bus number. I think you already have this.Simple example using lsusb+grep for a Nexus 4:
$ lsusb | grep Google Bus 002 Device 025: ID 18d1:4ee2 Google Inc.Then use
gvfs-mount:gvfs-mount -u /run/user/1000/gvfs/mtp:host=%5Busb%3A{busnumber}%2C{deviceNumber}%5DReplace busNumber and deviceNumber, also remove the brackets.
You should end with something like:
gvfs-mount -u /run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C025%5DIf
gvfs-mountdoesn't work, try withfusermount:fusermount -u /run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C025%5D
Hope it helps.
UPDATE: Sorry,gvfs-mount and fusermount seems to be designed to work without sudo as they are intended to manage fuse-based mounts by non admin users.
UPDATE 2: I observed the correct path is : /run/user/1000/gvfs/, while testing by myself on Ubuntu 16.04/16.10 , using 1000 instead of yourUsername.
I was asking the wrong question.
Instead of figuring out how to unmount the device, I needed to find out what process or daemon was claiming it.
I issued
ps aux | grep mtpwhich gave me a few mtp related processes and compared with the camera mounted and unmounted to get the specific process
and then
pkill -9 gvfsd-mtpdoes the trick.
You can use
dfto find all mounted devices, and you get more information if you run the following command
sudo lsblk -for even better in a wide terminal window (if necessary)
sudo lsblk -fmWhen you have identified the USB device, you can unmount it with the following command line
sudo umount /dev/sdxnwhere x is the drive letter and n is the partition number, for example '/dev/sdb1'
-o-
This is unmount. The buffers are flushed, so it is safe to unplug the device. The device has still power on, so it can be 'seen on the desktop', and it can be mounted again. This is different from eject. An ejected pendrive will be powered off, and must be unplugged and plugged in again if you want to mount it.
You can unmount by using below commands, First check list of all the blocks and mount paths. lsblk
sudo umount /dev/sdb