Data exchange via USB

When plugged to USB older devices act as expected and pop up as memory devices. Under Windows they get a drive letter.

Since Android seems to be really attracted to Microsoft, newer devices do not support anymore this expected behavior. Reasons for that point to data security, Those devices support instead of the commonly used memory device behavior MTP. MTP is the Microsoft media transfer protocol (alternatively the Picture Transfer Protocol PTP can be selected). Under Windows those devices pop up as multimedia device where no drive letter is assigned. This has a side effect, most application can not save a file to the device. So two steps are required store the file somewhere and then use the file manager to move it to the device.

mtp under linux

Under Linux the library libmtp needs to be installed libmtp. libtmp comes with simple commands as mtp-detect that should work before going ahead. Linux is able using libmtp to communicate to such devices without mounting them and using the mtp protocol. gmtp is a graphical front end for it.

On the android device it should made sure that USB gets the permission to exchange file (not just charge or exchange photos)

Linux desktop environments might automatically open a window to allow communicating with the device through the MTP protocol (but hhis is not via a mounted file system).

Note

When having directories with more than thousands files them mtp seems to block. Using ftp might then be the way to go

Access mtp devices

Gvfs can be used to automatically access mtp devices when plugged in.

For gentoo there is the mtp useflag that puts mtp functionalities to programs as vlc and gvfs

Important

Accessing does not mean mount. Data can be accessed via mtp protocol but is not mounted

Mount mtp devices to file system

Instead of using the MTP way to communicate with android devices it can also be mounted to the filesystem.

Note

It might be that the desktop environment detects the MTP device and occupies it. In this case mtp-detect will fail and obviously also mounting. Try to unmount/eject the mtp device in the file manager. /usr/share/gvfs/gvfsd-mtp the mtp backend of gvfs might cause the conflict. On gentoo linux gvfs can be compiled without mtp support (useflag -mtp) so gvfs leaves the mtp devices in peace)

Various programs exist for that.

All use fuse so check if /etc/fuse.conf has uncomment the following line:

user_allow_other

Either mtpfs, jmtpfs, simple_mtpfs or go-mtpfs can be used. mtpfs seems to be buggy whereas the latest versions of libmtp and jmtpfs work well.

To mount as root or user having permission to /mnt/mtp

mtpfs -o allow_other /mnt/mtp

jmtpfs -o allow_other /mnt/mtp

go-mtpfs /mnt/mtp

simple-mtpfs /mnt/mtp

To unmount fusermount -u /mnt/mtp/

If it fails then one reason might be that the device already got managed by the desktop environment and is therefore busy (Having too many managers is always a problem). In the gui there might pop up two icons one named the device the other one called mtp. Unmount the mtp and do the mounting command again.

To mount (maybe as root) jmtpfs /media/sgs3/ or jmtpfs -o allow_other /media/sgs3

To unmount fusermount -u /media/sgs3/ or add to /etc/fstab

jmtpfs /media/sgs3 fuse users,noauto,allow_other 0 0

Then mounting works as usual mount /media/sgs3 and umount /media/sgs3

To mount as regular user add

user_allow_other

in /etc/fuse.conf

A udev rule can start a script that automatically mounts it, when it gets plugged in, this is done as the user root, to unmount it it is no more root but a regular used, this is just allowed when the fstab line holds users and not user.

Persistent device name for MTP devices

Check if a /dev/libmtp-* device is created when it is plugged in. To get a persistent file name a udev rule can be created that creates a symlink as /dev/mtp. The details can be found using udevadm monitor that shows where the device is recognized and then udevadm info -a -p /sys/devices/pci000<and the rest from udevadm monitor> | grep id

So add all modifications to a new file with a high number, so it gets processed late when the device is plugged in /etc/udev/rules.d/99-mtp.rules:

ACTION!="add", GOTO="99_mtp_rules_end"
ENV{MAJOR}!="?*", GOTO="99_mtp_rules_end"
ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="107e", \
SYMLINK+="mtp%n", GROUP="plugdev", MODE="0660"
LABEL="99_mtp_rules_end"

Run udevadm control --reload-rules to make the above effective and then replug the phone a constant /dev/mtp<n> name should now appear.

Automatically mount mtp devices to file system

If the standard desktop environment does not mount it automatically then the following can do the same:

Edit /etc/fstab that needs:

jmtpfs /mnt/mtp fuse users,noauto,allow_other 0 0

Note

users instead of user is required since root mounts it and a regular user unmounts it.

It seems to be necessary to add:

user_allow_other

to /etc/fuse.conf so I did this as well.

Then it can run as: mount /mnt/sgs/ Now the udev rule needs to run this command

ACTION!="add", GOTO="99_mtp_rules_end"
ENV{MAJOR}!="?*", GOTO="99_mtp_rules_end"
ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="107e", \
SYMLINK+="mtp%n", GROUP="plugdev", MODE="0660",
RUN+="/bin/mount /mnt/mtp"
LABEL="99_mtp_rules_end"

Note

You must unlock the devices screen and maybe set USB to data exchange to get access to the device


Linurs startpage