How to connect Samsung Galaxy Nexus to Ubuntu 12.04 LTS using MTP

Samsung Galaxy Nexus USB computer connection settings
Samsung Galaxy Nexus USB computer connection settings
Trying to connect and  transfer files between my Ubuntu desktop and my Samsung Galaxy Nexus was a pain in the ass. It seems that my Samsung Galaxy Nexus is unable to mount to my Ubuntu desktop at all. After a long search in the internet, i found a customized solution to this problem.

When an Android is connected to Ubuntu Linux through Media Transfer Protocol (MTP), Ubuntu will try to mount the Android using gvfs through gphoto2 but because gvfs does not have native support for MTP yet, it doesn't always work properly. You will probably see this error whenever you try to browse the Android device (that seems like it mounted) from Nautilus:
"Sorry, could not display all the contents of "Android": Timeout was reached"
When it did work, it work very sluggishly and unreliably.

An alternative is to use mtpfs but that too has been reported unstable lately. Because of this, a Google employee created his own mtpfs called go-mtpfs. I tried go-mtpfs and it works great and fast too.

This is how you can setup your Ubuntu 12.04 LTS to connect your Samsung Galaxy Nexus using MTP:

Install go-mtpfs
  • Run this commands to install go-mtpfs
sudo add-apt-repository ppa:webupd8team/unstable
sudo apt-get update
sudo apt-get install go-mtpfs
  • Configure fuse
sudo chmod a+r /etc/fuse.conf
sudo gedit /etc/fuse.conf
  • Un-comment the user_allow_other line in the file. This is to allow Ubuntu to allow non-root users to use fuse to mount the MTP filesystem. This is how the line look like in the file:
...
# Allow non-root users to specify the 'allow_other' or 'allow_root' mount options.
# user_allow_other
  • To mount, use this command line:
go-mtpfs /media/MyAndroid
  • To unmount, use this command line:
fusermount -u /media/MyAndroid

Setup Auto-mounting
  • Create a mount point
sudo mkdir /media/GalaxyNexus
sudo chmod 777 /media/GalaxyNexus
  • Run udev monitoring to get device information
udevadm monitor --environment --udev
  • Set your Samsung Galaxy Nexus in MTP mode.
  • Plug in your Samsung Galaxy Nexus.
  • Wait for a few seconds or until the monitor produce some results when the device is plugged in.
  • Un-plug your Samsung Galaxy Nexus.
  • You will get results that look like this:
CommandLine$>> udevadm monitor --environment --udev
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing

UDEV  [3790.512388] add      /devices/pci0000:00/0000:00:02.1/usb1/1-10 (usb)
ACTION=add
BUSNUM=001
COLORD_DEVICE=1
COLORD_KIND=camera
DEVLINKS=/dev/libmtp-1-10
DEVNAME=/dev/bus/usb/001/008
DEVNUM=008
DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-10
DEVTYPE=usb_device
GPHOTO2_DRIVER=proprietary
ID_BUS=usb
ID_GPHOTO2=1
ID_MEDIA_PLAYER=1
ID_MODEL=Galaxy_Nexus
ID_MODEL_ENC=Galaxy\x20Nexus
ID_MODEL_ID=685c
ID_MTP_DEVICE=1
ID_REVISION=0216
ID_SERIAL=samsung_Galaxy_Nexus_0149C25E1201300B
ID_SERIAL_SHORT=0149C25E1201300B
ID_USB_INTERFACES=:ffff00:
ID_VENDOR=samsung
ID_VENDOR_ENC=samsung
ID_VENDOR_ID=04e8
MAJOR=189
MINOR=7
PRODUCT=4e8/685c/216
SEQNUM=2043
SUBSYSTEM=usb
TAGS=:udev-acl:
TYPE=0/0/0
UDEV_LOG=3
USEC_INITIALIZED=3790495491

UDEV  [3790.567675] add      /devices/pci0000:00/0000:00:02.1/usb1/1-10/1-10:1.0 (usb)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-10/1-10:1.0
DEVTYPE=usb_interface
INTERFACE=255/255/0
MODALIAS=usb:v04E8p685Cd0216dc00dsc00dp00icFFiscFFip00
PRODUCT=4e8/685c/216
SEQNUM=2044
SUBSYSTEM=usb
TYPE=0/0/0
UDEV_LOG=3
USEC_INITIALIZED=3790525581

UDEV  [3790.650223] add      /devices/virtual/bdi/0:22 (bdi)
ACTION=add
DEVPATH=/devices/virtual/bdi/0:22
SEQNUM=2045
SUBSYSTEM=bdi
UDEV_LOG=3
USEC_INITIALIZED=3790649842

UDEV  [3800.498944] remove   /devices/pci0000:00/0000:00:02.1/usb1/1-10/1-10:1.0 (usb)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-10/1-10:1.0
DEVTYPE=usb_interface
INTERFACE=255/255/0
MODALIAS=usb:v04E8p685Cd0216dc00dsc00dp00icFFiscFFip00
PRODUCT=4e8/685c/216
SEQNUM=2046
SUBSYSTEM=usb
TYPE=0/0/0
UDEV_LOG=3
USEC_INITIALIZED=3800498412

UDEV  [3800.513880] remove   /devices/virtual/bdi/0:22 (bdi)
ACTION=remove
DEVPATH=/devices/virtual/bdi/0:22
SEQNUM=2048
SUBSYSTEM=bdi
UDEV_LOG=3
USEC_INITIALIZED=3800513458

UDEV  [3800.542165] remove   /devices/pci0000:00/0000:00:02.1/usb1/1-10 (usb)
ACTION=remove
BUSNUM=001
COLORD_DEVICE=1
COLORD_KIND=camera
DEVLINKS=/dev/libmtp-1-10
DEVNAME=/dev/bus/usb/001/008
DEVNUM=008
DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-10
DEVTYPE=usb_device
GPHOTO2_DRIVER=proprietary
ID_BUS=usb
ID_GPHOTO2=1
ID_MEDIA_PLAYER=1
ID_MODEL=Galaxy_Nexus
ID_MODEL_ENC=Galaxy\x20Nexus
ID_MODEL_ID=685c
ID_MTP_DEVICE=1
ID_REVISION=0216
ID_SERIAL=samsung_Galaxy_Nexus_0149C25E1201300B
ID_SERIAL_SHORT=0149C25E1201300B
ID_USB_INTERFACES=:ffff00:
ID_VENDOR=samsung
ID_VENDOR_ENC=samsung
ID_VENDOR_ID=04e8
MAJOR=189
MINOR=7
PRODUCT=4e8/685c/216
SEQNUM=2047
SUBSYSTEM=usb
TAGS=:udev-acl:
TYPE=0/0/0
UDEV_LOG=3
USEC_INITIALIZED=3790495491
  • Create a udev rules file.
sudo gedit /etc/udev/rules.d/99-android.rules &
  • Replace all the fields highlighted in red with the values that you get from your Samsung Galaxy Nexus udev values. Take note of the values highlighted in yellow.
# Google Galaxy Nexus MTP mode (multimedia device)
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="685c", MODE="0666" # MTP media

# Google Galaxy Nexus MTP mode : automatic mount when plugged (all android versions)
ENV{ID_MODEL}=="Galaxy_Nexus", ENV{ID_MODEL_ID}=="685c", ACTION=="add", RUN+="/usr/bin/sudo -b -u libos /usr/bin/go-mtpfs -allow-other=true /media/GalaxyNexus"

# Google Galaxy Nexus MTP mode : automatic unmount when unplugged (all android versions)
ENV{ID_MODEL}=="Galaxy_Nexus", ENV{ID_MODEL_ID}=="685c", ACTION=="remove", RUN+="/bin/fusermount -u /media/GalaxyNexus"
  • Restart the udev service.
sudo service udev restart
  • You can now plug in your Samsung Galaxy Nexus and your Ubuntu 12.04 LTS will auto mount. To unmount, just unplug your Samsung Galaxy Nexus.


Manual Mounting
To make life easier without using command line, Andrew from WEB UPD8 that helped package go-mtpfs for this installation also wrote a custom Unity-launcher script to mount and unmount. 
  • To get this custom Unity-launcher script, run this command to install:
sudo apt-get install go-mtpfs-unity
  • Search your Dash Home for "Mount Android" and drag the icon to the Unity launcher. 
  • Right click it for selections of to mount or unmount.

Important notes about MTP limitation:

  • File copy is limited to 2GB in size.
  • Empty file creation is not allowed.


References, Sources and Credits:
  1. http://www.webupd8.org/2012/12/how-to-mount-android-40-ubuntu-go-mtpfs.html
  2. http://blog.itsbilal.com/index.php/2012/12/connect-an-android-4-0-phonetablet-to-ubuntu-the-reliable-way/
  3. http://www.omgubuntu.co.uk/2011/12/how-to-connect-your-android-ice-cream-sandwich-phone-to-ubuntu-for-file-access
  4. https://github.com/hanwen/go-mtpfs
  5. http://bernaerts.dyndns.org/linux/247-ubuntu-automount-nexus7-mtp
  6. http://research.jacquette.com/jmtpfs-exchanging-files-between-android-devices-and-linux/
  7. https://bugs.launchpad.net/ubuntu/+source/udev/+bug/903422


Comments

  1. Very helpful.. Thank you man.. :)

    ReplyDelete
  2. Finally I can copy files to and from my GNex easily! You and that Google employee made my day!

    Thanks a lot :)

    ReplyDelete
  3. Ubuntu 12.04 64 bit + Galaxy Nexus + this post = happy me :)

    Thank you!

    ReplyDelete
  4. I followed this guide but still not happy. i get this message when i connect my Samsung galaxy nexus
    Sorry, could not display all the contents of "Galaxy Nexus": DBus error org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
    Did i do something wrong ?

    ReplyDelete
    Replies
    1. Hi pantelis,

      I did not face this issue but from this forum thread, could it be the cause of your error message?
      http://rootzwiki.com/topic/31136-problem-mounting-my-nexus-to-my-computer/

      Delete
  5. Hi,

    My OS is Ubuntu 12.04.3 LTS & installed with the latest go-mtpfs package from ppa:nilarimogard/webupd8 repository

    go-mtpfs run fine in terminal to access my Samsung Galaxy S4 Android phone. The same scripts are used in the udev rule:-
    ---------------------------------------------------
    ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", ENV{ID_SERIAL_SHORT}=="811f75d6", SYMLINK+="SamGalS4", MODE="0666", RUN+="/bin/bash -c 'touch /tmp/samgals4;/usr/bin/go-mtpfs -allow-other=true /media/MyAndroid &'"

    ACTION=="remove", SUBSYSTEM=="usb", ENV{ID_SERIAL_SHORT}=="811f75d6", RUN+="/bin/bash -c 'pkill go-mtpfs; fusermount -u /media/MyAndroid; rm /tmp/samgals4'"
    ---------------------------------------------------

    udev ACTION=="add" is triggered after I plugged in the phone by:-
    ls /media/MyAndroid; ls /dev/Sam*; ls /tmp/sam*
    /dev/SamGalS4 <--- trigger by SYMLINK+=
    /tmp/samgals4 <--- trigger by RUN+=

    udev ACTION=="remove" is triggered after I unplugged in the phone by:-
    ls /media/MyAndroid; ls /dev/Sam*; ls /tmp/sam*
    ls: cannot access /dev/Sam*: No such file or directory <--- trigger by action
    ls: cannot access /tmp/sam*: No such file or directory <--- trigger by RUN+=

    The problem I'm facing is go-mtpfs is not executed by RUN+= for unknown reason.
    ls /media/MyAndroid <--- did not display anything

    I confirmed udev rule trigger & the script is working fine by running the same script in terminal after I plugged in the phone:-
    /bin/bash -c 'touch /tmp/samgals4;/usr/bin/go-mtpfs -allow-other=true /media/MyAndroid &'

    ls /media/MyAndroid; ls /dev/Sam*; ls /tmp/sam*
    Card Phone <---- phone storage
    /dev/SamGalS4
    /tmp/samgals4

    Please help.

    ReplyDelete

Post a Comment

Popular posts from this blog

City Code Table for Casio SGW300HD-1AV Watch

How to force only 4G or LTE network connection for Samsung Galaxy Note 4

Mounting NFS share directory from D-link DNS 320L on Ubuntu 12.04 LTS