Early Lollipop Ports for Micromax A116 and A117

It feels like it was only yesterday when Google announced the mysterious Android L.After … more

Now Gesture Tweaks Replaces Google Now with Custom Action

On most modern Android devices with software navigation keys, swiping up from the … more

ToqAN Fixes Android 5.0 Notification Bug on Qualcomm Toq

The Qualcomm Toq is probably one of the lesser known smartwatches on the market … more

How to Root and Unlock the Google Nexus 6 on a Mac – XDA TV

In the past, XDA Developer TV Producer droidmodd3rx has shown you how to … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

How to setup MTP under Ubuntu

OP bjtheone

6th April 2013, 04:18 PM   |  #1  
bjtheone's Avatar
OP Senior Member
Flag Kanata
Thanks Meter: 78
 
323 posts
Join Date:Joined: Sep 2009
More
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:
# sudo chmod a+r /etc/fuse.conf
# sudo gedit /etc/fuse.conf
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:
# 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:
# 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:
# sudo gedit /etc/udev/rules.d/51-android.rules
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:
# 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:
# sudo gedit /etc/fstab
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 ...
The Following 10 Users Say Thank You to bjtheone For This Useful Post: [ View ]
9th April 2013, 03:13 PM   |  #2  
Keshukas's Avatar
Senior Member
Thanks Meter: 43
 
132 posts
Join Date:Joined: Aug 2010
Thanks wery good info

ʞןɐʇɐdɐʇ on tf300t
26th April 2013, 07:37 PM   |  #3  
timrock's Avatar
Senior Member
Thanks Meter: 176
 
1,290 posts
Join Date:Joined: 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.
13th May 2013, 01:13 AM   |  #4  
Xplorer4x4's Avatar
Senior Member
Thanks Meter: 24
 
309 posts
Join Date:Joined: Mar 2010
More
Quote:
Originally Posted by timrock

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.
14th May 2013, 07:02 PM   |  #5  
timrock's Avatar
Senior Member
Thanks Meter: 176
 
1,290 posts
Join Date:Joined: Dec 2010
Quote:
Originally Posted by Xplorer4x4

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
13th July 2013, 10:58 PM   |  #6  
Member
Flag Montreal
Thanks Meter: 10
 
59 posts
Join Date:Joined: Sep 2011
Donate to Me
More
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


Code:
# sudo gedit /etc/udev/rules.d/51-android.rules
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:
# 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:
#!/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:
#!/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:
/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:
# sudo service udev restart
The Following User Says Thank You to fcastillousfq For This Useful Post: [ View ]
12th September 2013, 04:06 AM   |  #7  
Junior Member
Thanks Meter: 1
 
15 posts
Join Date:Joined: Aug 2013
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.

Post Reply Subscribe to Thread

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

Advanced Search
Display Modes