Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,741,857 Members 44,551 Now Online
XDA Developers Android and Mobile Development Forum

How to setup MTP under Ubuntu

Tip us?
 
bjtheone
Old
#1  
bjtheone's Avatar
Senior Member - OP
Thanks Meter 76
Posts: 314
Join Date: Sep 2009
Location: Kanata
Default How to setup MTP under Ubuntu

This guide was created using information taken from:

http://bernaerts.dyndns.org/linux/24...unt-nexus7-mtp
http://www.webupd8.org/2012/12/how-t...-go-mtpfs.html
http://blog.itsbilal.com/index.php/2...-reliable-way/

and others. They show you how to determoine all the id information required to set up mtp mounting. This guide will just focus in on what you need to get your Asus TF700 connected.

Background:

Latest Android devices are using 2 different USB connexion modes : PTP and MTP.

With PTP mode, the tablet is seen as a digital camera. This is working Out Of The Box under Ubuntu 12.04. But, you can only access DCIM directory of your device.

With MTP mode, the tablet is seen as a multimedia device where you can access the complete exported filesystem. But it doesn't work Out Of The Box under Ubuntu. It needs some setup and configuration to work.

Note: Gvfs has been updated in Ubuntu 13.04 Raring Ringtail, bringing a new MTP backend which allows users to access Android 4.0 devices which do not support the USB Mass Storage. So this should work out of the box with Raring.

Even if you can access easily a MTP device thru a program called gmtp, it is not as convenient as a conventional USB mass storage, accessible directly from Nautilus.

This guide explains how to configure your Ubuntu computer to directly access your Asus TF700, exported filesystem in MTP mode as soon as you plug it to a USB port.

Thanks to some udev rules, your tablet will automatically mount when device is plugged in & unmount when device is unplugged.

This guide has been done for Asus TF700, but it should work with any other MTP device (Android phone or tablet, MP4 player, ...) if you adapt the Udev rules according to your device.

The Basic steps are:

1) Allow non root users to access root mounted filesystems
2) Install go_mtpfs
3) Configure udev rules to mount and unmount Android filesystems

Configuring FUSE:

Ubuntu doens't allow normal users to access fuse configuration file. This is a bug, which is quite easy to correct by giving read attribute to /etc/fuse.conf.

By default, fuse does not allow mounted filesystems to be accessed by anybody else that the user who has mounted it. As MTP filesystem will be mounted by root to be used by any user, we need to modify fuse default behaviour to allow it. This is configured by uncommenting the user_allow_other key in /etc/fuse.conf.

Code:
Select Code
# sudo chmod a+r /etc/fuse.conf
# sudo gedit /etc/fuse.conf
Code:
Select Code
/etc/fuse.conf

...
# Allow non-root users to specify the 'allow_other' or 'allow_root' mount options.
user_allow_other
Install go-mtpfs:

There are various programs to add support for mtp to Ubuntu. After trying a number of them I have found go-mtpfs works best for me. You certainly could install a different program and just adjust the guide to suit. Go-mtpfs is available in the WebUpd8 Unstable PPA, for Ubuntu 13.04, 12.10 and 12.04. Add the PPA and install it using the following commands:

Code:
Select Code
# sudo add-apt-repository ppa:webupd8team/unstable
# sudo apt-get update
# sudo apt-get install go-mtpfs
If you are not happy with installing prebuild binaries from repositories, you can easily get the source from github and build it yourself.

Once that is done you need to create a mount point for your Android filesystems. I have chosen TF700 under /media. This mount point should be accessible by anybody as you will later mount the device using your user account.

Code:
Select Code
# sudo mkdir /media/TF700
# sudo chmod 777 /media/TF700
Add the udev rules:

This is the core of making the auto mounting work. The first link I reference has all the information on how you discover the Vendor and Product ids. While it is interesting reading, I have just skipped over all that and supplied the TF700 specific values. If you are trying to setup another device you WILL NEED TO read it and get the appropriate values, as they are device specific.

Code:
Select Code
# sudo gedit /etc/udev/rules.d/51-android.rules
Code:
Select Code
# Asus TF700
SUBSYSTEM=="usb", SYSFS{idVendor}=="0b05", ATTR{idProduct}=="4c91", MODE="0666" #MTP media, USB debug on

# Asus TF700 MTP mode under JB 4.2+ : automatic mount & umount when plugged (USB debug on & off)
ENV{ID_MODEL}=="ASUS_Transformer_Pad_TF700T", ENV{ID_MODEL_ID}=="4c91", ACTION=="add", RUN+="/usr/bin/sudo -b -u YOUR_LOGIN /usr/bin/go-mtpfs -allow-other=true /media/TF700"
ENV{ID_MODEL}=="ASUS_Transformer_Pad_TF700T", ENV{ID_MODEL_ID}=="4c91", ACTION=="remove", RUN+="/bin/umount /media/TF700"
You need to change "YOUR_LOGIN" to your username.

Last thing is to restart udev for the new rules to become operationnal.

Code:
Select Code
# sudo service udev restart
Declaration in /etc/fstab:

At this stage, you are able to automatically mount and unmount your TF700. Your device should appear after few seconds in Nautilus computer section.

You can now browse your device straight from Nautilus. You can copy files from and to your TF700, you can rename files, ...

You have to know that you will face some limitations as MTP is not a real filesystem protocol :

* you can not copy files bigger than 2 Gb,
* you can not create empty files,
* you can not move file within the phone with drag & drop
* you cannot open files in write mode directly from TF700

Another problem is that you can not unmount your TF700 straight from Nautilus. If you click on the Eject button, you will get an error message saying :

umount: /media/TF700 is not in the fstab (and you are not root)

To solve that, it has to be declared in /etc/fstab with its fuse caracteristics.

As /etc/fstab is using SPACE as a separator and as our TF700 fuse caracteristics include SPACE caracter, we have to convert them to its octal escape code \040.

Code:
Select Code
# sudo gedit /etc/fstab
Code:
Select Code
/etc/fstab

...
DeviceFs(ASUS\040Transf)    /media/TF700   fuse.DeviceFs(ASUS\040Transf)    allow_other,rw,user,noauto    0    0
When you will remount it in MTP mode, your TF700 will be seen as a device. In Nautilus, it appears in the device section and you are now able to Eject it ...
bj - Samsung Galaxy SIII | Rogers | Rooted | SlimBean | TWRP
Asus tf700 | Rooted | JB-CleanROMi | TWRP
The Following 10 Users Say Thank You to bjtheone For This Useful Post: [ Click to Expand ]
 
Keshukas
Old
#2  
Keshukas's Avatar
Senior Member
Thanks Meter 41
Posts: 123
Join Date: Aug 2010
Thanks wery good info

ʞןɐʇɐdɐʇ on tf300t
 
timrock
Old
#3  
timrock's Avatar
Senior Member
Thanks Meter 175
Posts: 1,269
Join Date: Dec 2010
with 13.04, i hear where now have native support. i installed 13.04 last night, but did not test it out. i will try it tonight.
Nexus 7 (2013)
I couldn't hold out, so i rooted.

Add me on Google+
 
Xplorer4x4
Old
#4  
Xplorer4x4's Avatar
Senior Member
Thanks Meter 16
Posts: 246
Join Date: Mar 2010
Quote:
Originally Posted by timrock View Post
with 13.04, i hear where now have native support. i installed 13.04 last night, but did not test it out. i will try it tonight.
Didn't work for me on my Droid Razr HD but the OPs tutorial was pretty useful.

Few questions though:
Quote:
1. you can not create empty files,
2. you can not move file within the phone with drag & drop
1. Does this apply to folders as well?
2. What about cut and paste? I swear it worked for me.
Phone: Motorola Droid Razr HD
ROM: OSE with arrrghhh's kernel
 
timrock
Old
#5  
timrock's Avatar
Senior Member
Thanks Meter 175
Posts: 1,269
Join Date: Dec 2010
Quote:
Originally Posted by Xplorer4x4 View Post
Didn't work for me on my Droid Razr HD but the OPs tutorial was pretty useful.

Few questions though:

1. Does this apply to folders as well?
2. What about cut and paste? I swear it worked for me.
worked fine with my tf700, galaxy nexus, nexus 7 and my daughter samsung galaxy tab 2
Nexus 7 (2013)
I couldn't hold out, so i rooted.

Add me on Google+
 
fcastillousfq
Old
#6  
Member
Thanks Meter 8
Posts: 53
Join Date: Sep 2011
Location: Montreal

 
DONATE TO ME
As some extra help. I hate to see the device always present in Nautilus even if it's not mounted, because of fstab. So as a workaround (which is not the best way I imagine) I modified the udev rules file and the fstab file.

Quote:
Originally Posted by bjtheone View Post

Code:
Select Code
# sudo gedit /etc/udev/rules.d/51-android.rules
Code:
Select Code
# Asus TF700 MTP mode under JB 4.2+ : automatic mount & umount when plugged (USB debug on & off)
ENV{ID_MODEL}=="ASUS_Transformer_Pad_TF700T", ENV{ID_MODEL_ID}=="4c91", ACTION=="add", RUN+="/usr/bin/sudo -b -u YOUR_LOGIN /usr/bin/go-mtpfs -allow-other=true /media/TF700"
ENV{ID_MODEL}=="ASUS_Transformer_Pad_TF700T", ENV{ID_MODEL_ID}=="4c91", ACTION=="remove", RUN+="/bin/umount /media/TF700"
I changed it as follows:

Code:
Select Code
# Asus TF700 MTP mode under JB 4.2+ : automatic mount & umount when plugged (USB debug on & off)
ENV{ID_MODEL}=="ASUS_Transformer_Pad_TF700T", ENV{ID_MODEL_ID}=="4c91", ACTION=="add", RUN+="/path/to/mount_script.sh"
ENV{ID_MODEL}=="ASUS_Transformer_Pad_TF700T", ENV{ID_MODEL_ID}=="4c91", ACTION=="remove", RUN+="/path/to/unmount_script.sh"
The mount_script.sh contains:

Code:
Select Code
#!/bin/sh
/bin/sed -i 's|#DeviceFs(ASUS\040Transf)|DeviceFs(ASUS\040Transf)|' /etc/fstab
/usr/bin/sudo -b -u YOUR_LOGIN /usr/bin/go-mtpfs -allow-other=true /media/TF700
and the unmount_script.sh:

Code:
Select Code
#!/bin/sh
/bin/sed -i 's|DeviceFs(ASUS\040Transf)|#DeviceFs(ASUS\040Transf)|' /etc/fstab
/bin/umount /media/TF700
Now to make sense of the previous scripts, the fstab file has to change just a little. The extra line previously added has to be commented. That way the mount script will uncomment that line, making your device unmountable by the user and showing under the devices section, and when removed the unmount script will comment the same line so it won't show in that section any more.
Just to be sure, here's how the fstab looks (note the [B]#[/B in front of the line)]:

Code:
Select Code
/etc/fstab

...
#DeviceFs(ASUS\040Transf)    /media/TF700   fuse.DeviceFs(ASUS\040Transf)    allow_other,rw,user,noauto    0    0

Make sure you restart your udev so the new scripts can work, using with

Code:
Select Code
# sudo service udev restart
The Following User Says Thank You to fcastillousfq For This Useful Post: [ Click to Expand ]
 
eris170
Old
#7  
Junior Member
Thanks Meter 1
Posts: 15
Join Date: Aug 2013
Default Great tutorial but go-mtpfs is buggy

How come there are files that don't show up when I mount the go-mtpfs directory? For instance, when I navigate to SD Card/DCIM/Camera over the go-mtpfs mount,there is nothing there. if I connect to a shell over adb, I can see the files are clearly there. I thought it may be filesystem corruption however issuing adb pull of the Camera directory does indeed retrieve the correct files.

Tags
mtp, ubuntu
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


XDA PORTAL POSTS

Enjoy Wallpaper Overload with PhotoPhase

We don’t usually feature live wallpapers on the XDA Portal unless they are somewhat innovative … more

Monitor What Your Phone’s Camera Sees with Android Wear

Having a smart device strapped to your wrist certainly has its merits. A … more

Mod Lets You Have Stereo Speakers on Your Sony Xperia Z1 (Sort Of)

The stereo speakers onthe Sony Xperia Z2areprobably a relatively large … more

Give Your Screen Some Color with HexaTime Live Wallpaper

We don’t often cover very many live wallpapers here on the XDA Portal. You may … more