Linux: Mount Google Drive Cloud Drive with Rclone
I believe I am not the only one. To save money, many people pick the basic server configuration when choosing a server, leaving only a pitiful few tens of GB of storage, or even just 10 GB. But sometimes you really do need a larger storage space. At such times, cloud drives that provide APIs — OneDrive, Google Drive and the like — can be mounted onto the server and used as local storage, which to some extent helps relieve our storage anxiety.
Steps
1. Download and Install
A Linux system is assumed in this article, but the operations are basically the same everywhere, and other systems can follow along too.
Run the following command to download and install Rclone:
| |
2. Configure Rclone
After installation, run:
1rclone configThe output is as follows:
1 2 3 4 5No remotes found - make a new one n) New remote s) Set configuration password q) Quit config n/s/q>Type
nto create a new config. The name is up to you; here I entered:1name> GDriveNext it asks you to choose the type of cloud drive service to mount:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95Option Storage. 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 Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, SeaweedFS, and Tencent COS \ "s3" 5 / Backblaze B2 \ "b2" 6 / Better checksums for other remotes \ "hasher" 7 / Box \ "box" 8 / Cache a remote \ "cache" 9 / Citrix Sharefile \ "sharefile" 10 / Compress a remote \ "compress" 11 / Dropbox \ "dropbox" 12 / Encrypt/Decrypt a remote \ "crypt" 13 / Enterprise File Fabric \ "filefabric" 14 / FTP Connection \ "ftp" 15 / Google Cloud Storage (this is not Google Drive) \ "google cloud storage" 16 / Google Drive \ "drive" 17 / Google Photos \ "google photos" 18 / Hadoop distributed file system \ "hdfs" 19 / Hubic \ "hubic" 20 / In memory object storage system. \ "memory" 21 / Jottacloud \ "jottacloud" 22 / Koofr \ "koofr" 23 / Local Disk \ "local" 24 / Mail.ru Cloud \ "mailru" 25 / Mega \ "mega" 26 / Microsoft Azure Blob Storage \ "azureblob" 27 / Microsoft OneDrive \ "onedrive" 28 / OpenDrive \ "opendrive" 29 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH) \ "swift" 30 / Pcloud \ "pcloud" 31 / Put.io \ "putio" 32 / QingCloud Object Storage \ "qingstor" 33 / SSH/SFTP Connection \ "sftp" 34 / Sia Decentralized Cloud \ "sia" 35 / Sugarsync \ "sugarsync" 36 / Tardigrade Decentralized Cloud Storage \ "tardigrade" 37 / Transparently chunk/split large files \ "chunker" 38 / Union merges the contents of several upstream fs \ "union" 39 / Uptobox \ "uptobox" 40 / Webdav \ "webdav" 41 / Yandex Disk \ "yandex" 42 / Zoho \ "zoho" 43 / http Connection \ "http" 44 / premiumize.me \ "premiumizeme" 45 / seafile \ "seafile" Storage> 16Here Google Drive is number
16, so type16.Next it will ask you to enter the
OAuth client ID, which consists ofclient_idandclient_secret. You can refer to my other article Creating a Google OAuth Client ID to learn how to obtain them:1 2 3 4 5 6 7 8 9 10 11 12Option client_id. 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> 填入ID Option client_secret. OAuth Client Secret. Leave blank normally. Enter a string value. Press Enter for the default (""). client_secret> 填入密钥Next, choose the access scope of Rclone’s operations on the Google Drive files:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19Option scope. 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> 1Choose Full access to all files, excluding the Application Data Folder, i.e.
1.Most of the following options can keep the defaults; refer to the content below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18Option root_folder_id. 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> Option service_account_file. 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> Edit advanced config? y) Yes n) No (default) y/n>Note that this step requires logging in, so choose
n:1 2 3 4 5 6 7Use 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> nCopy the link to a browser and log in; after logging in it will give a
config_verification_code, then paste it:1 2 3 4 5 6Option config_verification_code. Verification code Go to this URL, authenticate then paste the code here. 此处为链接,复制后到浏览器完成登录步骤,会给一个“config_verification_code”。 Enter a string value. Press Enter for the default (""). config_verification_code> 在此填入“config_verification_code”。Choose a shared drive (team drive) or a personal drive; here I used a shared drive, so I chose
y:1 2 3 4 5Configure this as a Shared Drive (Team Drive)? y) Yes n) No (default) y/n> yAt this point the configuration is finished. All the cloud drive config information will be output for confirmation; after confirming it is correct, press Enter to accept the default, then type
qto quit. Then use this command to check whether the configuration succeeded; if successful, it will list the directories under the root of the cloud drive:1rclone lsd <配置的网盘名称>:/
3. Mount the Google Drive Cloud Drive
Depending on your needs, you can modify the parameters yourself according to the table below. For other configuration parameters, refer to the official Rclone website:
| Parameter | Description |
|---|---|
| –allow-other | Allow users other than the current rclone user to access |
| –attr-timeout 5m | The duration of the file attribute cache (size, modification time, etc.). If the VPS |
| –vfs-cache-mode full | Enable the VFS file cache, which reduces the interactions between rclone and the API and also improves file read/write efficiency |
| –vfs-cache-max-age 24h | The VFS file cache duration; set to 24 hours here. If files rarely change, a longer duration is recommended |
| –vfs-cache-max-size 10G | The upper limit of the VFS file cache size; adjust it according to the remaining disk space of the server |
| –vfs-read-chunk-size-limit 100M | The chunk read size; 100M is set here to improve file read efficiency. For example, a 1 GB file is roughly read in 10 chunks, but this also increases the number of API requests |
| –buffer-size 32M | The memory buffer size when reading each file; it controls the memory usage of rclone while uploading and mounting. Lowering it can prevent crashes caused by excessive memory usage, but setting it too low may affect the transfer speed of some files; set it according to the server’s memory size |
| –low-level-retries | The number of retries when a file transfer has no speed. When there is no speed, it starts by sleeping 10ms before each retry; if it still fails, it sleeps for a longer period and retries again, which can slightly speed up file uploads |
| –transfers | Controls the maximum number of concurrent transfer tasks. If your CPU performance is poor, lower it; but too low a value may affect the speed of transferring multiple files simultaneously |
| –daemon | Run the program in the background |
Here is a template:
| |
If it fails to mount, try the following command:
| |
After mounting, test with the following command; if the cloud drive directory appears, it succeeded:
| |
To unmount, use the following command:
| |