Digital Cameras, Linux, and BSD
Using Your Digital Camera
There are several sections to this page, jump to what you need:
Attaching the camera or phone
Mass storage, MTP, or PTP?
Using MTP
Using PTP
How to Recover Deleted Images
Attach the camera to the USB port, verify that it's seen
The kernel should detect the USB device.
On Linux,
lsusb
should display a line showing the device.
On BSD, use usbdevs
.
With either command, add the -v
option for verbose output and many more details.
Linux% lsusb Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 003 Device 003: ID 05e3:0761 Genesys Logic, Inc. Genesys Mass Storage Device Bus 003 Device 004: ID 04ca:707f Lite-On Technology Corp. USB Storage Bus 003 Device 002: ID 05e3:0608 Genesys Logic, Inc. Hub Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 003: ID 0bda:b00b Realtek Semiconductor Corp. Bluetooth Radio Bus 001 Device 015: ID 22b8:2e82 Motorola PCS moto z4 Bus 001 Device 002: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
BSD% usbdevs addr 1: EHCI root hub, Intel addr 2: 802.11 n WLAN, Ralink addr 1: EHCI root hub, Intel addr 2: USB PTP Camera, Fuji Photo Film addr 1: UHCI root hub, Intel addr 1: UHCI root hub, Intel addr 1: UHCI root hub, Intel addr 1: UHCI root hub, Intel addr 1: UHCI root hub, Intel addr 1: UHCI root hub, Intel
usbview
may provide a detailed graphical user interface for
examining USB devices.
Mass storage, MTP, or PTP?
There are three entirely different methods of data storage on digital cameras:
- USB Mass Storage Device
- Picture Transfer Protocol or PTP
- Media Transfer Protocol or MTP
If your camera behaves as a mass storage device, it will appear as a SCSI disk. Mount it with something like the following:
% mount /dev/sda1 /media/camera
The device will be something like /dev/sd0i
on BSD.
How can you tell what the device name is?
It will probably be the first partition of some
SCSI/SATA device, but how do you get the specific name?
If you can't just guess, on Linux you could ask for your
partition tables as root
:
# fdisk -l
You could also see what the kernel has recently noticed:
% dmesg | grep 'sd[a-z]'
How can you allow an ordinary user to mount removeable
file systems?
Specify this in /etc/fstab
:
% grep media /etc/fstab /dev/sda1 /media/camera auto user 0 0
However, it seems that most newer cameras do not support USB mass storage. You will need to use some user-space tools.
Using MTP
The desktop environment on my Mint laptop uses MTP with some GTK tools and daemons. While it works fine with USB disks and flash drives, it does not work with a camera. I get a pop-up with this error message:
Unable to open a folder for moto z4 No such interface "org.gtk.vfs.Mount" on object at path /org/gtk/vfs/mount/1
I see these processes running:
$ ps axuww | egrep 'PID|gvfs' USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND cromwell 21249 0.0 0.1 239708 7588 ? Ssl 01:09 0:00 /usr/libexec/gvfsd cromwell 21254 0.0 0.1 378336 6484 ? Sl 01:09 0:00 /usr/libexec/gvfsd-fuse /run/user/1000/gvfs -f -o big_writes cromwell 28501 0.0 0.1 388012 9404 ? Ssl 08:49 0:00 /usr/libexec/gvfs-udisks2-volume-monitor cromwell 28507 0.0 0.1 316716 8804 ? Ssl 08:49 0:00 /usr/libexec/gvfs-afc-volume-monitor cromwell 28512 0.0 0.1 238104 6236 ? Ssl 08:49 0:00 /usr/libexec/gvfs-gphoto2-volume-monitor cromwell 28516 0.0 0.0 235872 5996 ? Ssl 08:49 0:00 /usr/libexec/gvfs-goa-volume-monitor cromwell 28520 0.0 0.1 236312 6808 ? Ssl 08:49 0:00 /usr/libexec/gvfs-mtp-volume-monitor cromwell 28524 0.0 0.1 313800 7936 ? Sl 08:49 0:00 /usr/libexec/gvfsd-trash --spawner :1.192 /org/gtk/gvfs/exec_spaw/1 cromwell 28541 0.0 0.1 387940 8580 ? Sl 08:49 0:00 /usr/libexec/gvfsd-network --spawner :1.192 /org/gtk/gvfs/exec_spaw/2 cromwell 28558 0.0 0.3 524540 23352 ? Sl 08:49 0:00 /usr/libexec/gvfsd-smb-browse --spawner :1.192 /org/gtk/gvfs/exec_spaw/3 cromwell 28566 0.0 0.1 314980 8212 ? Sl 08:49 0:00 /usr/libexec/gvfsd-dnssd --spawner :1.192 /org/gtk/gvfs/exec_spaw/4 cromwell 29450 0.0 0.1 162796 6788 ? Ssl 08:56 0:00 /usr/libexec/gvfsd-metadata cromwell 31197 0.3 1.5 676336 92964 ? Sl 09:44 0:03 nemo /run/user/1000/gvfs/mtp:host=motorola_moto_z4_ZY226VKDSH cromwell 31233 0.0 0.1 470468 9252 ? Sl 09:44 0:00 /usr/libexec/gvfsd-mtp --spawner :1.192 /org/gtk/gvfs/exec_spaw/7
Kill those processes:
$ pkill gvfsgo-mtpfs
Unplug the phone, and plug it back in.
Do what's needed to enable file transfer. On my Motorola "moto z4", that's:
- Swipe down to see notifications.
- Tap "Android System: Charging this device via USB"
- Tap "Tap for more options"
- Tap "File Transfer"
Now go-mtpfs
and gphoto2
and related tools will work.
go-mtpfs
uses FUSE, a user-space file system.
You create a mount point, and then mount the device there.
By default it runs in the foreground, so start it in the
background to use the same terminal to interact with the
file system.
$ mkdir /tmp/phone $ go-mtpfs /tmp/phone & $ df -hT /tmp/phone Filesystem Type Size Used Avail Use% Mounted on Locked(fs.rootNode) fuse.Locked(fs.rootNode) 169G 22G 148G 13% /tmp/phone
Now let's browse the result.
The mounted file system contains what actually is two
file systems: that of the phone itself, plus the one
on the Micro SD memory card.
My memory card has a file system label of
ANDROID
, and so change that for your card.
$ ls -F /tmp/phone ANDROID/ Internal shared storage/ $ ls -F /tmp/phone/Internal\ shared\ storage Alarms/ DCIM/ Movies/ Notifications/ Podcasts/ Android/ Download/ Music/ Pictures/ Ringtones/ cromwell@aphrodite:~$ ls -F /tmp/phone4/ANDROID/ $ ls -F /tmp/phone/ANDROID Android/ Download/ Movies/ Pictures/ alarms/ notifications/ DCIM/ LOST.DIR/ Music/ Podcasts/ media/ ringtones/
My pictures are now in:
/tmp/phone/ANDROID/DCIM/Camera/
I can change to that directory, list what's there,
view them, and then copy or move them to the computer.
The
gphoto2
tool is more suited for scripting.
To download all the pictures from the command line, simply use:
% cd /path/to/desired/storage/area % gphoto2 -P
See
the gphoto2
manual page
for far more.
Using PTP
The
Konqueror browser
part of the KDE desktop,
understands PTP.
Just bring up a Konqueror browser and change the location
to camera:/
That should let you browse the camera's storage. The URL ends up being something like this:
camera://USB%20PTP%20Class%20Camera@[usb:004,006]/store_10000001/DCIM/101_FUJI
Of course, that 004,006
,
indicating USB bus #4 and device #6,
will depend on where you attach your camera.
See the lsusb
output above for how you can
figure out in advance what this will be.
However, Konqueror will give give you icons to click on:
USB PTP Class Camera
, then
store_10000001
, then
DCIM
, then
101_FUJI
(or however your camera identifies itself).
How to Recover Deleted Images
recoverjpeg
is a very nice tool.
Get it from
rfc1149.net
or from
free(code).
If your camera works as a USB mass storage device,
you can simply find its device name (it will appear
as if it were a SCSI or SATA disk, use fdisk -l
to figure out its name).
Then you can image the camera's memory into a file,
and extract images from there:
$ cd $ dd if=/dev/sdb of=camera-image bs=1M $ recoverjpeg camera-image
Or you could simply recover the JPEG image files directly, there is no real need to save an image of the camera's memory:
$ cd $ recoverjpeg /dev/sdb
If, on the other hand, your camera uses the
Picture Transfer Protocol, or PTP,
then as far as I know you will have to put the memory card
into a reader so it appears as a USB mass storage device.
I don't think there's a way of using the PTP interface
to directly access or copy the memory.
See
the gphoto2
manual page
for far more, maybe there's a way to image or directly
access the memory.