Skip to main content

Mount Google Drive

To mount your google drive as a network storage location on Linux, check out google-drive-ocamlfuse. It's a very useful cli tool to quickly mount your google drive to a local directory.

I don't see why I should duplicate the official installation instructions, see there for instructions to setup the utility on Ubuntu. Once that's done, you can mount your Google Drive with a simple command

mkdir /path/to/mount/directory
google-drive-ocamlfuse /path/to/mount/directory

Usually, I do something like this

mkdir /path/to/mount/directory
google-drive-ocamlfuse ~/GDrive

Once running this command, a browser will open and you can select the google account to authenticate with. The Drive associated with this account is the one that will mount to the directory.

User configurations are in ~/.gdfuse/default/ by default. Setting download_docs=false in ~/.gdfuse/default/config can sometimes help for mounting drives with a large number of Google Docs files.

I have had the following issue randomly appear when hopping between i3 and plasma desktop sessions. For now I'm just documenting it, I'll report findings on the GitHub soon.

kapper@xps:~$ ls GDrive 
ls: cannot access 'GDrive': Transport endpoint is not connected
kapper@xps:~$ ls .config/autostart-scripts/
kapper@xps:~$ rm -r GDrive 
rm: cannot remove 'GDrive': Transport endpoint is not connected
kapper@xps:~$ sudo rm -r GDrive 
[sudo] password for kapper: 
rm: cannot remove 'GDrive': Is a directory
kapper@xps:~$ ll
ls: cannot access 'GDrive': Input/output error
total 772
drwxr-xr-x 39 kapper kapper   4096 Dec 20 12:33 ./
drwxr-xr-x  3 root   root     4096 Dec  6 09:28 ../
lrwxrwxrwx  1 kapper kapper     17 Dec  6 17:44 .bash_aliases -> dot/.bash_aliases
-rw-------  1 kapper kapper  29382 Dec 20 12:29 .bash_history
-rw-r--r--  1 kapper kapper    220 Dec  6 09:28 .bash_logout
lrwxrwxrwx  1 kapper kapper     11 Dec  6 17:44 .bashrc -> dot/.bashrc
-rw-rw-r--  1 kapper kapper    172 Dec 18 14:39 .bash_secrets
drwx------  3 kapper kapper   4096 Dec 20 01:00 .gdfuse/
d?????????  ? ?      ?           ?            ? GDrive/
-rw-rw-r--  1 kapper kapper     54 Dec 13 15:15 .gitconfig

To fix this, we first need to get the ~/GDrive directory in a workable state again. The mountdrive.sh script in the command below is a script I wrote to mount my drive automatically. This file will not exist on your system, but for this first step you should make sure you have no script or automation that mounts your Google Drive on reboot or login, then reboot the system. Optionally, you can try to run sudo umount --force /path/to/mount/directory instead of rebooting.

rm ~/.config/autostart-scripts/mountdrive.sh
sudo reboot now

When logging back in, we can see the directory is fine, so we made some progress

kapper@xps:~$ ls GDrive/
kapper@xps:~$ ll
total 772
drwxr-xr-x 39 kapper kapper   4096 Dec 20 12:33 ./
drwxr-xr-x  3 root   root     4096 Dec  6 09:28 ../
lrwxrwxrwx  1 kapper kapper     17 Dec  6 17:44 .bash_aliases -> dot/.bash_aliases
-rw-------  1 kapper kapper  29382 Dec 20 12:29 .bash_history
-rw-r--r--  1 kapper kapper    220 Dec  6 09:28 .bash_logout
lrwxrwxrwx  1 kapper kapper     11 Dec  6 17:44 .bashrc -> dot/.bashrc
-rw-rw-r--  1 kapper kapper    172 Dec 18 14:39 .bash_secrets
drwx------  3 kapper kapper   4096 Dec 20 01:00 .gdfuse/
drwxrwxr-x  2 kapper kapper   4096 Dec 19 23:52 GDrive/
-rw-rw-r--  1 kapper kapper     54 Dec 13 15:15 .gitconfig

Next, we remove all configurations for google-drive-ocamlfuse that are stored in our home directory. To do this, run the command below. Note that this will remove all authentication with your google accounts.

sudo rm -r ~/.gdfuse/default/*

Now we can just reauthenticate and the drive will mount successfully. This is the only workaround I have found so far, and I'm not sure how I can reproduce the bug. I tried clearing the cache with the -cc flag, and that did not fix the problem.

google-drive-ocamlfuse ~/GDrive