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.
-
It's possible using udev rules: http://askubuntu.com/questions/301122/prevent-a-specific-usb-device-from-auto-mounting – Flint Dec 06 '14 at 06:23
2 Answers
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.

- 211
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.

- 31,947
-
1The camera (a Nikon Coolpix p90) is being connected via PTP. As a result it does not appear mounted on anything in /media, nor does it appear in mtab. This is a feature introduced with 14.04, I believe. In earlier versions of 14.04, many digital cameras could not be connected. The present arrangement seems to be patch. In order to 'release' the camera from gphoto2's point of view, I have to ask for a folder to be opened (that is, directory contents displayed in a window) and then 'eject' it. There is no obvious command-line way to do this. – Starrygordon Dec 07 '14 at 03:58