Samstag, 20. Oktober 2012

Nexus 7 MTP automount on OpenSuse 11.4

Unfortunately Android 4.x devices cannot be mounted as a VFAT device any longer. While with 4.0 only the PTP mode is supported (which can be used to transfer photos only), on 4.1 you can switch between PTP mode and MTP mode in the settings.

While Windows has an acceptable MTP support, on Linux systems MTP is not supported out of the box, even worse if you want to automount your android device when connecting it. Looking around, I found Han-Wen Nienhuys go-mtpfs project on Github.


install mtpfs support

go-mtpfs is based on libmtp. For OpenSuse 11.4 you need to download the latest rpm from pbone.net and to install it on your system

After that, you can either checkout the go-mtpfs project from github and compile it by yourself or, probably more easy, download the binary from here.

You can install the binaries in every place you like, but it should be either on your path configuration or you need to define the full path to the binary when using it.


configure automount

Automount on current Linux systems is initiated by the udev system. In /etc/udev/rules.d/ you will find a set of rules which define what should happen when a new device is added, removed, ...

Create or modify a new ruleset, i.e./etc/udev/rules.d/50-android.rules. Here we need to add the following rules regarding the Nexus 7 device:


# Google Nexus 7 16 Gb Bootloader & recovery mode
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0666" # Bootloader
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d001", MODE="0666" # Recovery

# Google Nexus 7 16 Gb PTP mode (camera)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e43", MODE="0666" # PTP media
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e44", MODE="0666" # PTP media with USB debug on

# Google Nexus 7 16 Gb MTP mode (multimedia device)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e41", MODE="0666" # MTP media
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0666" # MTP media with USB debug on

# Google Nexus 7 MTP mode : automatic mount when plugged
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e41", ACTION=="add", RUN+="/usr/bin/sudo -u /go-mtpfs /media/nexus7"
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e42", ACTION=="add", RUN+="/usr/bin/sudo -u /go-mtpfs /media/nexus7"

# Google Nexus 7 MTP mode : automatic unmount when unplugged
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e41", ACTION=="remove", RUN+="/usr/bin/fusermount -u /media/nexus7"
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e42", ACTION=="remove", RUN+="/usr/bin/fusermount -u /media/nexus7"

Be sure, that the mount point /media/nexus7 exists and is accessable for your user.

After sudo /etc/init.d/boot.udev restart your Nexus 7 device should be mounted automatically to /media/nexus7 when plugged to your PC.

If you want to mount other devices, you only need to add the corresponding rules, i.e. you need to know the corresponding idVendor/idProduct values. Those you can figure out using the dmesg command after the device is plugged.

4 Kommentare:

  1. :)
    I compiled the go compiler and this for Ubuntu 11.10, it mosty worked but it does suck.. I found it slow, didn't always mount and there are some pretty awful limits with mtp like moving files on the device, time stamps and stuff.
    I kinda gave up on it
    I mostly use AndFTP now, that and a combination of Bluetooth/dropbox for phone/tablet transfers

    Recently started serving media over NFS, which works great with mx player, i mount the NFS to /storage/usbdisk ;)
    I plan on serving from the nexus 7 via NFS but neglected to config the server in the kernel last time. I don't think I will ever really use that much tbh, simpler to Bluetooth/dropbox or use kws webserver

    AntwortenLöschen
    Antworten
    1. Up to now I didn't have problems with not mounting / beeing too slow, but you are right, it's not the best solution to transfer from/to PC. NFS might be ok, but over the air it's too slow fro me:( The same is for ftp / bluetooth / dropbox: Having a 54 Mbit connection, more than 2-3 MB / sec is not possible. Using MTP it's almost ten times faster.

      Löschen
  2. A quick note: your udev code isn't showing some bits because you enclosed them in angle brackets, so it's interpreted on the blog as html code!

    AntwortenLöschen
    Antworten
    1. What browser are you using? For me with Firefox it's looking fine.

      Löschen