Jump to content

MTP: Difference between revisions

From Official NixOS Wiki
imported>IgorM
m Fixed link
Perchun (talk | contribs)
Add `go-mtpfs`
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
The Media Transfer Protocol (MTP) can be used to transfer media files to and from many mobile phones (most Windows Phone and [[Android]] devices) and media players (e.g. Creative Zen).
The [https://en.wikipedia.org/wiki/Media_Transfer_Protocol Media Transfer Protocol (MTP)] can be used to transfer media files to and from many mobile phones (mostly [[Android]] devices) and media players (e.g. Creative Zen).


MTP devices are usually mounted via [[FUSE]] and then appear as a more or less regular file system.
MTP devices are usually mounted via [https://wiki.archlinux.org/title/FUSE FUSE] and then appear as a more or less regular file system.


This page lists some ways to mount a MTP device.
{{Tip|You usually need to unlock and change the connection mode to "File Transfer" for an Android device to appear as an MTP device}}
 
=== go-mtpfs ===
 
[https://github.com/hanwen/go-mtpfs <code>go-mtpfs</code>] is a simple implementation of the MTP filesystem, which has its own limitations, but the main advantage is that it does not need to be installed. You can just run:


{{Commands|
$ mkdir mnt
$ go-mtpfs mnt
(your device gets automatically found and mounted)
}}


{{Tip|You usually need to unlock and change the connection mode to "File Transfer" for an Android device to appear as an MTP device}}
Sometimes, <code>go-mtpfs</code> can crash, and you have to first run <code>umount mnt</code> before restarting <code>go-mtpfs</code>.


=== jmtpfs ===
=== jmtpfs ===
{{Warning|<code>jmtpfs</code> will be removed in 26.11, so you should not rely on it.}}
Install <code>jmtpfs</code>:
Install <code>jmtpfs</code>:
{{Commands|$ nix-env -f "<nixpkgs>" -iA jmtpfs}}
{{Commands|$ nix-env -f "<nixpkgs>" -iA jmtpfs}}
Line 33: Line 45:
</syntaxhighlight>
</syntaxhighlight>


The above should suffice, but there also exists a more manual method. This method apparently only works well with gtk/gnome-based desktops like [[GNOME|Gnome Shell]] or [[Xfce]].
The above should suffice, but there also exists a more manual method. This method apparently only works well with GTK/Gnome-based desktops like [[GNOME|Gnome Shell]] or [[Xfce]].
It relies on having <code>gvfs</code> listed in the environment variable <code>GIO_EXTRA_MODULES</code>, for example:
It relies on having <code>gvfs</code> listed in the environment variable <code>GIO_EXTRA_MODULES</code>, for example:



Latest revision as of 10:00, 27 September 2026

The Media Transfer Protocol (MTP) can be used to transfer media files to and from many mobile phones (mostly Android devices) and media players (e.g. Creative Zen).

MTP devices are usually mounted via FUSE and then appear as a more or less regular file system.

🟆︎
Tip: You usually need to unlock and change the connection mode to "File Transfer" for an Android device to appear as an MTP device

go-mtpfs

go-mtpfs is a simple implementation of the MTP filesystem, which has its own limitations, but the main advantage is that it does not need to be installed. You can just run:

$ mkdir mnt
$ go-mtpfs mnt
(your device gets automatically found and mounted)

Sometimes, go-mtpfs can crash, and you have to first run umount mnt before restarting go-mtpfs.

jmtpfs

⚠︎
Warning: jmtpfs will be removed in 26.11, so you should not rely on it.

Install jmtpfs:

$ nix-env -f "<nixpkgs>" -iA jmtpfs

To mount the only available device:

$ mkdir mountpoint
$ jmtpfs mountpoint

If there are several connected devices, use -l to find them and -device= to specify which one to mount.

To unmount:

$ fusermount -u

gvfs

On NixOS, file managers that support gvfs, such as PCManFM, can mount mtp devices by adding this to configuration.nix:

{ 
  services.gvfs.enable = true;
}

The above should suffice, but there also exists a more manual method. This method apparently only works well with GTK/Gnome-based desktops like Gnome Shell or Xfce. It relies on having gvfs listed in the environment variable GIO_EXTRA_MODULES, for example:

GIO_EXTRA_MODULES=/nix/store/my9jjhq7s19l05zqk969h69jhrrijpkz-gvfs-1.34.2/lib/gio/modules

First identify your device with lsusb:

$ lsusb
Bus 002 Device 007: ID 1234:5678 The device
...

The adress of the device will then be mtp://[usb:002,007]/.

You need the gio from the glib package. Then:

$ gio mount "mtp://[usb:002,007]/"

to mount and

$ gio mount -u "mtp://[usb:002,007]/"

to unmount.

The device will appear in your favorite file manager.