8

How can I bind my Android file system to my Linux machine, and modify it? When I plug in my Android device, it seems to use one USB interface but I couldn't find whre the mount point is. I checked /mnt but there is nothing.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
user55778
  • 187
  • 1
  • 1
  • 6

5 Answers5

1

Some phones have icky USB storage interfaces, which don't work on Linux reliably (look here for example), others (e.g. my Samsung Galaxy with Android 4.3) seem not to offer USB access to their innards at all (nothing in the logs when plugging it in). Some need to be set up specially (allow USB in their configuration) to mount them.

vonbrand
  • 18,156
  • 2
  • 37
  • 59
1

MTPFS is likely what you want, it's FUSE based, but there is no reason that that wouldn't work (outside of device-specific issues)

After installing it :

Add yourself to plugdev group (to have the needed permissions)

gpasswd -a <USER_NAME> plugdev

Then, just run

mtpfs <empty folder>

To unmount :

fusermount -u <folder>
  • I could not find `mtpfs` for Ubuntu, but I found `jmtpfs`. When running that as normal user or as root I get: `No mtp devices found.` My phone "Select USB configuration" > "Media Transfer Protocol (MTP)" and plugged in USB. – Ole Tange Jan 24 '22 at 20:03
0

If you have a newer smartphone that uses MTP/PTP protocol, I'm afraid you can't mount it to the filesystem and access it as a regular drive device with just a mount command - similar discussion here.

To make this work, you need some kind of virtual file system tool. I believe gvfs should do the trick. To make this mounting automatic, a daemon has to be running in the background. Search for gvfs, gvfs-mtp, gvfs-fuse, gvfs-deamons, etc. in your package manager.

References:

https://en.wikipedia.org/wiki/Virtual_file_system

https://wiki.archlinux.org/title/Media_Transfer_Protocol

https://superuser.com/questions/1157661/how-to-mount-an-android-smartphone-as-a-drive-in-windows

Accessing MTP mounted device in terminal

https://wiki.gnome.org/Projects/gvfs

BlueManCZ
  • 1,693
  • 12
  • 31
0

I wouldn't expect to find a reliable solution that would work with USB cable, the general trend in the industry is to go fully wireless.

The method I used for a couple of years and that works with various Android devices and that works well and that doesn't require rooted device is to use SimpleSSHD on your Android device and sshfs on your desktop Linux machine.

Install and setup SimpleSSHD on your Android device and use sshfs on desktop Linux machine like that:

sshfs <PHONE_IP_ADDRESS>:<PATH_ON_ANDROID> <LOCAL_DIR>

For example, this is the command I use to mount Gallery from my Galaxy S8 phone on my Slackware system:

$ mkdir gallery
$ sshfs phone:/sdcard/DCIM/Camera gallery

phone is an alias I defined in ~/.ssh/config:

Host phone
     User shell
     Hostname Galaxy-S8
     Port 2222

Of course it requires your Android device and your Linux machine to be in the same network.

Unmount local dir without root:

fusermount -u gallery

Last time I checked SimpleSSHD was a re-packaged Dropebar binary for ARM.

Arkadiusz Drabczyk
  • 25,049
  • 5
  • 53
  • 68
  • `sshfs 192.168.1.230:/ phone/; ls phone/` gives `ls: reading directory 'phone/': Permission denied`. – Ole Tange Jan 24 '22 at 19:38
  • You don't have a rooted device, you won't be able to access `/` like that. Rooting an Android device is a separate issue. – Arkadiusz Drabczyk Jan 24 '22 at 19:45
  • I do not want to root my device, but I want access to all the files I have access to. In other words: I want to be able to do a `find dir` and see all the files I have access to in `dir`. – Ole Tange Jan 24 '22 at 19:59
  • That's possible only if you have a rooted device, normally you don't have access to `/` but to SD Card and several other directories. – Arkadiusz Drabczyk Jan 24 '22 at 20:05
  • You misunderstand me. The solution I am looking for should know this and give access to the dirs I have access to. I am not looking for a solution where you need to root your phone, but simply one that will give me the same access as any filemanager app on the phone already give. – Ole Tange Jan 24 '22 at 20:08
  • so why did you specify `/` in your example if that's the directory you _cannot_ access? Specify the directory you can access such as `/storage/emulated/0` – Arkadiusz Drabczyk Jan 24 '22 at 20:11
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/133487/discussion-between-ole-tange-and-arkadiusz-drabczyk). – Ole Tange Jan 24 '22 at 20:15
0

ADBFS-rootless is another option, that works better for me than the other alternatives in this thread, when proper SSH is not setup to also work via USB-NET/JumpHost.

It's trivial to compile, the usual small dance:

git clone git://github.com/spion/adbfs-rootless.git
cd adbfs-rootless
make

maybe install libfuse-dev android-tools-adb build-essential git pkg-config before.

Then mount your local usb-connected Android device with ./adbfs ~/droid.

It's originally "configured" to only connect to local ADB devices via source, but can be trivially patched to connect to remotely usb-connected Android devices, using the remote ADBd on the USB-Host as "Jumphost".

You can also use it with USB-IP to connect to Android-devices hooked up to the USB of some WIFI-APs/Routers that way.

If you need to connect to ancient versions of Android, you may need to get statically compiled adb versions for different API-levels, and just make several adbfs-binaries with hardcoded paths to specific adb-versions.

Alex Stragies
  • 5,857
  • 2
  • 32
  • 56