MTP (简体中文)
MTP 是 "Media Transfer Protocol" (媒体传输协议)的缩写,很多移动和多媒体设备都支持这个协议.
Contents
安装
功能
libmtp 提供了 Linux 下的 MTP 支持,可以从 official repositories 直接安装 libmtp。仅安装 libmtp 就已经可以正确的访问设备。为了添加与文件管理器的集成或者是提高传输和访问的速度,还可以安装以下的软件包:
These packages to choose from all implement a Wikipedia:Filesystem in Userspace:
- mtpfs
- jmtpfsAUR - 据说对 Android 4+ 以上的设备支持更好
- go-mtpfs-gitAUR - 据说对 Android 3+ 以上的设备支持更好
- simple-mtpfsAUR
以上的这些都旨在提供比 libmtp
更好的使用体验。因为 USB 设备实在是太多,所以你可能需要先研究一下哪个更加适合于你的设备。
文件管理器集成
为了能够直接在文件管理器中通过 MTP 查看 Android 设备,需要安装以下插件:
- 如果文件管理器使用 GVFS (GNOME Files, Xfce 的 Thunar),安装 gvfs-mtp 提供 MTP 支持或者是安装 gvfs-gphoto2 提供 PTP 支持。
- 如果文件管理器使用 KIO (KDE 的 Dolphin),安装 kio-mtp (自带 PTP 支持)。
当所需要的软件包已经安装,就可以通过链接访问设备了。比如 mtp://[usb:002,013]/
。
用法
在使用之前,可能需要先建立一个挂载点用于设备的挂载,本例中的挂载目录为 ~/mnt。还有,在连接电脑之前需要解锁手机屏幕。
libmtp
检测设备
# mtp-detect
来查看 MTP 设备是否检测到,如果出错,查看 troubleshooting libmtp。
使用以下指令连接到设备:
# mtp-connect
同样,你也可以使用以下的独立命令来访问您的 MTP 设备:
mtp-albumart mtp-emptyfolders mtp-getplaylist mtp-reset mtp-trexist mtp-albums mtp-files mtp-hotplug mtp-sendfile mtp-connect mtp-folders mtp-newfolder mtp-sendtr mtp-delfile mtp-format mtp-newplaylist mtp-thumb mtp-detect mtp-getfile mtp-playlists mtp-tracks
mtpfs
首先编辑 /etc/fuse.conf
注释掉以下行:
user_allow_other
将设备挂载到 ~/mnt
:
$ mtpfs -o allow_other ~/mnt
从 ~/mnt
卸载设备:
$ fusermount -u ~/mnt
jmtpfs
使用此命令挂载设备(需要确保挂载点可用):
$ jmtpfs ~/mtp
使用此命令卸载设备
$ fusermount -u ~/mtp
go-mtpfs
If the above instructions don't show any positive results one should try go-mtpfs-gitAUR from the AUR. The following has been tested on a Samsung Galaxy Nexus GSM, Asus/Google Nexus 7 (2012 1st gen model) and Samsung Galaxy S 3 mini. (This is the only mtp software which worked for me on nexus 4. Settings are usb debugging enabled, connected as media device.)
If you want do it simpler, install go, libmtp and git from the official repositories. After that install go-mtpfs-gitAUR from the AUR.
As in the section above install android-udev which will provide you with "/usr/lib/udev/rules.d/51-android.rules" edit it to apply to your vendorID and productID, which you can see after running mtp-detect. To the end of the line add with a comma OWNER="yourusername". Save the file.
- 将用户添加到 "fuse" 组:
gpasswd -a [user] fuse
- 如果该组不存在,请用以下的命令创建:
groupadd fuse
注销用户或者重启计算机以使得更改生效.
- 建立名为 "Android" 的挂载点:
mkdir Android
- 挂载设备:
go-mtpfs Android
- 卸载设备:
fusermount -u Android
您可以在 .bashrc 为这个命令设置一个别名,来让它更加的符合你的口味.
simple-mtpfs
这是MTP设备的另外一个用户空间文件系统。 你可能会觉得它比mtpfs更加可靠。你能通过AUR安装或者从源代码编译simple-mtpfsAUR。记住 不要 用root运行下面的命令。
- 查看MTP设备,运行:
simple-mtpfs --list-devices
- 挂在一个MTP设备 (in this example device 0),运行:
simple-mtpfs /path/to/your/mount/point
- 卸载,运行
fusermount -u /path/to/your/mount/point
使用媒体播放器
您也可以在音乐播放器中使用 MTP 设备,例如 Amarok 等. 但是您也许要做以下的操作:编辑 /etc/udev/rules.d/51-android.rules
[ MTP 设备使用示例如下(以 Galaxy Nexus 为例)]:
执行命令:
$ lsusb
查看您的设备信息,他们一般看起来像:
Bus 003 Device 011: ID 04e8:6860 Samsung Electronics Co., Ltd GT-I9100 Phone [Galaxy S II], GT-P7500 [Galaxy Tab 10.1]
在这种情况下,条目将是:
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666", OWNER="[username]"
然后重新载入 udev 规则:
# udevadm control --reload
Troubleshooting
libmtp
Unknown device
如果你看到像这样的信息:
Device 0 (VID=XXXX and PID=XXXX) is UNKNOWN. Please report this VID/PID and the device model to the libmtp development team
你应该核对你的设备是否列在supported devices list上。如果没有,那么你应该像开发团队报告,而且,可能你的 libmtp
稍稍有点过时。 允许你的设备能通过libmtp
适当地使用,你应该添加你的设备到:
/etc/udev/rules.d/69-libmtp.rules
不能列举USB设备
如果你在系统日志中看到像这样的信息(journalctl
)
usb usb4-port2: unable to enumerate USB device
你能够尝试下面的临时解决方案
# modprobe -vr uhci_hcd # modprobe -va ohci_hcd # modprobe -va uhci_hcd
如果它工作,你应该创建/etc/modprobe.d/usb_hci_order.conf
和下面的内容。
# create a dependency on ohci for uhci, which fixes problems # with external usb devices not showing up # softdep uhci_hcd pre: ohci_hcd
gvfs-mtp
如果你已经安装了gvfs-mtp,并且你的设备没有在文件管理器中出现,为了能够用自动挂在设备,你可能需要重启电脑或者写入一个udev规则。
插入设备后你能分别得到厂商ID和产品编号:
$ lsusb Bus 001 Device 007: ID 0421:0661 Nokia Mobile Phones Lumia 920 (...)
在ID后的两串数字是厂商ID : 产品编号
然后设定一个udev规则,
# nano /etc/udev/rules.d/51-android.rules
并且列出规则:
ATTR{idVendor}=="YOUR VENDOR ID HERE", ATTR{idProduct}=="YOUR PRODUCT ID HERE", SYMLINK+="libmtp", MODE="660", ENV{ID_MTP_DEVICE}="1"
重新加载udev规则。
# udevadm control --reload
And reboot the system. Now file managers (like Thunar) should be able to automount the MTP Device. [1]
kio-mtp
如果你不能够使用“打开文件管理器”操作,你可以通过编辑文件/usr/share/apps/solid/actions/solid_mtp.desktop
解决这个问题。
使下面这行:
Exec=kioclient exec mtp:udi=%i/
变成
Exec=dolphin "mtp:/"