In this post, I’ll be describing how to setup automatic mounting of one or more Google Drives locally, on your Ubuntu system. Following steps should generally work for the supported Ubuntu versions of the google-drive-ocamlfuse tool. Let’s just right into the setup steps.

Assumptions

Here are the list of assumptions made for descriptive purposes. Please replace them with appropriate values based on your system and environment.

  • Normal user: ubuntu
  • Base path for GDrive mount folders: $HOME/Store (Ex., /home/ubuntu/Store)
  • Gmail address corresponding to the drive: sample01@gmail.com
  • Mount folder for GDrive under base path: gdrive01

Install Google Drive tool for Ubuntu

Thanks to Alessandro Strada for this nice tool called google-drive-ocamlfuse , written in OCAML language. We will be using this tool to mount one or more Google Drives under appropriate folder(s) locally. Pre-built binaries for this tool are available from Ubuntu PPA . It can be installed as follows. For more detailed installation steps and other ways to install and setup your system, please refer to the tool’s link as mentioned earlier.

Install google-drive-ocamlfuse tool by running the following commands in a terminal, with superuser privileges (i.e., sudo).

1sudo add-apt-repository ppa:alessandro-strada/ppa
2sudo apt-get update
3sudo apt-get install google-drive-ocamlfuse
4sudo dpkg --configure -a ## Optional, mainly to complete any pending package configurations

Setup BASH script to mount Google Drive(s)

  1. Open a text editor as normal user and create a new BASH script by name mount-google-drives with the following content. Edit the values in the configuration block based on your need.

     1#!/bin/bash
     2# Script to mount google-drive accounts locally
     3
     4############ Configuration block - START ############
     5## Either 'export' GDRIVE_BASE folder in ~/.bashrc or,
     6## completely hardcode the absolute path here.
     7##
     8## This indicates the base folder under which, various
     9## google-drive account folders are mounted.
    10GDRIVE_BASE=${GDRIVE_BASE:-$HOME/Store}
    11
    12## Define mapping between a google-account label and
    13## corresponding destination folder to mount it. The
    14## mount-dir (i.e., destination folder) will be a folder
    15## within the GDRIVE_BASE.
    16##
    17## The label need not match exactly with your gmail username
    18## part. It's just an identifier to help you in identifying
    19## the mounted google-drive.
    20##
    21## Multiple label-mount-dir can be provided in the array
    22## below, by adding them in their own line.
    23GDRIVE_MAPPING=(
    24  #"label|mount-dir"
    25  "sample01|gdrive01"
    26)
    27############ Configuration block - END ############
    28
    29############ No need to touch anything below this ############
    30for drv in $GDRIVE_MAPPING; do
    31  label=$(echo $drv | awk -F '|' '{print $1}')
    32  mount_dir=$(echo $drv | awk -F '|' '{print $2}')
    33
    34  [[ -z "$label" ]] || [[ -z "$mount_dir" ]] && echo -e "GDrive label or mount-dir not defined!" && exit 1
    35
    36  mount_point="$GDRIVE_BASE/$mount_dir"
    37
    38  CHECK_DRIVE=$(mount | grep -E "$mount_point" | grep -v "grep")
    39  [[ -z "${CHECK_DRIVE}" ]] && mkdir -p $mount_point && google-drive-ocamlfuse -label $label $mount_point && \
    40  sync || echo -e "GDrive for ${label} already mounted"
    41done
    42
    43exit 0

  2. Save the file and close the editor.

  3. Move the file into $HOME/.local/bin folder. If the folder doesn’t exist, create it by running mkdir -p $HOME/.local/bin.

  4. Set the executable bit for the script by running chmod +x $HOME/.local/bin/mount-google-drives.

  5. Ensure that $HOME/.local/bin is set as part of the PATH environment variable by running echo $PATH.

  6. If $HOME/.local/bin is not set as part of the PATH environment, you can add the following line to $HOME/.bashrc file

    1PATH="$HOME/.local/bin:$PATH"
    
  7. Close the terminal.

The script should be good enough for manual mounting of Google drives at any point. This script also ensures that, the Google drives are mounted only once, even if it is run multiple times.

In case, you would like the Google drives to get automated on every login, you just need to do the following.

  1. Open a text editor and create the file mount-google-drives.desktop under $HOME/.config/autostart folder. Create the folder, if it doesn’t already exist.

     1[Desktop Entry]
     2Type=Application
     3Exec=/home/ubuntu/.local/bin/mount-google-drives
     4Hidden=false
     5NoDisplay=false
     6X-GNOME-Autostart-enabled=true
     7Name[en_US]=Google Drives
     8Name=Google Drives
     9Comment[en_US]=Mount Google Drive locally
    10Comment=Mount Google Drive locally
    
    TIP
    Update the absolute path to the `mount-google-drives` script for `Exec` entry based on your username.
    
  2. Save the file and close the editor.

Now, logout of your desktop session and login again. If all the steps are followed correctly, you should see your mounted Google drive(s) locally, using File Explorer or by running df -TH command in a terminal.

Hope it helped you!