Skip to content

Instantly share code, notes, and snippets.

@prochor666
Last active September 7, 2023 16:44
Show Gist options
  • Save prochor666/6475aaff0e06a846d86f8496c0bbd2fa to your computer and use it in GitHub Desktop.
Save prochor666/6475aaff0e06a846d86f8496c0bbd2fa to your computer and use it in GitHub Desktop.
Mount Google drive under Debian Linux (Jessie and later)

FUSE filesystem over Google Drive

Complete guide to go to hell and back. © @Lion 🔉

Install google-drive-ocamlfuse on Debian Jessie and later.

Preinstall

Source: https://github.com/astrada/google-drive-ocamlfuse/wiki/How-to-install-from-source-on-Debian-Jessie

su
apt-get install software-properties-common sudo ssh
exit

Continue with sudo:

sudo apt-get install opam ocaml make fuse camlp4-extra build-essential pkg-config

Fuse

Create fuse group (if not already present):

sudo groupadd fuse

Debian has a special user group to allow fuse access. Log out, and log back in after this to make change effective:

Replace *username* with your real username

sudo usermod -a -G fuse *username*
sudo chown root:fuse /dev/fuse
sudo chmod 660 /dev/fuse

Install packages

opam init
opam update
opam install depext
eval `opam config env`
opam depext google-drive-ocamlfuse
opam install google-drive-ocamlfuse
. /home/*username*/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true

Reboot

Yes, do it.

sudo reboot

Authorize your account

Source: https://github.com/astrada/google-drive-ocamlfuse/wiki/Headless-Usage-&-Authorization

  • Sign in to your Google account and create a project: https://console.cloud.google.com/
  • Click "API Manager" then "Library" in the left-hand pane (will take you to https://console.cloud.google.com/apis/library). Click on "Drive API", then "ENABLE API".
  • Click "Credentials" in the left hand pane, then click on the button "Create Credentials" (OAuth client ID)
    • Choose "Other"
    • Choose any product name, e.g "My OCAMLDrive".
    • Click "Create". You will get a Client ID, a Client Secret.
  • Authorization: Back in your headless server, run google-drive-ocamlfuse for the first time. I used labels (in this document, I use the label "me") because I plan on using multiple accounts. However you can also run it without the -label parameter and it will use a default name for the label called "default". You will need the Client ID and secret you got from google above.

From version 0.5.3, you should use the -headless option:

Replace *yourClientID* and *yourSecret* with your real credentials

google-drive-ocamlfuse -headless -label me -id *yourClientID*.apps.googleusercontent.com -secret *yourSecret* 

Example output:

Please, open the following URL in a web browser: https://accounts.google.com/o/oauth2/auth?client_id=##yourClientID##.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&response_type=code&access_type=offline&approval_prompt=force
Then, you should open the URL above in a graphical web browser, get the verification code from Google and put it here:
Please enter the verification code: 

That's it. You should be ready to mount.

Replace *username* with your real username

mkdir /home/*username*/gdrive

Try mount:

google-drive-ocamlfuse -label me /home/*username*/gdrive

Mount on startup using systemd

You need mount script and service configuration

Mount script

Source/tips: https://linuxconfig.org/how-to-automatically-execute-shell-script-at-startup-boot-on-systemd-linux

cd /user/local/bin
nano mount-gdrive.sh

Type script content:

Replace *username* with your real username

#!/bin/sh

su *username* -l -c "google-drive-ocamlfuse -label me /home/*username*/gdrive"

Fix permission:

chmod 755 mount-gdrive.sh

Systemd service

Go to systemd directory:

cd /etc/systemd/system
nano gdrive.service

Type in file content:

[Unit]
After=networking.service

[Service]
ExecStart=/usr/local/bin/mount-gdrive.sh

[Install]
WantedBy=default.target

Configure service:

chmod 664 /etc/systemd/system/gdrive.service
systemctl daemon-reload
systemctl enable gdrive.service

Testing before reboot [optional]

Test your configuration:

systemctl start gdrive.service

GG WP 🎮 👏 :feelsgood: 😈 ☕

@Alextremerus
Copy link

Alextremerus commented Aug 25, 2021

Thanks you a lot for this manual!
It was little bit difficult for me (I'm new in Linux, my first week on Linux Debian :)) but I completed it successfully :D. I run this process on Debian 11 "Bullseye".
Also I found that steps at https://console.cloud.google.com/ was changed. Before creating credentials google required to create first OAuth project. During project configurations need to add your email to the testers users list, otherwise it will be not work.
Then you will be able to create new credentials. Also no more option "Other", I chose "Desktop" and it's worked for me.
That's all :)

@Alextremerus
Copy link

Hi @prochor666,
After last google drive update unable to mount google drive :( Any idea what wrong and how to fix it?
image
Thanks!

@prochor666
Copy link
Author

prochor666 commented Sep 17, 2021

I don't use Google drive anymore, sorry, I have no time for testing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment