How To Mount Google Drive on Raspberry

This How To Mount Google Drive on Raspberry explains in simple steps how you can mount your google drive to Raspberry.

Index:

Background

This How To Mount Google Drive on Raspberry assumes that you have both, a properly running Raspberry that is on Debian Linux, as well as a Google account. If this is not the case, than you should setup first your Raspberry and secondly create a Google account.

There are various software in order to mount a Google Drive on Raspberry. In this How To Mount Google Drive on Raspberry we select:

  • rclone, because this seems to be actively maintained and provides the necessary functionality
  • All other software, on a typical Debian installation, should be there already. 

How To Mount Google Drive on Raspberry

Install rclone

First, we install rclone. To do so, we leverage on the below command that installs the pre-compiled Debian package:

sudo apt-get install rclone

Get A Google Drive Client ID

With your favourite browser you connect in the first step to the Google Developer Console. Once arrived, you like to login with your Google Account. Once logged in:

    • Select on top of the Google Developer Console “Project” -> “NEW PROJECT
    • Give the new project a name, e.g. -> “rclone raspi access
    • Once you created your project, you select on the left hand site “Enabled APIs and services
    • On top you will find a search filed. Type into the search field “Drive“. This will provide you with a result including something looking like this:
    • Select “Google Drive API
    • Click on “Enable
    • Once enabled, click on the left hand site “Credentials” 
    • You like to read the warning provided and search the internet if you have questions to it. Once you fine, you click on “CONFIGURE CONSET SCREEN
    • Select “External“, but before hitting “CREATE” you like to Learn more about user type if you not sure what this is about. If you clear with this, than you click on “CREATE
    • Google will kick off a 4 step process. Now drive thru this 4 step process:
      • Application Name: for example “rclone raspi access
      • User support email: YourPreferredEmailAddress@YourDomain.com
      • If you like, you add an App logo
      • All other fields are not mandatory and we leave it out in this How To
    • Next step in Scopes 
      • Click on “ADD OR REMOVE SCOPES
      • Flip thru the pages until you find “./auth/drive“. -> Select “./auth/drive
      • Click “SAVE AND CONTINUE
    • Next step in Test Users. Read carefully the instructions. In this how to we do not add anything, but simply click on “SAVE AND CONTINUE”
    • Google summaries the configuration and in this how to we hit “BACK TO DASHBOARD
    • In the Dashboard click on “Credentials“, and on top select “+ CREATE CREDENTIALS” -> “OAuth client ID
      • Application type: “Desktop” 
      • Name: “Your Favourite Name
      •  Hit “CREATE
      • You now will be provided with “Your Client ID” and “Your Client Secret“. Store this in a save place, e.g. KeePass or similar. Finally, click OK.

        How To Mount Google Drive on Raspberry

        How To Mount Google Drive on Raspberry – OAuth

Lets get to the next step now, which is to configure rclone. For this we will need the Client ID and the Client Secret. 

Configure rclone

Next step in this How To Mount Google Drive on Raspberry is to configure rclone with the specifics needed to connect the Google drive to your Raspberry. On your Raspi command line you type

 rclone config

Rclone will start a menu. The key points to be selected are marked purple in the below. Of course, depending on your needs, you can go for other options

rclone config
2022/06/06 13:46:59 NOTICE: Config file "/home/openhabian/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
<strong><span style="color: #ff00ff;">n) New remote</span></strong>
s) Set configuration password
q) Quit config
n/s/q&gt;<strong> <span style="color: #ff00ff;">n</span>
name&gt; <span style="color: #ff00ff;">GoogleDrive</span></strong>
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / 1Fichier
   \ "fichier"
 2 / Alias for an existing remote
&lt;......&gt;
12 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
<strong><span style="color: #ff00ff;">13 / Google Drive
   \ "drive"</span></strong>
14 / Google Photos
   \ "google photos"
&lt;.....&gt;
<span style="color: #ff00ff;"><strong>Storage&gt; 13</strong></span>
** 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 ("").
<strong><span style="color: #ff00ff;">client_id&gt; &lt;ENTER YOUR CLIENT ID&gt;</span></strong>
OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
<strong><span style="color: #ff00ff;">client_secret&gt; &lt;ENTER YOUR SECRET&gt;</span></strong>
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
<strong><span style="color: #ff00ff;"> 1 / Full access all files, excluding Application Data Folder.
   \ "drive"</span></strong>
 2 / Read-only access to file metadata and file contents.
   \ "drive.readonly"
 &lt;........&gt;
<strong>scope&gt; <span style="color: #ff00ff;">1</span></strong>
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.

Enter a string value. Press Enter for the default ("").
root_folder_id&gt; 
Service Account Credentials JSON file path 
Leave blank normally.
Needed only if you want use SA instead of interactive login.

Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`.

Enter a string value. Press Enter for the default ("").
service_account_file&gt; 
Edit advanced config? (y/n)
y) Yes
<strong><span style="color: #ff00ff;">n) No (default)</span></strong>
<strong>y/n&gt; <span style="color: #ff00ff;">n</span></strong>
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)
<span style="color: #ff00ff;"><strong>n) No</strong></span>
<strong>y/n&gt; <span style="color: #ff00ff;">n</span></strong>
Please go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&amp;client_id=X&amp;redirect_uri=XXXX
Log in and authorize rclone for access
Enter verification code&gt;<strong> <span style="color: #ff00ff;">&lt;ENTER YOUR VERIFICATION CODE&gt;</span></strong>
Configure this as a team drive?
y) Yes
<strong>n) No (default)
y/n&gt; <span style="color: #ff00ff;">n</span></strong>
--------------------
[GoogleDrive]
client_id = XXXXXXXXXX
client_secret = XXXXXXXXXX
scope = drive
token = {"access_token":"X}
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d&gt; <span style="color: #ff00ff;">y</span>
Current remotes:

Name                 Type
====                 ====
GoogleDrive          drive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
<span style="color: #ff00ff;"><strong>q) Quit config</strong></span>
<strong>e/n/d/r/c/s/q&gt; <span style="color: #ff00ff;">q
</span></strong>

 With this you are set now. Lets go to the next step.

Test the Configuration

Lets test now if the How To Mount Google Drive on Raspberry so far worked properly. To do so, lets send a simple command that should list everything stored in your Google Drive directory:

 rclone ls GoogleDrive:

Most likely you have no files because you in the above maybe only created a new drive. If you leverage on something existing, then you get a list of files on your google drive.

Now you check if you are able to mount GoogleDrive into your system:

cd ~
mkdir -p mnt/GoogleDrive
rclone mount GoogleDrive: $HOME/mnt/GoogleDrive

Once done, you should open a second terminal. Type in this seconded terminal:

ls -la $HOME/mnt/GoogleDrive

Again, the Raspberry terminal should show directories and files stored on the Google Drive.

Mount Google Drive at Startup

Next step in the How To Mount Google Drive on Raspberry is to mount Google Drive at Startup we create a Systemd configuration. This works as the following:

sudo vi /etc/systemd/system/rclone@GoogleDrive.service

Include into the below into your rclone@GoogleDrive.service file , BUT, exchange  values with the right one’s for fitting your configuration. Typically and if you followed the above, this should not be required and you can simply copy and paste. 

# service to mount Google Drive by rclone
# Place the file into /etc/systemd/user/ following how to guidance on https://www.myhowto.blog
# Once the file was placed, reload the systemctl deamon by typing systemctl --user daemon-reload
# To start the service type: systemctl --user start rclone@GoogleDrive
# To stop the service type:: systemctl --user stop rclone@GoogleDrive
# To restart the service type: systemctl --user restart rclone@GoogleDrive
# To check the service status type: systemctl --user status rclone@GoogleDrive 
[Unit]
Description=rclone: Remote FUSE filesystem for cloud storage config %i
Documentation=man:rclone(1)
[Service]
Type=notify
ExecStartPre=/bin/mkdir -p %h/mnt/%i
ExecStart= \
  /usr/bin/rclone mount \
    --fast-list \
    --vfs-cache-mode writes \
    --vfs-cache-max-size 100M \
    %i: %h/mnt/%i
[Install]
WantedBy=default.target

Next is to enable the new service. This can be done by the following commands:

systemctl --user enable rclone@GoogleDrive
systemctl --user daemon-reload
systemctl --user start rclone@GoogleDrive

To check whether everything is running well, type:

The output most likely will be something towards this:

systemctl --user status rclone@GoogleDrive
<span style="color: #00ff00;">● </span>rclone@GoogleDrive.service - rclone: Remote FUSE filesystem for cloud storage config GoogleDrive
     Loaded: loaded (/etc/xdg/systemd/user/rclone@GoogleDrive.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-06-06 18:01:50 CEST; 28s ago
       Docs: man:rclone(1)
    Process: 4958 ExecStartPre=/bin/mkdir -p /home/YourUserName/mnt/GoogleDrive (code=exited, status=0/SUCCESS)
   Main PID: 4959 (rclone)
      Tasks: 9 (limit: 4915)
        CPU: 713ms
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/app-rclone.slice/rclone@GoogleDrive.service
             └─4959 /usr/bin/rclone mount --fast-list --vfs-cache-mode writes --vfs-cache-max-size 100M GoogleDrive: /ho&gt;

Jun 06 18:01:49 OpenHAB systemd[721]: Starting rclone: Remote FUSE filesystem for cloud storage config GoogleDrive...
Jun 06 18:01:50 OpenHAB systemd[721]: Started rclone: Remote FUSE filesystem for cloud storage config GoogleDrive.

Test whether you can access your data on Google Drive. To do so, we leverage on ls and check whether your Raspberry can see what’s on your GoogleDrive:

ls -la $HOME/mnt/GoogleDrive

Finally and before we conclude the How To Mount Google Drive on Raspberry we reboot the system by leveraging on the below command and do the above checks again. Enjoy having GoogleDrive mapped to your Raspberry!

sudo reboot

Additional Information

Some background information to the How To Mount Google Drive on Raspberry.

Background information on rclone. Check out the official rclone website.

The google developer console can be found here: Google Developer Console

The Raspberry I used for this configuration is a Raspberry Pi 4+ 8GB.

 

This is it! I hope you enjoyed the How To Mount Google Drive on Raspberry. Please link this page to other websites, recommend it to others and share it with your friends! Thanks so much!