How to mount Google Drive on Linux

Last updated on January 14, 2021 by Dan Nanni

In the past, close to 30K people signed up for a online petition, desperately wanting to have an official native Linux client for Google Drive, and yet their voice is still being ignored by Google. Perhaps when it comes to boosting their bottom line, Linux desktop market is not a priority for Google.

They can ignore Linux desktop market all they want, but they cannot ignore the power of FOSS. Faced with the frustration, the open-source community respondded, producing unofficial Google Drive clients such as Grive or SyncDrive. These clients are file synchronization tools which sync files and folders between local file system and remote Google Drive. As such, you cannot mount Google Drive using these tools.

If you want to mount Google Drive on Linux, you can try google-drive-ocamlfuse (gdfuse), which is a FUSE-based file system backed by Google Drive. Using this user-space file system, you can mount your Google Drive account on Linux, and have full read/write access to files/folders stored in your Google Drive as if they were local files/folders.

In this tutorial, I will describe how to mount Google Drive on Linux with google-drive-ocamlfuse. google-drive-ocamlfuse is written in OCaml, and you can use OPAM (OCaml package manager) to install google-drive-ocamlfuse and its dependencies. The following guide shows distro-specific instructions to install google-drive-ocamlfuse.

Install google-drive-ocamlfuse on Debian and Ubuntu

These instructions are tested on Debian 10 (buster) and Ubuntu 20.04 (focal). If you have success on other versions of Debian/Ubuntu, let me know.

The first step is to install OPAM. Luckily OPAM is available in the base repository of Debian 10 and Ubuntu 20.04. So simply install it with:

$ sudo apt install opam

Next, start OPAM as follows. It will ask you a series of questions for OPAM initialization. You can press ENTER each time to choose default answers.

$ opam init

Next, update OPAM package repositories.

$ opam update

OPAM has a useful tool called depext which can resolve external dependencies of OPAM packages. depext automatically detects and installs external dependencies of google-drive-ocamlfuse using apt-get package manager.

$ opam install depext

Now go ahead and install external dependencies of google-drive-ocamlfuse with depext. As shown below, several DEB packages (e.g., libfuse-dev libsqlite3-dev, m4) are installed by depext.

$ opam depext google-drive-ocamlfuse

Finally, install google-drive-ocamlfuse with opam.

$ opam install google-drive-ocamlfuse

After successful build, the google-drive-ocamlfuse binary will be found in ~/.opam/default/bin. Add this path to your PATH environment variable.

$ vi ~/.bashrc
PATH="$PATH:$HOME/.opam/default/bin"
$ source ~/.bashrc

Install google-drive-ocamlfuse on Ubuntu via PPA

The author of google-drive-ocamlfuse maintains the PPA repository for google-drive-ocamlfuse. So you can install it on Ubuntu and its derivatives such as Linux Mint more easily.

$ sudo add-apt-repository ppa:alessandro-strada/ppa
$ sudo apt update
$ sudo apt install google-drive-ocamlfuse

Install google-drive-ocamlfuse on Fedora

These instructions are tested on Fedora 33. If you have success on other versions of Fedora, let me know.

The procedure starts with installing OPAM, which makes installation of google-drive-ocamlfuse painless. OPAM is included in the base repository of Fedora 33.

$ sudo yum install opam

Next, initialize OPAM as follows. It will ask you a series of questions for OPAM initialization. You can press ENTER each time to accept default answers.

$ opam init

Next, update OPAM package repositories with:

$ opam update

Next, install an OPAM package called depext, which can install external dependencies of google-drive-ocamlfuse using Fedora's yum package manager.

$ opam install depext

Go ahead and install external dependencies of google-drive-ocamlfuse. As shown below, several RPM packages (e.g., fuse-devel gmp-devel, sqlite-devel) are installed with yum.

$ opam depext google-drive-ocamlfuse

Finally, install google-drive-ocamlfuse with opam.

$ opam install google-drive-ocamlfuse

After successful build, the google-drive-ocamlfuse executable will be found in ~/.opam/default/bin. Add this path to your PATH environment variable.

$ vi ~/.bashrc
PATH="$PATH:$HOME/.opam/default/bin"
$ source ~/.bashrc

Install google-drive-ocamlfuse on Other Linux Systems

If you want to install google-drive-ocamlfuse on other Linux distros, the easiest way is to first install OPAM. Most modern Linux distributions provide OPAM in their repositories. Once OPAM is installed, the rest of the steps should be the same as Debian, Ubuntu and Fedora described above.

Mount Google Drive with google-drive-ocamlfuse

The first step to configure google-drive-ocamlfuse is to run it in your home directory without any argument:

$ google-drive-ocamlfuse

This will open up a web browser window, asking you to log in to your Google account. After logging in, you will see the following screen, requesting for permission. Click on Allow.

Next you have to grant gdfuse access to your Google Drive. Click on Allow.

Subsequently, the browser window will say:

The application was successfully granted access. Please wait for the client to retrieve the authorization tokens

At this point, if you go back to the termain window where google-drive-ocamlfuse was launched, you will see the message:

Access token retrieved correctly.

If, for whatever reason, you see the following error, simply restart google-drive-ocamlfuse from the terminal and go through Google authorization steps again.

Cannot get token. Quitting.

At this point, the initial configuration is completed. You should see a new directory named ~/.gdfuse/default created, which contains the configuration file config and file cache.

Now proceed to create a local mount point for your Google Drive and mount Google Drive as follows.

$ mkdir ~/googledrive
$ google-drive-ocamlfuse ~/googledrive

At this point, your Google Drive should be accessible via ~/googledrive. You can use the mount command to verify that.

$ mount | grep google

You can also check how much space is left on your Google Drive account by using df command.

$ df ~/googledrive

To unmount Google Drive from your file system, simply run:

$ fusermount -u ~/googledrive

Mount Multiple Google Drive Accounts Simultaneously

If you have more than one Google Drive account, you can mount them simultaneously. In this case, use -label option to distinguish between them as follows.

$ google-drive-ocamlfuse -label [label] [mountpoint]

Note that the original Google Drive you mounted without any label in the above is assigned the label called default.

Every time you configure google-drive-ocamlfuse with a new label, you will need to go through the same Google authentication procedure described above, but for a different Google account. After that, ~/.gdfuse/[label] will be created to store configuration data for the different Google account.

Auto-mount Google Drive upon Boot

If you want to have Google Drive mounted automatically upon boot, you can use systemd to do that. Create the following systemd unit file. In this example, the user account being used is dan, and the paths for google-drive-ocamlfuse and the mount point are defined accordingly. So adjust them based on your environment.

$ sudo vi /etc/systemd/system/google-drive.service
[Unit]
Description=FUSE filesystem over Google Drive
After=network.target

[Service]
User=dan
Group=dan
ExecStart=/home/dan/.opam/default/bin/google-drive-ocamlfuse -label default /home/dan/googledrive
ExecStop=fusermount -u /home/dan/googledrive
Restart=always
Type=forking

[Install]
WantedBy=multi-user.target
Alias=google-drive.service

Now reload systemd and test-run it with:

$ sudo systemctl daemon-reload
$ sudo systemctl start google-drive

Verify that the status of the Google Drive systemd service is active:

$ sudo systemctl status google-drive

Now if you reboot your system, your Google Drive account will be automatically mounted and ready for use by systemd.

If you don't want to use systemd, you can also use /etc/fstab or pam_mount to auto-mount Google Drive. Refer to the official document for details.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean