5

The version of Ubuntu I have (14.04.1) automatically mounts my digital camera and generates a box inviting me to say what to do with it. Since I was dissatisfied with all the options presented, I wrote a script which does exactly what I want, using gphoto2 to access the camera and get files from it. The one problem is that, even if I have specified 'do nothing' to the box, the camera remains mounted and thus, as far as gphoto2 is concerned, unavailable because not released. In order to release it I must open or find a folder display, and specifically eject the camera. I would rather not bother with this step and just let my script run. I am wondering if there is a way to do this.

2 Answers2

2

For Ubuntu 17.10, 18.04, and up, you'll need to use the utility gio (which replaced gvfs-mount).

If the camera is mounted and you have gphoto2 installed, try

gio mount -s gphoto2

but if you want to target the camera specifically:

gio mount -l

will show you the mountable drives.

If you have a camera plugged in, it might look like this:

$ gio mount -l
Drive(0): DA4032
  Type: GProxyDrive (GProxyVolumeMonitorUDisks2)
Volume(0): Canon Digital Camera
  Type: GProxyVolume (GProxyVolumeMonitorGPhoto2)
  Mount(0): Canon Digital Camera -> gphoto2://%5Busb%3A002,002%5D/
    Type: GProxyShadowMount (GProxyVolumeMonitorGPhoto2)
Mount(1): Canon Digital Camera -> gphoto2://%5Busb%3A002,002%5D/
  Type: GDaemonMount

copying the location after the -> will allow you to unmount it via gio mount -u (unmount, if you look at the help: gio help mount

gio mount -u gphoto2://%5Busb%3A002,002%5D/

will unmount the camera via shell. Now, to automate this, you'll need to create a systemd script.

jimbotron
  • 221
0

If you do not want to fiddle with udev (which is a system thing), you can use the udisk interface to unmount the camera.

The camera will normally mount at a fixed place, like /media/user/1234-5678/ or similar (YMMV, depends on how the camera formats the card); and as a device, say /dev/sdc1/.

Now, you can unmount it from your script using

 udisksctl unmount -b /dev/sdc1

the problem is that the device can change; my solution is having this little magic

 udisksctl unmount -b $(mount | grep 1234-5678  | cut -d" "  -f1)

which will work provided that the card id doesn't change.

Rmano
  • 32,167