This How To Mount Google Drive on Raspberry explains in simple steps how you can mount your google drive to Raspberry.
(Updated 25.03.2023)
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.
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. Select the following options:
- New Remote (n), say “n” and give it the name “GoogleDrive“
- Select “18” (drive) for Google Drive “drive“
- For “client_id”: <ENTER YOUR CLIENT ID>
- For “client_secret”: <ENTER YOUR SECRET>
- Scope: Select “1” for Full Access
- root_folder_id> ID of root folder: Leave it blank
- Edit advanced config? (y/n) –> say “n” for no
- Remote config? -> say “n” for no
Now you will be requested to click a link that looks like the below and to “Enter Your verification code” from this link.
Please go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=X&redirect_uri=XXXX
- Configure this as a team drive -> Say “n” for No
- Following this, store the created drive as default by “y” for yes and press “q” for Quit config.
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> 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.
To mount google drive with a Service Account, follow this How To that was written for OpenHABian but that should work on any Debian and probably on many other Linux distributions.
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!