Friday, November 1, 2013

How to mount a Nexus 4 as a drive in Arch Linux

I wanted to copy a bunch of photos from my Nexus 4 to my laptop, which is running Arch Linux. It turns out this is not a plug-and-play operation, but it's not difficult to set up. By default, when the phone is plugged into the USB port on my laptop, it's recognized as a media device, so using the Media Transfer Protocol will allow file transfer.

This assumes FUSE is already installed.

1. Install MTP support:

sudo pacman -S libmtp

2. Plug in the Nexus 4 then run lsusb. Find your device listing, it should look like this:

Bus 001 Device 018: ID 18d1:4ee1 Google Inc. Nexus 4

In this line, the "18d1" is the vendor id, and "4ee1" is the product id. 

3. Edit or create /etc/udev/rules.d/51-android.rules so that it has this line:

SUBSYSTEM=="usb", ATTR{idVendor}=="[vendorid]", ATTR{idProduct}=="[productid]", MODE="0666", OWNER="[yourusername]"

Replace [vendorid] and [productid] with the values found in #2, and add your username.

4. Reload the udev rules:

sudo udevadm control --reload

5. Check that the phone is now visible:

mtp-detect

This may take some time, like several minutes, then it will show a lot of information. Be patient, it may look like it has hung, but just wait.

6. Create a mount point somewhere:

sudo mkdir /media/phone

7. Mount the phone:

sudo mtpfs -o allow_other /media/phone

Copy files and whatever.

8. Unmount the phone:

sudo umount /media/phone

I added these to my .bashrc:

alias nexus-connect="sudo mtpfs -o allow_other /media/phone"
alias nexus-disconnect="sudo umount /media/phone"


Some other notes:
I've read that mtpfs is unstable, but it seems to work fine for me, it's just slow.

I've read that jmtpfs is faster.

I've also read that go-mtpfs has even better performance and is more stable, so I gave it a try:

1. I already had libmtp and git installed, so all I needed to install was go:

sudo pacman -S go

2. Get go-mtpfs from AUR, install as per usual for AUR packages.

3. Mount the phone with

go-mtpfs /media/phone

It does seem to mount much faster than plain mtpfs, so I changed my .bashrc:

alias nexus-connect="go-mtpfs /media/phone"