Thursday , 22 October 2020
Stackode
Home > Linux > Archlinux > How To Mount Google Drive Locally As Virtual File System In Archlinux with rclone

How To Mount Google Drive Locally As Virtual File System In Archlinux with rclone

Rclone is command line tool to sync files and directories to and from local and remote cloud storage providers. It can also serve local or remote files over HTTP/WebDav/FTP/SFTP/dlna. Rclone is a free and open source application written using GO programming language.

It is not just for Google drive, Rclone will support a lot of other cloud storage providers as listed below.

1 / 1Fichier
  \ “fichier”
2 / Alias for an existing remote
  \ “alias”
3 / Amazon Drive
  \ “amazon cloud drive”
4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
  \ “s3”
5 / Backblaze B2
  \ “b2”
6 / Box
  \ “box”
7 / Cache a remote
  \ “cache”
8 / Citrix Sharefile
  \ “sharefile”
9 / Dropbox
  \ “dropbox”
10 / Encrypt/Decrypt a remote
  \ “crypt”
11 / FTP Connection
  \ “ftp”
12 / Google Cloud Storage (this is not Google Drive)
  \ “google cloud storage”
13 / Google Drive
  \ “drive”
14 / Google Photos
  \ “google photos”
15 / Hubic
  \ “hubic”
16 / In memory object storage system.
  \ “memory”
17 / Jottacloud
  \ “jottacloud”
18 / Koofr
  \ “koofr”
19 / Local Disk
  \ “local”
20 / Mail.ru Cloud
  \ “mailru”
21 / Mega
  \ “mega”
22 / Microsoft Azure Blob Storage
  \ “azureblob”
23 / Microsoft OneDrive
  \ “onedrive”
24 / OpenDrive
  \ “opendrive”
25 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
  \ “swift”
26 / Pcloud
  \ “pcloud”
27 / Put.io
  \ “putio”
28 / QingCloud Object Storage
  \ “qingstor”
29 / SSH/SFTP Connection
  \ “sftp”
30 / Sugarsync
  \ “sugarsync”
31 / Tardigrade Decentralized Cloud Storage
  \ “tardigrade”
32 / Transparently chunk/split large files
  \ “chunker”
33 / Union merges the contents of several upstream fs
  \ “union”
34 / Webdav
  \ “webdav”
35 / Yandex Disk
  \ “yandex”
36 / http Connection
  \ “http”
37 / premiumize.me
  \ “premiumizeme”
38 / seafile
  \ “seafile”

Install rclone

$ sudo pacman -S rclone

Configure Rclone to access Google drive

run the following command to give permission to Rclone to access your Google drive:

$ rclone config

This will guide you through a series of interactive setup process. First, it will search for list of available remotes. We don’t have created any remotes yet, so let us create one. To do so, simply type “n” and hit ENTER. Then type the name of the remote. I am going to name it as “GDrive”:

[[email protected] ~]$ rclone config
2020/09/03 13:18:50 NOTICE: Config file "/home/whendy/.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
name> GDrive  

Next choose the cloud provider. In our case. It is Google drive, so I entered number 13.

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
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Citrix Sharefile
   \ "sharefile"
 9 / Dropbox
   \ "dropbox"
10 / Encrypt/Decrypt a remote
   \ "crypt"
11 / FTP Connection
   \ "ftp"
12 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
13 / Google Drive
   \ "drive"
14 / Google Photos
   \ "google photos"
15 / Hubic
   \ "hubic"
16 / In memory object storage system.
   \ "memory"
17 / Jottacloud
   \ "jottacloud"
18 / Koofr
   \ "koofr"
19 / Local Disk
   \ "local"
20 / Mail.ru Cloud
   \ "mailru"
21 / Mega
   \ "mega"
22 / Microsoft Azure Blob Storage
   \ "azureblob"
23 / Microsoft OneDrive
   \ "onedrive"
24 / OpenDrive
   \ "opendrive"
25 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
26 / Pcloud
   \ "pcloud"
27 / Put.io
   \ "putio"
28 / QingCloud Object Storage
   \ "qingstor"
29 / SSH/SFTP Connection
   \ "sftp"
30 / Sugarsync
   \ "sugarsync"
31 / Tardigrade Decentralized Cloud Storage
   \ "tardigrade"
32 / Transparently chunk/split large files
   \ "chunker"
33 / Union merges the contents of several upstream fs
   \ "union"
34 / Webdav
   \ "webdav"
35 / Yandex Disk
   \ "yandex"
36 / http Connection
   \ "http"
37 / premiumize.me
   \ "premiumizeme"
38 / seafile
   \ "seafile"
Storage> 13

Next press ENTER to leave blank values for Google application client id and client secret:

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

OAuth Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> 
OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>

Next, rclone prompt should use when requesting access from google drive:

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

Next, ID of the root folder :

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> 

Next:

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> 

Next:

Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> 
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> 
If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=generateTokenFromRclonce
Log in and authorize rclone for access
Waiting for code...
Got code

Next, configuration team driver, just enter cause by default it is No:

Configure this as a team drive?
y) Yes
n) No (default)
y/n> 
--------------------
[GDrive]
type = drive
scope = drive
root_folder_id =
token = {
            "access_token":"your_token_access_from_gdrive","token_type":"Bearer",
            "refresh_token":"token_refresh_from_gdrive",
            "expiry":"2020-09-03T14:22:36.568303786+07:00"
         }
--------------------

Next, another question will appear stating whether you agree with the credentials:

y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> 

Then just follow the steps, I’m tired of choosing the right word:

Current remotes:

Name                 Type
====                 ====
GDrive               drive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> s
Your configuration is not encrypted.
If you add a password, you will protect your login information to cloud services.
a) Add Password
q) Quit to main menu
a/q> a
Enter NEW configuration password:
password:
Confirm NEW configuration password:
password:
Password set
Your configuration is encrypted.
c) Change Password
u) Unencrypt configuration
q) Quit to main menu
c/u/q> u
Your configuration is not encrypted.
If you add a password, you will protect your login information to cloud services.
a) Add Password
q) Quit to main menu
a/q> a
Enter NEW configuration password:
password:
Confirm NEW configuration password:
password:
Password set
Your configuration is encrypted.
c) Change Password
u) Unencrypt configuration
q) Quit to main menu
c/u/q> q
Current remotes:

Name                 Type
====                 ====
GDrive               drive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q

Ok, well done. Next we will mount Google Drive in our local

Mount Google Drive Locally As Virtual File System Using Rclone

First we create a folder, which is this folder that will be the destination for mounting Google Drive

$ mkdir /home/whendy/GDrive

Next, mounting Google Drive using this command:

$ rclone mount GDrive:/ /home/whendy/GDrive/

Enter your password

[[email protected] ~]$ rclone mount GDrive:/ /home/whendy/GDrive/
Enter configuration password:
password:

Good job, now Google Drive is mounted at your location.

Undesirable events :

[[email protected] ~]$ rclone mount GDrive:/ /home/whendy/GDrive/
Enter configuration password:
password:
2020/09/03 13:35:38 Fatal error: Can not open: /home/whendy/GDrive/: open /home/whendy/GDrive/: transport endpoint is not connected

To solve the above problem, you can try it by running the command below

$ fusermount -u /home/whendy/GDrive

To unmount, just press “CTRL+c” to stop the mount.

Open your file manager and you will see the drive folder in the left side. Click on it to access your Google drive.

Mount Google Drive Locally As Virtual File System Using Rclone
Mount Google Drive Locally As Virtual File System Using Rclone

And now on, you can create, copy, move, rename and delete files/folders as you do in your local file system. Anything you put in the local mount folder will be uploaded to your Google drive.

You can also list and copy files/directories from the command line like below.

To view all files in your Google drive, run:

$ rclone ls GDrive:/

Replace “GDrive” with your remote name

To list all directories in the top level, run:

$ rclone lsd GDrive:/

Try to copy a directory from your local system, say “/home/whendy/testing”, to your Google drive directory called “testing_copy_from_local”, use this command:

$ rclone copy /home/whendy/testing GDrive:testing_copy_from_local

Or try it using “cp”

$ cp /home/whendy/testing /home/whendy/GDrive/testing_copy_from_local

Note:
This is a mount folder “/home/whendy/GDrive/”

rclone has many other command line options, but this is not the scope of this guide.

For more details, refer to the Rclone website.

About Whendy

Whendy Blog mengumpulkan beberapa Tutorial Website, PHP, AngularJS, JQuery, Laravel, Codeigniter dan lain-lain. ( jika sempat ) :)

Leave a Reply

Your email address will not be published. Required fields are marked *