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.


Solution 1:

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 lsusb to 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}%5D
    

    Replace 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%5D
    
  • If gvfs-mount doesn't work, try with fusermount:

    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.

Solution 2:

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 mtp

which 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-mtp

does the trick.