One would think that since Android is a Linux-based operating system, that integration between Android devices and Linux computers would work rather seamlessly. Unfortunately, that’s not always the case. Things have, however, improved over the years. Here are a few of the tools that I’ve used in the past to transfer my photos from my Android mobile phone to my Debian laptop system.
Usually it’s not possible to mount a mobile phone’s storage device directly
to your computer (for instance, as if it were a USB drive). The Android
device can, however, report itself as a camera (e.g. via the “Connect as
Camera (PTP)” option when connecting the device to a computer via USB) and
therefore one can use the
gphotofs command from the gPhoto
project to expose the camera as a filesystem (hence
fs in the command’s name). The gPhoto library behind the command
speaks the Picture Transfer Protocol
(PTP) and hence
can be used either with a normal digital camera or (as in the case discussed
here) an Android mobile phone.
To get started, first install the package:
$ sudo apt install gphotofs
Before we can start backing up photos, we need to create a mountpoint for the filesystem to be mounted, as well as a location to which we can back up the images.
Create a directory onto which we want to mount the filesystem
$ mkdir -p ~/Camera/mnt
and the directory into which the images will be copied1:
$ mkdir -p ~/Camera/ShiftPhone
Now set the mobile phone to PTP mode (when connected via USB, connect “as a camera”).
The filesystem can now be simply mounted via the
$ gphotofs ~/Camera/mnt
Let’s have a look what’s in the mounted directory:
$ ls ~/Camera/mnt store_00010001
This directory contains two further directories,
~/Camera/mnt/store_00010001/ ├── DCIM │ └── Camera └── Pictures
DCIM directory should be familiar to you if you’ve seen directories
stored on a digital camera before. If you haven’t, don’t worry, you just
need to know that there’s a
Camera subdirectory which contains all of the
images we want to back up.
If you look at a directory listing of the
Camera directory, you will
probably find lots of JPEG images (and maybe some MP4 video files if you’ve
recorded some videos). Let’s back up all of these files to our backup
$ rsync -av ~/Camera/mnt/store_00010001/DCIM/Camera/ ~/Camera/ShiftPhone/
Now that we’ve finished using using the mountpoint we can unmount it:
$ fusermount -u ~/Camera/mnt
Another option is the
gphoto2 command line
interface to digital cameras. This is more of a direct interface to the
files the camera makes available.
Although this is part of the gPhoto suite of applications, it comes as a separate package on Debian. Therefore, the first thing to do is to install it:
$ sudo apt install gphoto2
gphoto2 has lots of options, as you will be able to see by passing the
--help option to the command, or by reading the man page.
$ gphoto2 --help $ man gphoto2
For a quick start guide about using the
gphoto2 command line interface,
check out the gPhoto docs for
After connecting your phone to your laptop via USB–and ensuring that it’s
connected as a Camera via PTP–you can check if
gphoto2 can detect the
camera. You do this by passing
--auto-detect option, e.g.
for my SHIFT phone:
$ gphoto2 --auto-detect Model Port ---------------------------------------------------------- USB PTP Class Camera usb:001,040
That’s cool, it seems that the camera has been detected. We can get more
information about what’s been detected by using the
Camera summary: Manufacturer: SHIFT Model: SHIFT6m Version: 1.0 Serial Number: Capture Formats: Display Formats: Undefined Type, Association/Directory, Text, HTML, MS Wave, MP3, MPEG, JPEG, TIFF EP, BMP, GIF, JFIF, PNG, TIFF, Unknown(b901), Unknown(b902), Unknown(b903), Unknown(b982), Unknown(b983), Unknown(b984), Unknown(ba05), Unknown(ba10), Unknown(ba11), Unknown(ba14), Unknown(ba82), Unknown(b906), DNG Device Capabilities: File Download, File Deletion, File Upload No Image Capture, No Open Capture, No vendor specific capture Storage Devices Summary: store_00010001: StorageDescription: Interner gemeinsamer Speicher VolumeLabel: None Storage Type: Builtin RAM Filesystemtype: Generic Hierarchical Access Capability: Read-Write Maximum Capability: 53387345920 (50914 MB) Free Space (Bytes): 36395479040 (34709 MB) Free Space (Images): 1073741824 Device Property Summary: Property 0xd401:(readwrite) (type=0x0) Undefined Property 0xd402:(readwrite) (type=0x0) Undefined Image Size(0x5003):(read only) (type=0xffff) '1920x1920' Battery Level(0x5001):(read only) (type=0x2) Range [0 - 100, step 1] value: 100% (100) Property 0xd407:(read only) (type=0x6) 0
As you can see, there is a lot of information one can ascertain about the camera which has been attached. We see that it’s from the company SHIFT and what its model is, namely a SHIFT6m, which is correct. Obviously you will see different information here, unless you’ve also bought a SHIFT6m.
Now that we’re happy that the information about the attached device is
as we expect, we can find out what files are available on the camera. This
we find out by using the
$ gphoto2 --list-folders There is 1 folder in folder '/'. - store_00010001 There are 2 folders in folder '/store_00010001'. - DCIM - Pictures There is 1 folder in folder '/store_00010001/DCIM'. - Camera There are 0 folders in folder '/store_00010001/DCIM/Camera'. There are 2 folders in folder '/store_00010001/Pictures'. - Telegram - Twitter There are 0 folders in folder '/store_00010001/Pictures/Telegram'. There are 0 folders in folder '/store_00010001/Pictures/Twitter'.
Here we see effectively the same directory structure as in the
example above. Now that we know where the files are, we need to get them
somehow; after all, we want to back the files up to the laptop, not just
see what’s available!
Assuming we have the same directory structure outlined above, we can change
~/Camera/ShiftPhone directory and use the
option to copy the files to the current directory on the laptop’s hard drive:
$ cd ~/Camera/ShiftPhone $ gphoto2 --get-all-files --folder=/store_00010001/DCIM/Camera
Note that we specify here the path to the directory containing the images
that the mobile phone’s camera has taken. This allows you to avoid the funny
pictures that your coworkers sent to you via Telegram or the cat video you
found on Twitter. The default value of the
--folder option is
means that quite literally all files will be retrieved, but that’s not
what we want to do here, hence we limit the source directory to get only the
files we are interested in.
You should see output something along these lines:
Saving file as IMG_20190604_124651_4.jpg Saving file as IMG_20190604_124730_4.jpg Saving file as IMG_20190605_135402_5.jpg Saving file as IMG_20190619_124805_0.jpg Saving file as IMG_20190630_155523_4.jpg Saving file as IMG_20190701_150034_4.jpg Saving file as IMG_20190702_115445_6.jpg Saving file as IMG_20190722_160812_1.jpg Saving file as IMG_20190722_160821_2.jpg Saving file as IMG_20190723_160056_3.jpg Saving file as IMG_20190723_162642_5.jpg Downloading... |----------------- - 38.5%
and the files will downloaded from the phone to the current directory.
Note that since we didn’t mount any filesystems, there’s no need to unmount anything, hence we’re done with the backup! Yay!
The final option that I’d like to mention is
jmtpfs. This is a user-space
filesystem for accessing Media Transfer Protocol
(MTP) devices. The
Media Transfer Protocol is useful for devices that don’t allow (or don’t
support) USB mass storage. In other words, it’s useful for devices that you
can’t just mount like a USB stick. For more Debian-related details
concerning MTP, see the Debian MTP page.
jmtpfs you’ll need to install the package, if you haven’t done so
$ sudo apt install jmtpfs
Connect your mobile phone to your laptop via USB and ensure it is attached
as a media device (MTP). If you check the
dmesg output you’ll notice that
a new USB device has been connected, e.g. for my phone I got this output:
[675519.623499] usb 1-9: USB disconnect, device number 40 [675520.113262] usb 1-9: new high-speed USB device number 41 using xhci_hcd [675520.134432] usb 1-9: New USB device found, idVendor=0e8d, idProduct=201d, bcdDevice=ff.ff [675520.134441] usb 1-9: New USB device strings: Mfr=3, Product=4, SerialNumber=5 [675520.134446] usb 1-9: Product: SHIFT6m [675520.134449] usb 1-9: Manufacturer: MediaTek [675520.134453] usb 1-9: SerialNumber:
This might look like you might be able to just mount the device as a USB
stick, but it’s not quite enough, hence the need for a tool like
Assuming that we’ve got the directory layout described in the section about
gphotofs above, you can now mount the device by using the
$ jmtpfs ~/Camera/mnt Device 0 (VID=0e8d and PID=201d) is a MediaTek Inc Elephone P8000. Android device detected, assigning default bug flags
Having a look at the contents of the
~/Camera/mnt directory, you’ll see
something like this:
ls ~/Camera/mnt/ 'Internal Storage'
The directory name could be different, depending upon the language you use
on your phone. For instance, mine says
'Interner gemeinsamer Speicher'
because my phone’s default language is German. Your situation might also
'Phone storage'. Either way, you should see something that points to
the storage device on your phone.
If you look inside this directory, you’ll see many more directories than
were available with
gphotofs, for instance
Pictures among many others. As with the
example, we aren’t interested in the
Pictures folder but the
folder (again, we want to avoid cat videos and funny meme pictures from
To transfer the files taken with the phone’s camera, we can again use
rsync as we did in the
$ rsync -av ~/Camera/mnt/Internal\ Storage/DCIM/Camera/ ~/Camera/ShiftPhone/
Note that the only real difference between this example and the one
mentioned in the first section is the
Internal\ Storage component. You
might also notice that transferring files with
jmtpfs isn’t as fast as
gphoto2, however with
jmtpfs we have the ability to
access more files than is possible with the other options should we wish to.
When the files have finished transferring, simply use
$ fusermount -u ~/Camera/mnt
to unmount the partition and ensure all buffered data is written to disk.
Our photos are now all nicely backed up. Nice!
I remember in the days before
jmtpfs came on the scene that it was quite
frustrating trying to access the files on my Android device and that it
seemed to be easier on Windows or MacOS rather than on Linux, which seemed
silly given Android’s Linux foundation. Fortunately, things have improved
over the years and there are several options one can use to access the
photos, documents, videos and other files saved on your Android phone and
transfer them to your laptop if you want or need to.
If you liked this post and want to see more like this, please buy me a coffee!