Media Transfer Protocol

出自 Arch Linux 中文维基

本文內容或本節內容已經過期。

原因: 請提供模板的第一個位置參數以概括原因。 (在Talk:Media Transfer Protocol討論)

這篇文章或章節的翻譯不反映原文。

原因:Last updated in 2016(在 Talk:Media Transfer Protocol# 中討論)

MTP 是 "Media Transfer Protocol" (媒體傳輸協議)的縮寫,很多移動和多媒體設備都支持這個協議.

安裝[編輯 | 編輯原始碼]

功能[編輯 | 編輯原始碼]

直接安裝 軟件包 libmtp。僅安裝 libmtp 就已經可以正確的訪問設備。為了添加與文件管理器的集成或者是提高傳輸和訪問的速度,還可以安裝以下的軟件包:

These packages to choose from all implement a Wikipedia:Filesystem in Userspace:

以上的這些都旨在提供比 libmtp 更好的使用體驗。因為 USB 設備實在是太多,所以你可能需要先研究一下哪個更加適合於你的設備。

提示:建議在安裝 MTP 軟件包後重啟電腦。

文件管理器集成[編輯 | 編輯原始碼]

為了能夠直接在文件管理器中通過 MTP 查看 Android 設備,需要安裝以下插件:

  • 如果文件管理器使用 GVFS (GNOME Files),安裝 gvfs-mtp 提供 MTP 支持或者是安裝 gvfs-gphoto2 提供 PTP 支持。
  • 如果文件管理器使用 KIO (KDE 的 Dolphin),安裝 kio-extras (KIO 的依賴包)。

當所需要的軟件包已經安裝,就可以通過連結訪問設備了。比如 mtp://[usb:002,013]/

用法[編輯 | 編輯原始碼]

在使用之前,可能需要先建立一個掛載點用於設備的掛載,本例中的掛載目錄為 ~/mnt。還有,在連接電腦之前需要解鎖手機屏幕。

libmtp[編輯 | 編輯原始碼]

檢測設備

# mtp-detect

來查看 MTP 設備是否檢測到,如果出錯,查看 troubleshooting libmtp

注意: 需要將當前用户添加到 uucp 用户組。

使用以下指令連接到設備:

# 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[編輯 | 編輯原始碼]

警吿: 以下的操作可能不能正常的工作,你必須求助於 GPhoto 或者是其他基於 gvfs 的文件管理器(如PCManFM

首先編輯 /etc/fuse.conf 註釋掉以下行:

user_allow_other

將設備掛載到 ~/mnt

$ mtpfs -o allow_other ~/mnt

~/mnt 卸載設備:

$ fusermount -u ~/mnt

Make this cohere to the rest of Linux (use regular mount/umount commands) by doing two steps

$# ln -s <actual mount command's path/name>  <a name consistent with Linux's mount convention>
$  ln -s /sbin/jmtpfs                        /sbin/mount.jmtpfs

add this line to /etc/fstab;

 #jmtpfs <mount path>        fuse nodev,allow_other,<other options>                             0    0
  jmtpfs /home/sam/run/motog fuse nodev,allow_other,rw,user,noauto,noatime,uid=1000,gid=1000    0    0

Now mount the device and see if the options "took"

 $ mount /home/sam/run/motog
 Device 0 (VID=22b8 and PID=2e82) is a Motorola Moto G (ID2).
 Android device detected, assigning default bug flags
 $ mount 
  ...
  jmtpfs on /home/sam/run/motog type fuse.jmtpfs (rw,nosuid,nodev,noexec,noatime,user_id=1000,group_id=1000,allow_other,user=sam)

jmtpfs[編輯 | 編輯原始碼]

使用此命令掛載設備(需要確保掛載點可用):

$ jmtpfs ~/mtp

使用此命令卸載設備

$ fusermount -u ~/mtp

go-mtpfs[編輯 | 編輯原始碼]

注意: Mounting with go-mtpfs might fail if an external SD Card is present. If you try to access your device while having an SD card and go-mtpfs complains, try removing the SD card and mounting again.

Install android-udev, which will allow you to edit /etc/udev/rules.d/51-android.rules and apply to your idVendor and idProduct, which you can see after running mtp-detect. To the end of the line, add your user OWNER="<user>".

  • 掛載設備:
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
注意: 安裝了 MTP 後您需要重啟設備以使其生效

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設備[編輯 | 編輯原始碼]

本文或本章節可能需要合併到[[]]。

附註: Unrelated to MTP, perhaps suited for USB storage devices(在 Talk:Media Transfer Protocol 中討論)

如果你在系統日誌中看到像這樣的信息(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[編輯 | 編輯原始碼]

本文或本章節可能需要合併到udev

附註: 請提供模板的second參數以more detailed indications。(在 Talk:Media Transfer Protocol 中討論)

如果你已經安裝了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]

jmtpfs Input/output error upon first access[編輯 | 編輯原始碼]

Symptoms: jmtpfs successfully mounts, but as soon as one attempts to access files on the device (e.g. via ls), an error is reported:

 cannot access <mount-point>: Input/output error

This appears to be a security feature: MTP does not work when the phone is locked by the lockscreen. Unlock the phone and it should work again as long as the cord remains connected.

kio-mtp[編輯 | 編輯原始碼]

如果你不能夠使用「打開文件管理器」操作,你可以通過編輯文件/usr/share/apps/solid/actions/solid_mtp.desktop解決這個問題。

使下面這行:

Exec=kioclient exec mtp:udi=%i/

變成

Exec=dolphin "mtp:/"