Search

Ubuntu 16.04 - Correct GoPro USB access bug

Contents[Hide]

dropcap ubuntu gopro

Under Ubuntu 16.04 Xenial, a nasty bug stops you to mount latest GoPro action cams. 

I discovered this problem while connecting a GoPro Hero Session 4 to my laptop via the USB cable. In Nautilus, the device was showing, but it was showing some weird directories :

  • DCIM_00000001_00000001
  • DCIM_00000001

Both directories were empty.

After some internet search, I realised that this problem seems to occur with few recent models of GoPro action cams.

This short article explains how to solve this problem and to properly mount latest GoPro action cams via USB under Ubuntu 16.04 Xerial. 

It has been tested with an original GoPro Hero and a GoPro Hero Session 4 connected on a Ubuntu Gnome 16.04.1 LTS Amd64 laptop.

ubuntu gopro usb bug

If you don't need any technical explaination and you just want your GoPro to be recognised by your computer, you can jump to section Installation.

1. Explaination

The trouble comes from libgphoto2 library version 2.5.9, which is shipped with Ubuntu 16.04.

It is buggy and doesn't handle properly PTP protocol of latest GoPro camera. Bug is referenced in gphoto project as https://github.com/gphoto/libgphoto2/issues/52.  Hopefully, this bug has been corrected in libgphoto2 version 2.5.10.

So, solution to our problem is quite simple : we need to update libgphoto2 to latest version 2.5.10. 

As Ubuntu Xerial is only providing version 2.5.9, we will need to use Yakkety repository where packages are available in version 2.5.10.

Packages can be downloaded from http://packages.ubuntu.com/yakkety/

To respect gphoto dependencies, we need to install 2 packages in this specific order :

  1.  libgphoto2-port12
  2.  libgphoto2-6

To avoid breaking apt database, we won't install the packages, but instead we will unpack then under /opt/libgphoto2 directory and create some symbolic links to these updated libraries.

With this approach, installation process is fully reversible and transparent to apt package management tool.

As some Ubuntu updates may break the libgphoto2 patch, we will need to setup a patch verification after every package update. This can be done quite easily with an apt hook called DPkg::Post-Invoke, which is called everytime dpkg has done some package installation/removal/update.

2. Main Patch Script

To install and declare latest libgphoto2 libraries, I've written a script which should be placed under /opt/libgphoto2/nautilus-xenial-gopro.

This script, available from my GitHub repository, is in charge of handling libgphoto2 patch. It can run in 3 modes :

  • --install : download and install new libraries
  • --remove : remove new libraries and reinstall original ones
  • --update : re-declare new libraries

/opt/libgphoto2/nautilus-xenial-gopro
#!/usr/bin/env bash
# -------------------------------------------------------------
# Handle installation, update or removal of updated 
# gphoto libraries to avoid corrupted DCIM with latest GoPro
#
# Revision history :
#   20/06/2016, V1.0 - Creation by N. Bernaerts
#   20/07/2017, V2.0 - Complete rework to become update proof
# -------------------------------------------------------------

# if no argument, display help
if [ $# -eq 0 ] 
then
  echo "Tool to install libgphoto2 2.5.10 libraries to correct latest GoPro DCIM bug under Xenial."
  echo "Parameters are :"
  echo "  --install       Install and declare the updated library"
  echo "  --remove        Back to original library"
  echo "  --update        Re-declare updated libraries"
  exit
fi

# loop to retrieve arguments
while test $# -gt 0
do
  case "$1" in
    "--install") MODE="install"; shift; ;;
    "--remove") MODE="remove"; shift; ;;
    "--update") MODE="update"; shift; ;;
    *) shift; ;;
  esac
done

# check --update or --cleanup mode
[ "${MODE}" = "" ] && { echo "Please use --install, --remove or --update mode"; exit 1; }

# select mode
case "${MODE}" in

  # ---------------------------
  #   Installation mode
  # ---------------------------
  "install") 
    
    # remove targeted files and directories 
    rm -f /usr/lib/x86_64-linux-gnu/libgphoto2_port.so.12
    rm -R /usr/lib/x86_64-linux-gnu/libgphoto2_port/0.12.0
    rm -f /usr/lib/x86_64-linux-gnu/libgphoto2.so.6
    rm -R /usr/lib/x86_64-linux-gnu/libgphoto2/2.5.10
    rm -f /lib/udev/hwdb.d/20-libgphoto2-6.hwdb

    # unpack and declare libgphoto2-port12
    wget -O /tmp/libgphoto2-port12.deb http://fr.archive.ubuntu.com/ubuntu/pool/main/libg/libgphoto2/libgphoto2-port12_2.5.10-3_amd64.deb
    dpkg --fsys-tarfile /tmp/libgphoto2-port12.deb | sudo tar xf - -C /opt/libgphoto2
    rm /tmp/libgphoto2-port12.deb
    ln -s /opt/libgphoto2/usr/lib/x86_64-linux-gnu/libgphoto2_port.so.12.0.0 /usr/lib/x86_64-linux-gnu/libgphoto2_port.so.12
    ln -s /opt/libgphoto2/usr/lib/x86_64-linux-gnu/libgphoto2_port/0.12.0 /usr/lib/x86_64-linux-gnu/libgphoto2_port/0.12.0

    # unpack and declare libgphoto2
    wget -O /tmp/libgphoto2.deb http://fr.archive.ubuntu.com/ubuntu/pool/main/libg/libgphoto2/libgphoto2-6_2.5.10-3_amd64.deb
    dpkg --fsys-tarfile /tmp/libgphoto2.deb | sudo tar xf - -C /opt/libgphoto2
    rm /tmp/libgphoto2.deb
    ln -s /opt/libgphoto2/usr/lib/x86_64-linux-gnu/libgphoto2.so.6.0.0 /usr/lib/x86_64-linux-gnu/libgphoto2.so.6
    ln -s /opt/libgphoto2/usr/lib/x86_64-linux-gnu/libgphoto2/2.5.10 /usr/lib/x86_64-linux-gnu/libgphoto2/2.5.10
    ln -s /opt/libgphoto2/lib/udev/hwdb.d/20-libgphoto2-6.hwdb /lib/udev/hwdb.d/20-libgphoto2-6.hwdb
    
    # download and declare apt post install hook
    wget -O /etc/apt/apt.conf.d/99nautilus-xenial-gopro https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/nautilus/99nautilus-xenial-gopro
    ;;

  # ---------------------------
  #   Removal mode
  # ---------------------------
  "remove")
    
    # remove targeted files and directories 
    rm -f /usr/lib/x86_64-linux-gnu/libgphoto2_port.so.12
    rm -R /usr/lib/x86_64-linux-gnu/libgphoto2_port/0.12.0
    rm -f /usr/lib/x86_64-linux-gnu/libgphoto2.so.6
    rm -R /usr/lib/x86_64-linux-gnu/libgphoto2/2.5.10
    rm -f /lib/udev/hwdb.d/20-libgphoto2-6.hwdb

    # remove apt post install hook
    rm /etc/apt/apt.conf.d/99nautilus-xenial-gopro

    # reinstall original packages
    apt-get install --yes --reinstall libgphoto2-6 libgphoto2-port12

    # remove /opt/libgphoto2 directory structure
    rm -R /opt/libgphoto2
    ;;

  # ---------------------------
  #   Update mode
  # ---------------------------
  "update")
    
    # remove targeted files and directories 
    rm -f /usr/lib/x86_64-linux-gnu/libgphoto2_port.so.12
    rm -R /usr/lib/x86_64-linux-gnu/libgphoto2_port/0.12.0
    rm -f /usr/lib/x86_64-linux-gnu/libgphoto2.so.6
    rm -R /usr/lib/x86_64-linux-gnu/libgphoto2/2.5.10
    rm -f /lib/udev/hwdb.d/20-libgphoto2-6.hwdb

    # create links
    ln -s /opt/libgphoto2/usr/lib/x86_64-linux-gnu/libgphoto2_port.so.12.0.0 /usr/lib/x86_64-linux-gnu/libgphoto2_port.so.12
    ln -s /opt/libgphoto2/usr/lib/x86_64-linux-gnu/libgphoto2_port/0.12.0 /usr/lib/x86_64-linux-gnu/libgphoto2_port/0.12.0
    ln -s /opt/libgphoto2/usr/lib/x86_64-linux-gnu/libgphoto2.so.6.0.0 /usr/lib/x86_64-linux-gnu/libgphoto2.so.6
    ln -s /opt/libgphoto2/usr/lib/x86_64-linux-gnu/libgphoto2/2.5.10 /usr/lib/x86_64-linux-gnu/libgphoto2/2.5.10
    ln -s /opt/libgphoto2/lib/udev/hwdb.d/20-libgphoto2-6.hwdb /lib/udev/hwdb.d/20-libgphoto2-6.hwdb
    ;;

  *)
    ;;

esac

# update hardware database
udevadm hwdb --update

# restart udev service
service udev restart

3. Make it Update Proof

When you make some Ubuntu package updates, the patch installed by /opt/libgphoto2/nautilus-xenial-gopro may be broken. You'll then loose access to your GoPro.

As apt provides some hook mechanism, it is possible to create a simple /etc/apt/apt.conf.d/99nautilus-xenial-gopro script that will provide the hook to call /opt/libgphoto2/nautilus-xenial-gopro in --update mode everytime a package is handled by dpkg (the low level package management software).

This way, if anything is broken by a dpkg command, il will be repaired immediatly after the command has been issued. Any package update should then be patch proof.

/etc/apt/apt.conf.d/99nautilus-xenial-gopro
## This file is provided by nautilus-xenial-gopro
## to re-declare the patch after apt upgrade

# Verify Nautilus GoPro patch when dpkg has been executed (i.e. after apt upgrade)
DPkg::Post-Invoke { "/opt/libgphoto2/nautilus-xenial-gopro --update"; };

4. Installation

To make it simple, complete installation process has been scripted and can be run with these simple terminal commands :

Terminal
# wget https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master/nautilus/nautilus-xenial-gopro-install.sh
# chmod +x nautilus-xenial-gopro-install.sh
# ./nautilus-xenial-gopro-install.sh

New libgphoto2 libraries are now installed, fully declared and package update proof.

You now need to plug your GoPro or to reboot your computer to get a fully operational USB access to your GoPro action cam.

ubuntu gopro usb ok

5. Removal

If, for any reason, you need to reverse to original libgphoto2 Xenial libraries, you just need to run :

Terminal
# sudo /opt/libgphoto2/nautilus-xenial-gopro --remove

Everything will be removed and original libgphoto2 libraries will be reinstalled.


Hope it helps.

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus