Mount Google Drive

Attention is for more advanced users that have some basic knowledge about Linux. This guide is provided without any guarentees or support.

Requirements:

  • Google Drive account, preferably Business because it has unlimited storage.
  • Up to date Swizzin install.
  • Swizzin Mediabox server, although this should work on any Debian based OS.
  • Time.
  • Not scared to use the command-line interface.
  • Some Linux knowledge

Step 1: Prepare your Google account

We need to create some credentials for Rclone to use in a later step. And create a directory where we wanna store everything so we can use our Gdrive account for something else then seedbox storage.
Therefore we start by going to https://console.developers.google.com/, Accept the Terms of Service and click on create a project.

Then you will get the following page fill in a Project name and click on create:

After this, you will need to enable the Google Drive API for this project. You can do this by going to Enable APIs and Services:

Then search for Google Drive in the search field:

Select Google Drive API:

And click on the Enable button to enable the API for this project:

After this click on the Hamburger menu on the top left -> APIs & Services -> Credentials:

Then you get the choice for internal or external. Since we only have to authenticate with our own account. We choose internal.

After clicking on create your send to a screen that looks pretty overwhelming. Just fill in the Application Name and click on Submit. I've chosen Rclone as the name but this can really be anything.

 

After this its time to create an OAuth client ID for use in Rclone.
Click on the Hamburger menu on the top left -> APIs & Services -> Credentials then there is a + Create Credentials button when you click that you get a few options:

This will lead you to the following page, Select Desktop app and fill in a name. We chose Rclone but this can be any name then click on create:

You will then get a popup screen with credentials. Save these somewhere safe on your computer so we can use this later.

 

Step 2: Setup Rclone

SSH into your media server. 
Once in the server run the following command to install the latest Rclone:

sudo box install rclone && sudo apt install -y fuse

Now Rclone is installed. The next step will be to configure the google drive in Rclone as something called a remote. 
Type the following command into the terminal:

rclone config

And the following will appear in your command-line interface (CLI):

walker@s6880:~$ rclone config
2020/06/25 16:05:59 NOTICE: Config file "/home/walker/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q>n

Fill in n for New remote, fill in the name, be sure to use the name gdrive if you wish to use the service file provided later in the guide. Then you get asked about which storage medium you wanna use. Type in drive and press enter.
The following will pop up:

** See help for drive backend at: https://rclone.org/drive/ **

Google Application Client Id
Setting your own is recommended.
See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
If you leave this blank, it will use an internal key which is low performance.
Enter a string value. Press Enter for the default ("").
client_id> 

This is the client ID you created earlier. So paste that in.

Google Application Client Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default ("").
client_secret> 

Here you fill in the client secret we created earlier.

Scope that rclone should use when requesting access from drive.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / Full access all files, excluding Application Data Folder.
   \ "drive"
 2 / Read-only access to file metadata and file contents.
   \ "drive.readonly"
   / Access to files created by rclone only.
 3 | These are visible in the drive website.
   | File authorization is revoked when the user deauthorizes the app.
   \ "drive.file"
   / Allows read and write access to the Application Data folder.
 4 | This is not visible in the drive website.
   \ "drive.appfolder"
   / Allows read-only access to file metadata but
 5 | does not allow any access to read or download file content.
   \ "drive.metadata.readonly"
scope> 1

The scope should be 1, or Empty. Both are fine for our application.

ID of the root folder
Leave blank normally.

Fill in to access "Computers" folders (see docs), or for rclone to use
a non root folder as its starting point.

Note that if this is blank, the first time rclone runs it will fill it
in with the ID of the root folder.

Enter a string value. Press Enter for the default ("").
root_folder_id>
Service Account Credentials JSON file path
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default ("").
service_account_file>
Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> n

Root folder ID you can leave empty, and for advanced config, you select N for no.

Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes (default)
n) No
y/n> n
Please go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=56546345645645-gfdhrere4543534534fd.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=OS9ivgdagharetsagfgadsfsdf
Log in and authorize rclone for access
Enter verification code> 4/gatewat5235at4643dsh2432

Now we are going to actually link your google drive account. So select N for auto-config. Since we are not on the same system as Rclone. And open the link you receive. Log in with the Google Drive account you want to link and copy the ID. Then paste this ID in the Rclone config.

Configure this as a team drive?
y) Yes
n) No (default)
y/n> n
--------------------
[gdrive]
type = drive
client_id = your_client_id
client_secret = your_client_secret
scope = drive
root_folder_id = 
token = the token rclone generated from Google
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y

Now you get an overview of the settings you just filled in. Put in Y when it is all correct.

Finally, you can close the Rclone config menu with Q.

Step 3: Mount the drive

We will be mounting the drive under your home user, in a folder called gdrive. We will accomplish this by mounting using a systemd service file. 

Then we have to run a few commands to start the mount, the first line starts the mount. The second line makes sure the mount automatically starts at boot:

sudo systemctl start rclone@yourusername.service
sudo systemctl enable rclone@yourusername.service

We then verify that the mount is online by running sudo systemctl status rclone@username.service

● rclone@yourusername.service - rclone VFS
   Loaded: loaded (/etc/systemd/system/rclone@yourusername.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-09-09 19:00:02 CEST; 2 days ago
 Main PID: 912240 (rclone)
    Tasks: 26 (limit: 4915)
   Memory: 185.6M
   CGroup: /system.slice/system-gdrive-mount.slice/rclone@yourusername.service
           └─912240 /usr/bin/rclone mount --config=/home/$USER/.config/rclone/rclone.conf --user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36 --rc-

If you see no errors here the mount is activated! Now you can test this by uploading some files through the Google Drive web interface and then running:

ls -l ~/cloud

If everything went well you should see the files you uploaded appear in this folder.

Was this answer helpful? 48 Users Found This Useful (79 Votes)