[HOWTO] Mount Nexus 4 in Linux

Search This thread

marty331

Senior Member
Jun 29, 2011
829
249
Dallas, TX
You are unable to just plug in your Nexus 4 in Linux but it is very easy to mount and unmount to move data to/from your sdcard. This is one option that will allow you to utilize Nautilis (or any other file browser) to copy files to/from your Nexus 4. This is written for Ubuntu, but should work the same for other Linux systems. Also, this should work for Nexus 7 and 10.

1. Enable Developer options and enable USB debugging.
2. Install necessary modules to your computer:
sudo apt-get install mtp-tools mtpfs
3. Configure 51-android.rules:
sudo gedit /etc/udev/rules.d/51-android.rules
paste the following at the end of the file (if the file does not exist then just paste):
#LG - Nexus 4
SUBSYSTEM=="usb", ATTR{idVendor}=="1004", MODE="0666"
#Samsung - Nexus 7 & 10
SUBSYSTEM=="usb", SYSFS{idVendor}=="18d1", MODE="0666"

Save and exit.
4. Make the file executable:
sudo chmod +x /etc/udev/rules.d/51-android.rules
5. Restart udev
sudo service udev restart
6. Create mount point and permissions (will need to do this for other Nexus' if using for the 7 or 10)
sudo mkdir /media/nexus4
chmod 755 /media/nexus4

7. Plug in the Nexus 4 and make sure MTP is enabled.

8. Mount with the following command:
sudo mtpfs -o allow_other /media/nexus4

9. When you have completed your work you must unmount:
sudo umount /media/nexus4

Now each time you need to copy from/to your Nexus 4 to your Linux computer you only need to plug in and run 8, then 9 when you have completed your work.
 

wngmv

Senior Member
Sep 9, 2009
670
95
Awesome. Thanks

sent from my straight out of limbo 2 Nexus 4 using XDA-premium
 

Konsyst

Senior Member
Nov 23, 2011
61
3
This isn't so much a Nexus 4 guide as a general Linux mounting guide, but still cool. Thanks!
 

the3dman

Senior Member
Sep 5, 2007
657
99
Chicago :(
www.the3dman.com
First, thanks to the OP! Just wanted to add another way for linux.

Just install and run gMTP plug your phone in and click connect. It is in the Ubuntu software center or for other versions of linux at http://gmtp.sourceforge.net/
 

Attachments

  • gMTP.jpg
    gMTP.jpg
    15.8 KB · Views: 3,915
Last edited:

Kaar3l

Senior Member
Oct 4, 2011
94
36
I prefer adb+qtadb. Better speed and stability compared to mtp i think. :)

Sent from my Blade using xda app-developers app
 
  • Like
Reactions: smenes

mrmylanman

Senior Member
Jun 19, 2010
405
22
Altamonte Springs
Thanks for that write up. On my gentoo box my galaxy nexus worked flawlessly but the nexus 4 did not. Hopefully this will do it!

Sent from my Nexus 4 using Tapatalk 2
 

jamcar

Senior Member
Aug 11, 2010
1,215
400
Orlando
I prefer adb+qtadb. Better speed and stability compared to mtp i think. :)

Sent from my Blade using xda app-developers app







Yes QtADB works very nicely also. It requires a little more setup than gMTP, but you are correct that it is a little faster and stable.

Never heard of that. What is it?

Generating random authentication keys

---------- Post added at 07:48 AM ---------- Previous post was at 07:47 AM ----------

This isn't so much a Nexus 4 guide as a general Linux mounting guide, but still cool. Thanks!

Haven't gotten my N4 yet but I'm gonna try this on my sIII.

Generating random authentication keys
 

MisakaImouto

Senior Member
Jul 19, 2012
62
4
Menasha
I personally think using sshfs and sshdroid is a much more stable solution. MTP support on Linux is... shoddy to say the least.
Thanks given anyway though.
 

d4ft

Senior Member
Nov 1, 2010
59
8
It seems that mtpfs 1.1 is broken. I downgraded to 1.0 and it worked. However, there is usually lag for some reason whenever the screen is off.
 

mussieonlinux

Senior Member
Apr 10, 2012
64
24
I had MTP/PTP crash several sdcards of mine which required me to format them (no write permissions had no way to get that back.)
Ever since that I just use ADB (Android Debugging Bridge) there are several GUI front-ends available in the default deb/rpm repositories, or if you are comfortable with the terminal (and with ADB it's really really simple to master) you can just get the binary and put it in your bin folder and transfer it via that. Highly reliable, speed is about 2-3mb/s -- but it works. :)
 

mpmilestogo

Senior Member
Aug 9, 2009
348
66
Union City California
I gave up on this on Debian Testing. My Galaxy Nexus would not mount no matter what udev rules I used and mtpfs is not a solution. Instead, I just use a ftp server on the phone and ftp things to it or push things using adb. I've also tried airdroid a few times. I would not mind trying the sshfs alternative either. Gonna check that one out.
 

MisakaImouto

Senior Member
Jul 19, 2012
62
4
Menasha
OP's use of udev inspired me to come up with this solution using ADB.
I'll assume you have ADB installed. There's plenty of indepth guides for that elsewhere.

This tutorial will have you playing around in system directories on your Linux install. I tried to make this guide user friendly but you should have at least SOME knowledge of Unix like OSes before you even try this.
Not for the faint of heart.


Get http://https://play.google.com/store/apps/details?id=berserker.android.apps.sshdroid&hl=en from the play store. Enable USB debugging in the developer options on your phone.
Open SSHDroid on your phone and set your port to something other than 22. I use 2222.
Open a terminal window on your computer and elevate yourself to root (Preferably using su -. Otherwise use sudo su -.).
Now that we got that done, try logging into your phone to make sure everything works. It'll be something like
Code:
ssh -p2222 [email protected][yourPhone'sIP]
. If you get asked a password it probably works. Just hit ^C (Ctrl+C) to exit that password prompt since we don't need to go further yet.
Next you'll need to create a passwordless SSH login. Run
Code:
ssh-keygen -t rsa
. Just hit enter to use the defaults on all the questions, we don't need anything more.
Now run
Code:
scp -P2222 ~/.ssh/id_rsa.pub [email protected][yourPhone'sIP]:/emulated/storage/legacy/
. When it asks for the password just type "admin", though it should tell you that anyway.
If the file copied over successfully you should no be able to type
Code:
ssh -p2222 [email protected][yourPhone'sIP]
again and not be prompted with a password at all. Cool!
At this point it's recommended you go into the SSHDroid settings on your phone and untick the "Enable Password" box, though it's not required, especially if you want to ssh to your phone from other devices/computers.
Run lsusb and look for the line that says Google in it. You want to look out for something like
Code:
Bus 001 Device 070: ID 18d1:4ee2 Google Inc.
Copy the two alphanumeric codes before "Google Inc.". The first is your vendor ID and the second is your device ID. You might want to label them so you remember which is which.
Here's the scary part of the tutorial. Use your favorite text editor (preferably command line based) and create a new file at "/etc/udev/rules.d/85-android_mount.rules". Copy and paste this and edit to fit the IDs you got in the previous command.
Code:
SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4ee2", RUN+="/usr/local/sbin/phone-mount -m" SYMLINK+="Nexus_4"
SUBSYSTEMS=="usb", ACTION=="remove", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4ee2", RUN+="/usr/local/sbin/phone-mount -u" SYMLINK+="Nexus_4"
It should be obvious where you need to put your Vendor and Device IDs now.
Save it and run these commands.
Code:
chmod +x /etc/udev/rules.d/85-android_mount.rules
chmod 775 /etc/udev/rules.d/85-android_mount.rules
chown root:root /etc/udev/rules.d/85-android_mount.rules
Now we need to create another file at "/usr/local/sbin/phone-mount" and paste this inside.
Code:
#!/bin/bash
export PATH=/opt/android-sdk-update-manager/platform-tools/:$PATH

case "$1" in
    -m )
        adb wait-for-device
        adb forward tcp:2222 tcp:2222
        # If you have SSHDroid Pro you just need to add "pro" to the "sshdroid". 
        adb shell am broadcast -a berserker.android.apps.sshdroid.command.START
        sshfs -p2222 -o allow_other,idmap=user [email protected]:/storage/emulated/legacy/ /media/nexus4
        exit 0
     ;;

     -u )
        umount /media/nexus4
        exit 0
     ;;
esac
We need to modify the permissions for this file too.
Code:
chmod +x /usr/local/sbin/phone-mount
chmod 775 /usr/local/sbin/phone-mount
chown root:root /usr/local/sbin/phone-mount
Almost done. If you don't already have sshfs installed on your Linux install then do so now. You'll also need to enable the "allow_other" option. For my distro it's as simple as editing "/etc/fuse.conf" and uncommenting the "user_allow_other" line. Your results may vary.
Now finally we need to create the actual folder you'll be mounting your Nexus 4 at. If you blindly followed my guide that'll be /media/nexus4.
Code:
mkdir /media/nexus4
chown root:users /media/nexus4
chmod 775 /media/nexus4
Now all we need to do is restart udev. Right now you'll want to make sure the phone is unplugged, then restart your udev daemon. For Debian based distros like Mint, Ubuntu, Debian, Crunchbang, etc. you'd run.
Code:
service udev restart
After it's done restarting you can plug your phone in, wait a few seconds, and hopefully have your phone automount to /media/nexus4 .

You may have to improvise in a few spots because all distros are not the same, especially when you compare something like Gentoo to Debian. If you're having problems with sshfs chances are your answer is on Google. You'll honestly get better help there than having me trying to guess your system.

Also note this is a pretty hacky and dirty way to do things. Don't go yanking your phone's USB cord out without unmounting "/media/nexus4" first. You shouldn't have any problems if you're not reading or writing anything, but there is the potential for data loss and crashing udev.
 
Last edited:

loscassapalle

Senior Member
Jan 9, 2010
318
16
i got this error at the last step

Code:
Attempting to connect device
PTP_ERROR_IO: failed to open session, trying again after resetting USB interface
LIBMTP libusb: Attempt to reset device
Android device detected, assigning default bug flags
Listing File Information on Device with name: (NULL)
fuse: bad mount point `/media/nexus4': Transport endpoint is not connected
 

Top Liked Posts

  • There are no posts matching your filters.
  • 54
    You are unable to just plug in your Nexus 4 in Linux but it is very easy to mount and unmount to move data to/from your sdcard. This is one option that will allow you to utilize Nautilis (or any other file browser) to copy files to/from your Nexus 4. This is written for Ubuntu, but should work the same for other Linux systems. Also, this should work for Nexus 7 and 10.

    1. Enable Developer options and enable USB debugging.
    2. Install necessary modules to your computer:
    sudo apt-get install mtp-tools mtpfs
    3. Configure 51-android.rules:
    sudo gedit /etc/udev/rules.d/51-android.rules
    paste the following at the end of the file (if the file does not exist then just paste):
    #LG - Nexus 4
    SUBSYSTEM=="usb", ATTR{idVendor}=="1004", MODE="0666"
    #Samsung - Nexus 7 & 10
    SUBSYSTEM=="usb", SYSFS{idVendor}=="18d1", MODE="0666"

    Save and exit.
    4. Make the file executable:
    sudo chmod +x /etc/udev/rules.d/51-android.rules
    5. Restart udev
    sudo service udev restart
    6. Create mount point and permissions (will need to do this for other Nexus' if using for the 7 or 10)
    sudo mkdir /media/nexus4
    chmod 755 /media/nexus4

    7. Plug in the Nexus 4 and make sure MTP is enabled.

    8. Mount with the following command:
    sudo mtpfs -o allow_other /media/nexus4

    9. When you have completed your work you must unmount:
    sudo umount /media/nexus4

    Now each time you need to copy from/to your Nexus 4 to your Linux computer you only need to plug in and run 8, then 9 when you have completed your work.
    9
    First, thanks to the OP! Just wanted to add another way for linux.

    Just install and run gMTP plug your phone in and click connect. It is in the Ubuntu software center or for other versions of linux at http://gmtp.sourceforge.net/
    3
    MTP support in Ubuntu 13.04 has been backported to 12.04 and 12.10.

    http://www.webupd8.org/2013/01/upgrade-to-gvfs-with-mtp-support-in.html?m=1

    Code:
    sudo add-apt-repository ppa:webupd8team/gvfs-libmtp
    sudo apt-get update
    Reboot and done. Worked perfectly for me, it opened up a Nautilus window when I plugged the phone in and I unmounted it from the same window once I was done. :good:
    3
    OP's use of udev inspired me to come up with this solution using ADB.
    I'll assume you have ADB installed. There's plenty of indepth guides for that elsewhere.

    This tutorial will have you playing around in system directories on your Linux install. I tried to make this guide user friendly but you should have at least SOME knowledge of Unix like OSes before you even try this.
    Not for the faint of heart.


    Get http://https://play.google.com/store/apps/details?id=berserker.android.apps.sshdroid&hl=en from the play store. Enable USB debugging in the developer options on your phone.
    Open SSHDroid on your phone and set your port to something other than 22. I use 2222.
    Open a terminal window on your computer and elevate yourself to root (Preferably using su -. Otherwise use sudo su -.).
    Now that we got that done, try logging into your phone to make sure everything works. It'll be something like
    Code:
    ssh -p2222 [email protected][yourPhone'sIP]
    . If you get asked a password it probably works. Just hit ^C (Ctrl+C) to exit that password prompt since we don't need to go further yet.
    Next you'll need to create a passwordless SSH login. Run
    Code:
    ssh-keygen -t rsa
    . Just hit enter to use the defaults on all the questions, we don't need anything more.
    Now run
    Code:
    scp -P2222 ~/.ssh/id_rsa.pub [email protected][yourPhone'sIP]:/emulated/storage/legacy/
    . When it asks for the password just type "admin", though it should tell you that anyway.
    If the file copied over successfully you should no be able to type
    Code:
    ssh -p2222 [email protected][yourPhone'sIP]
    again and not be prompted with a password at all. Cool!
    At this point it's recommended you go into the SSHDroid settings on your phone and untick the "Enable Password" box, though it's not required, especially if you want to ssh to your phone from other devices/computers.
    Run lsusb and look for the line that says Google in it. You want to look out for something like
    Code:
    Bus 001 Device 070: ID 18d1:4ee2 Google Inc.
    Copy the two alphanumeric codes before "Google Inc.". The first is your vendor ID and the second is your device ID. You might want to label them so you remember which is which.
    Here's the scary part of the tutorial. Use your favorite text editor (preferably command line based) and create a new file at "/etc/udev/rules.d/85-android_mount.rules". Copy and paste this and edit to fit the IDs you got in the previous command.
    Code:
    SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4ee2", RUN+="/usr/local/sbin/phone-mount -m" SYMLINK+="Nexus_4"
    SUBSYSTEMS=="usb", ACTION=="remove", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4ee2", RUN+="/usr/local/sbin/phone-mount -u" SYMLINK+="Nexus_4"
    It should be obvious where you need to put your Vendor and Device IDs now.
    Save it and run these commands.
    Code:
    chmod +x /etc/udev/rules.d/85-android_mount.rules
    chmod 775 /etc/udev/rules.d/85-android_mount.rules
    chown root:root /etc/udev/rules.d/85-android_mount.rules
    Now we need to create another file at "/usr/local/sbin/phone-mount" and paste this inside.
    Code:
    #!/bin/bash
    export PATH=/opt/android-sdk-update-manager/platform-tools/:$PATH
    
    case "$1" in
        -m )
            adb wait-for-device
            adb forward tcp:2222 tcp:2222
            # If you have SSHDroid Pro you just need to add "pro" to the "sshdroid". 
            adb shell am broadcast -a berserker.android.apps.sshdroid.command.START
            sshfs -p2222 -o allow_other,idmap=user [email protected]:/storage/emulated/legacy/ /media/nexus4
            exit 0
         ;;
    
         -u )
            umount /media/nexus4
            exit 0
         ;;
    esac
    We need to modify the permissions for this file too.
    Code:
    chmod +x /usr/local/sbin/phone-mount
    chmod 775 /usr/local/sbin/phone-mount
    chown root:root /usr/local/sbin/phone-mount
    Almost done. If you don't already have sshfs installed on your Linux install then do so now. You'll also need to enable the "allow_other" option. For my distro it's as simple as editing "/etc/fuse.conf" and uncommenting the "user_allow_other" line. Your results may vary.
    Now finally we need to create the actual folder you'll be mounting your Nexus 4 at. If you blindly followed my guide that'll be /media/nexus4.
    Code:
    mkdir /media/nexus4
    chown root:users /media/nexus4
    chmod 775 /media/nexus4
    Now all we need to do is restart udev. Right now you'll want to make sure the phone is unplugged, then restart your udev daemon. For Debian based distros like Mint, Ubuntu, Debian, Crunchbang, etc. you'd run.
    Code:
    service udev restart
    After it's done restarting you can plug your phone in, wait a few seconds, and hopefully have your phone automount to /media/nexus4 .

    You may have to improvise in a few spots because all distros are not the same, especially when you compare something like Gentoo to Debian. If you're having problems with sshfs chances are your answer is on Google. You'll honestly get better help there than having me trying to guess your system.

    Also note this is a pretty hacky and dirty way to do things. Don't go yanking your phone's USB cord out without unmounting "/media/nexus4" first. You shouldn't have any problems if you're not reading or writing anything, but there is the potential for data loss and crashing udev.
    3
    A couple of other options for Ubuntu users (both work for me on Ubuntu 13.04 64bit):

    Easy right click mount/unmount:

    In terminal

    Code:
    sudo add-apt-repository ppa:webupd8team/unstable
    sudo apt-get update
    sudo apt-get install go-mtpfs go-mtpfs-unity

    Then go into Dash Home, type in Mount Android Device. Click and drag the icon to your launcher. It's not auto-mount, but works well on any Android device i've tried so far. When you plug in your Android device (tested on Galaxy Nexus, Nexus 4, and Nexus 7), unlock it, then, right click on the Android icon, and select Mount Android Device (not the bold text, normal text). Instantly there in Nautilus. When done, make sure unlocked, then right click / unmount. Easy.

    Set up auto mount (both nex4/nex7):

    set up fuse:
    Code:
    sudo chmod a+r /etc/fuse.conf
    sudo gedit /etc/fuse.conf

    remove the hash from infront of:
    #user_allow_other

    to be
    user_allow_othe

    save and close. now download/install go-mtpfs:
    Code:
    sudo add-apt-repository ppa:webupd8team/unstable
    sudo apt-get update
    sudo apt-get install go-mtpfs

    Now setup mount directories:
    Code:
    sudo mkdir /media/nexus4
    sudo chmod 777 /media/Nexus4
    sudo mkdir /media/nexus7
    sudo chmod 777 /media/Nexus7

    Add udev rules:
    Code:
    sudo gedit /etc/udev/rules.d/99-android.rules

    Add in the following (change "yourloginid" to your Ubuntu username):
    Code:
    # Google Nexus 7 MTP mode : automatic mount when plugged (all android versions)
    ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e41", ACTION=="add", RUN+="/usr/bin/sudo -u yourloginid /usr/local/sbin/go-mtpfs -allow-other=true /media/nexus7"
    ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e42", ACTION=="add", RUN+="/usr/bin/sudo -u yourloginid /usr/local/sbin/go-mtpfs -allow-other=true /media/nexus7"
    ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e41", ACTION=="add", RUN+="/usr/bin/sudo -u yourloginid /usr/local/sbin/go-mtpfs -allow-other=true /media/nexus7"
    ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e42", ACTION=="add", RUN+="/usr/bin/sudo -u yourloginid /usr/local/sbin/go-mtpfs -allow-other=true /media/nexus7"
    
    # Google Nexus 7 MTP mode : automatic unmount when unplugged (all android versions)
    ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e41", ACTION=="remove", RUN+="/bin/umount /media/nexus7"
    ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4ee2", ACTION=="remove", RUN+="/bin/umount /media/nexus7"
    ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e41", ACTION=="remove", RUN+="/bin/umount /media/nexus7"
    ENV{ID_MODEL}=="Nexus_7", ENV{ID_MODEL_ID}=="4e42", ACTION=="remove", RUN+="/bin/umount /media/nexus7"
    
    # Google Nexus 4 MTP mode : automatic mount when plugged (all android versions)
    ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4ee1", ACTION=="add", RUN+="/usr/bin/sudo -u yourloginid /usr/local/sbin/go-mtpfs -allow-other=true /media/Nexus4"
    ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4ee2", ACTION=="add", RUN+="/usr/bin/sudo -u yourloginid /usr/local/sbin/go-mtpfs -allow-other=true /media/Nexus4"
    ENV{ID_MODEL}=="Nexus_4", ENV{ID_MODEL_ID}=="4ee1", ACTION=="add", RUN+="/usr/bin/sudo -u yourloginid /usr/local/sbin/go-mtpfs -allow-other=true /media/Nexus4"
    ENV{ID_MODEL}=="Nexus_4", ENV{ID_MODEL_ID}=="4ee2", ACTION=="add", RUN+="/usr/bin/sudo -u yourloginid /usr/local/sbin/go-mtpfs -allow-other=true /media/Nexus4"
    
    # Google Nexus 4 MTP mode : automatic unmount when unplugged (all android versions)
    ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4ee1", ACTION=="remove", RUN+="/bin/umount /media/Nexus4"
    ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4ee2", ACTION=="remove", RUN+="/bin/umount /media/Nexus4"
    ENV{ID_MODEL}=="Nexus_4", ENV{ID_MODEL_ID}=="4ee1", ACTION=="remove", RUN+="/bin/umount /media/Nexus4"
    ENV{ID_MODEL}=="Nexus_4", ENV{ID_MODEL_ID}=="4ee2", ACTION=="remove", RUN+="/bin/umount /media/Nexus4"

    Restart udev:
    Code:
    sudo service udev restart

    Add rules to fstab to allow easy mount/unmount without root:
    Code:
    sudo gedit /etc/fstab

    Add in this to the end of the file:
    Code:
    DeviceFs(Nexus\0407)    /media/nexus7    fuse.DeviceFs(Nexus\0407)    allow_other,rw,user,noauto    0    0
    DeviceFs(Nexus\0404)    /media/Nexus4    fuse.DeviceFs(Nexus\0404)    allow_other,rw,user,noauto    0    0

    Remount all drives:
    Code:
    sudo mount -a

    sources:
    http://www.webupd8.org/2012/12/how-to-mount-android-40-ubuntu-go-mtpfs.html
    http://www.tuxtrix.com/2012/12/how-to-automount-nexus-4-and-nexus-7-in.html

    enjoy :)