Mounting an Android phone on Debian Linux to synchronise files
Last updated: Nov 5, 2022
In this post I show how to mount the internal storage of an Android phone so that folders can be updated using e.g. FreeFileSync.
An Android phone can be automagically mounted using a file explorer such as Nautilus to copy and paste files. However I cannot use FreeFileSync to synchronise files to a folder on the phone.
This blog post explains a method that worked for me in December 2021 to solve this issue.
I tested this successfully on a Oneplus 6 phone running LineageOS enchilada (based on Android v11) and on a Sony G8411 running Android v9.
The tool I use is jmtpfs.
To install this in Debian:
sudo aptitude install jmtpfs
Create a directory to mount the phone’s internal storage
We need to create a file to mount the Android phone in.
This creates a folder called ‘phone’ in your home directory in the subdirectory ’tmp’. You can name the folder anything else that you like.
Connect your Android phone to the Debian system
Connect your Android phone using a USB cable. For my phone running Lineage OS based on Android v11, I used the following to allow the internal storage to be accessible by the Debian system:
Go to settings. Search on USB, select ‘USB controlled by’. On the next screen: Select USB controlled: by ‘This device’ and use USB for: File transfer.
For the phone running Android v9, a message box comes up as soon as I connect the phone to the Debian system asking ‘Allow access?’. Click on ‘allow’.
The menu system in Android changes with each update, so the above instructions may not be accurate for your version of Android.
Mount the phone’s internal storage
Back on your Debian terminal mount the phone’s internal storage to the directory ~/tmp/phone using:
You should now be able to use the directory or subdirectories in ~/tmp/phone to sync with or move and delete files through the command line or file explorer.
Mounting under /media
For whatever reason, I could only get the method to work by creating the new folder under my home directory. I couldn’t get it to work by creating a new folder under /media, even though I changed the ownership and group name of the directory I created to my username.
Marcel sent a comment to this blog that solves this for him, but I couldn’t get the method to work on my system:
- Change the group and user of the mount point (e.g. /media/phone) to a normal non root user 2) jmtpfs /media/phone (WITHOUT sudo )
Unmount the phone’s internal storage
To end the session, exit from anything that is accessing the directory with the phone’s internal storage in. Then unmount the directory using:
fusermount -u /tmp/mtp
Then unplug your phone.