You are not logged in.

#1 2012-12-04 20:08:08

frix
Member
Registered: 2011-05-02
Posts: 23

Automounting MTP devices

Hi all,

I tried a lot of techniques to mount MTP devices (such as the latest Android devices without a SD card) automatically when plugged-in. gvfs-gphoto2 kinda worked, but for me it was dreadfully slow, and the only reliable solution, at this time, was to use go-mtpfs. But then it's not automatic, you have to type horribly complicated commands in a terminal! Yuck.

In the PKGBUILD below, a few UDEV rules to fix that. They currently only work with the devices I got (Nexus 7 and Galaxy Nexus, both on CyanogenMod 10), so they definitely won't work on anything else, which is why I didn't submit them right now to the AUR. I just wanted to share them in case anybody was interested. And since it's my first PKGBUILD (hurray!), do share any tips you might have regarding, oh, I don't know, something I might have forgotten, a rule I didn't know about, or something that could be done better.

Cheers!

Package source: https://github.com/fxthomas/android-aut … ter.tar.gz

Offline

#2 2012-12-17 08:27:23

tyler1234567
Member
Registered: 2012-10-18
Posts: 8

Re: Automounting MTP devices

just came here to spread the word after i stumbled across this! Holy crap it is just what I needed for my Galaxy Nexus!

Offline

#3 2012-12-17 13:38:19

frix
Member
Registered: 2011-05-02
Posts: 23

Re: Automounting MTP devices

Glad to hear somebody's using it wink

It should be able to work with any Android device by the way, but as I said it needs an additional rule for each different device, and I don't have the product/vendor IDs here. If you have such a device besides your Galaxy Nexus, just reply here and I'll update the list.

Offline

#4 2013-01-10 21:55:13

jonnybel
Member
Registered: 2011-11-21
Posts: 20

Re: Automounting MTP devices

Hi, I have a Sony Xperia U with Android 4.0 and haven't tested this yet, but here is my info for the device from the output of lsusb:

Bus 002 Device 010: ID 0fce:4171 Sony Ericsson Mobile Communications AB 

EDIT:
I've found that jmtpfs fulfills my needs and its very simple to use, and it's available in AUR.
If you've haven't tried it, give it a shot!

Last edited by jonnybel (2013-01-10 22:13:36)

Offline

#5 2013-01-10 23:49:31

oliver
Member
Registered: 2007-12-12
Posts: 420

Re: Automounting MTP devices

I was looking for how to mount my HP Touchpad and found this thread - so thanks for posting.  I modified your 99-android-mtp.rules file with the following (in the appropriate blocks of course)

# HP Touchpad 32GB (HTC (High Tech Computer Corp.))
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="685c", MODE="0666"


# HP Touchpad 32GB (HTC (High Tech Computer Corp.))
ENV{ID_MODEL_ID}=="685c", ENV{ID_VENDOR_ID}=="0bb4", ACTION=="remove", RUN+="/usr/bin/systemctl stop 'android-mtp@$env{ID_MODEL}.service'"


# HP Touchpad 32GB (HTC (High Tech Computer Corp.))
ENV{ID_MODEL_ID}=="685c", ENV{ID_VENDOR_ID}=="0bb4", ACTION=="add", RUN+="/usr/bin/systemctl start 'android-mtp@$env{ID_MODEL}.service'"

One thing that confused me though... after installing the pkg, I plugged the TP in and it was mounted automatically... do I even need to enable the service file?

Offline

#6 2013-01-11 08:01:12

frix
Member
Registered: 2011-05-02
Posts: 23

Re: Automounting MTP devices

jonnybel wrote:
Bus 002 Device 010: ID 0fce:4171 Sony Ericsson Mobile Communications AB 

This is just the info relative to where (on which USB port) the device is mounted, not the Vendor/Product ID.

I've found that jmtpfs fulfills my needs and its very simple to use, and it's available in AUR.
If you've haven't tried it, give it a shot!

Well, from what I remember jmtpfs works roughly the same as gomtpfs : you type the command in a terminal and the device is mounted. Did they add an automount feature for jmtpfs?

oliver wrote:

I was looking for how to mount my HP Touchpad and found this thread - so thanks for posting.  I modified your 99-android-mtp.rules file with the following (in the appropriate blocks of course)

# HP Touchpad 32GB (HTC (High Tech Computer Corp.))
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="685c", MODE="0666"


# HP Touchpad 32GB (HTC (High Tech Computer Corp.))
ENV{ID_MODEL_ID}=="685c", ENV{ID_VENDOR_ID}=="0bb4", ACTION=="remove", RUN+="/usr/bin/systemctl stop 'android-mtp@$env{ID_MODEL}.service'"


# HP Touchpad 32GB (HTC (High Tech Computer Corp.))
ENV{ID_MODEL_ID}=="685c", ENV{ID_VENDOR_ID}=="0bb4", ACTION=="add", RUN+="/usr/bin/systemctl start 'android-mtp@$env{ID_MODEL}.service'"

Thanks, I'll add it!

One thing that confused me though... after installing the pkg, I plugged the TP in and it was mounted automatically... do I even need to enable the service file?

No, it is started automatically by the UDev rules afaik.

Offline

#7 2013-01-11 13:23:49

oliver
Member
Registered: 2007-12-12
Posts: 420

Re: Automounting MTP devices

frix wrote:

One thing that confused me though... after installing the pkg, I plugged the TP in and it was mounted automatically... do I even need to enable the service file?

No, it is started automatically by the UDev rules afaik.

thanks... makes sense now.  I like stuff you don't have to think about

Offline

#8 2013-01-11 14:08:19

Šaran
Member
From: Bosnia
Registered: 2011-09-03
Posts: 407

Re: Automounting MTP devices

With this method you just plug the phone out when finished, right? No need to unmount?

Offline

#9 2013-01-11 14:17:39

frix
Member
Registered: 2011-05-02
Posts: 23

Re: Automounting MTP devices

Šaran wrote:

With this method you just plug the phone out when finished, right? No need to unmount?

Yes, that's the whole point of MTP if I understood things correctly. Basically all you do are "push" and "pull" (cf. same commands with adb) operations, which are guaranteed to either work or write nothing. But feel free to correct me if I'm saying nonsense, I'm not really an expert!

Last edited by frix (2013-01-11 14:18:09)

Offline

#10 2013-01-13 12:28:13

farnsworth
Member
Registered: 2012-01-28
Posts: 17

Re: Automounting MTP devices

Thanks for you Package, I was trying to use go-mtpfs and a single rules file (adapted from http://bernaerts.dyndns.org/linux/247-u … exus7-mtp) in /etc/udev/rules.d without success.

I've made a few modifications based on http://hackaday.com/2009/09/18/how-to-write-udev-rules/ in your /usr/bin/mtp file to have mount and unmount notifications under Gnome Shell.
There's a problem, unmount notifications doesn't work, if you have an idea...
here is the modified file:

#!/bin/bash
# Base Script File (android-mtp.sh)
# Created: Tue 04 Dec 2012 06:44:50 PM CET
# Version: 1.0
# Author: François-Xavier Thomas <fx.thomas@gmail.com>
#
# This Bash script was developped by François-Xavier Thomas.
# You are free to copy, adapt or modify it.
# If you do so, however, leave my name somewhere in the credits, I'd appreciate it ;)

GO_MTPFS=/usr/bin/go-mtpfs
DEVICE_NAME=${2//_/ }

GSuser=$(ps -ef | grep -w /usr/bin/gnome-shell | grep -v grep | awk '{print $1'})
GSpid=$(ps -ef | grep -w /usr/bin/gnome-shell | grep -v grep | awk '{print $2'})
DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$GSpid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`

case $1 in
  start|mount)
    echo "Mounting MTP device on /media/$DEVICE_NAME"
    /bin/mkdir -p "/media/$DEVICE_NAME"
    /usr/sbin/daemonize -l /var/lock/go-mtpfs.$2.lock /usr/bin/go-mtpfs -allow-other=true "/media/$DEVICE_NAME"
    if [ -r "/home/$GSuser/Images/$DEVICE_NAME.png" ]
    then
      sudo -b -u $GSuser DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS notify-send --hint=int:transient:1 -t 6000 "$DEVICE_NAME monté sous /media/$DEVICE_NAME" -i "/home/$GSuser/Images/$DEVICE_NAME.png"
    else
      sudo -b -u $GSuser DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS notify-send --hint=int:transient:1 -t 6000 "$DEVICE_NAME monté sous /media/$DEVICE_NAME"
    fi
    ;;
  stop|unmount)
    echo "Unmounting MTP device on /media/$DEVICE_NAME"
    /bin/umount "/media/$DEVICE_NAME"
    /bin/rmdir "/media/$DEVICE_NAME"
    if [ -r "/home/$GSuser/Images/$DEVICE_NAME.png" ]
    then
      sudo -b -u $GSuser DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS notify-send --hint=int:transient:1 -t 6000 "$DEVICE_NAME démonté" -i "/home/$GSuser/Images/$DEVICE_NAME.png"
    else
      sudo -b -u $GSuser DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS notify-send --hint=int:transient:1 -t 6000 "$DEVICE_NAME démonté"
    fi
    ;;
  *)
    echo "Usage: android-mtp start device-name"
    ;;
esac

Another problem, if the device is locked (I'm using the schema lock) it will not mount (it try to mount, fail, then unmount), Is there a way to send a notification to the user telling him to disconnect, unlock and retry? I'm anable to find a way to do this.

Last edited by farnsworth (2013-01-13 12:38:12)

Offline

#11 2013-01-13 21:34:03

frix
Member
Registered: 2011-05-02
Posts: 23

Re: Automounting MTP devices

Wow, I've never really used notify-send, but this looks quite nice! If you make a pull request on GitHub I'll accept it once I've got it tested.

Your first link most likely failed because, on Arch, Udev kills any process that takes too long in the RUN command.
Your second link has an interesting paragraph about unmounting. Right now it does fail when ejecting from Nautilus, I hadn't thought about adding a line to fstab.

If the device is locked then the go-mtpfs daemon will most likely exit right away, so maybe it'll return an useful exit code, in which case you can do it with notify-send. This is just speculation for now, I haven't really tested it.

Last edited by frix (2013-01-13 21:34:35)

Offline

#12 2013-01-15 07:30:50

farnsworth
Member
Registered: 2012-01-28
Posts: 17

Re: Automounting MTP devices

You're asking me too much wink I don't know how to use GitHub, I'm not familiar with this kind of tool, I'll try to create an account but I'm not sure of the result.
For the lock problem maybe the solution is to detach the notification in a script, do a small sleep, then check the device to see if it is mounted or not, I'll try this...

Offline

#13 2013-03-10 15:08:57

manouchk
Member
Registered: 2008-07-29
Posts: 212

Re: Automounting MTP devices

I've been struggling  quite a lot here with MTP on a samsung tab 10.1. Seems that mtp lib is to old from a gentoo discussion. http://forums.gentoo.org/viewtopic-t-92 … rt-25.html

I also found a solution there by using airdroid which makes it possible to share files between android and linux easily and gives remote control of the android device amazing. I will look later at mtp related stuff but I think that mtp lib 1.5 maybe too old and should be updated.

I'm now using http://airdroid.com/ and  don't need to connect my android to my computer. This problem leads me to a better solution to the one I was seeking!!

For now this is my solution. I will try aur/libmtp-git later.

Offline

#14 2013-03-11 19:32:18

Šaran
Member
From: Bosnia
Registered: 2011-09-03
Posts: 407

Re: Automounting MTP devices

I have just configured udev rules to run script from OP. It works perfectly every time and go-mtpfs is way faster than mtpfs (which crashes a lot).

Offline

#15 2014-04-16 19:09:00

karsten
Member
Registered: 2006-07-14
Posts: 261

Re: Automounting MTP devices

so if I understand this procedure correctly there's no need to unmount the device?  just unplug it and everything will be there?  can confirm auto-mount works great for Samsung S3 with file provided.

Offline

#16 2014-04-17 14:35:05

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 13,425

Re: Automounting MTP devices

karsten,
Be aware that this is a really old thread.  Generally, I would suggest you start a new thread and link back to this one, but as you asked a direct question, those who have posted that may be following this thread would not receive notification if we we were to do it that way.   I am going to leave the thread open for now, but I have not seen some of the original participants for a while.
Thanks.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
You assume people are rational and influenced by evidence.  You must not work with the public much. -- Trilby
----
How to Ask Questions the Smart Way

Online

Board footer

Powered by FluxBB