前言

Rclone 是一款支持多网盘协议的云盘同步命令行工具,支持网盘的上传,下载,相互传输等多种功能.还支持 Windows Linux 挂载到本地磁盘.本文将简单介绍在 Linux 下安装和配置 Rclone ,并实践挂载 OneDrive 和 S3 存储协议.

本文是在ArchLinux上挂载OneDrive的一个例子。

安装Rclone

sudo pacman -S rclone

配置Rclone

在终端中依次输入以下命令行,请根据我下的步骤进操作。

$ rclone config                 // 第一步在终端输入 rclone config                       
2021/04/11 22:13:34 NOTICE: Config file "/home/liyp/.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						//第二步输入n创建新的配置
name> OneDrive					//第三步 输入一个英文名称 ,中间也不要有空格
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, and Tencent COS
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Citrix Sharefile
   \ "sharefile"
 9 / Compress a remote
   \ "compress"
10 / Dropbox
   \ "dropbox"
11 / Encrypt/Decrypt a remote
   \ "crypt"
12 / Enterprise File Fabric
   \ "filefabric"
13 / FTP Connection
   \ "ftp"
14 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
15 / Google Drive
   \ "drive"
16 / Google Photos
   \ "google photos"
17 / Hadoop distributed file system
   \ "hdfs"
18 / Hubic
   \ "hubic"
19 / In memory object storage system.
   \ "memory"
20 / Jottacloud
   \ "jottacloud"
21 / Koofr
   \ "koofr"
22 / Local Disk
   \ "local"
23 / Mail.ru Cloud
   \ "mailru"
24 / Mega
   \ "mega"
25 / Microsoft Azure Blob Storage
   \ "azureblob"
26 / Microsoft OneDrive
   \ "onedrive"
27 / OpenDrive
   \ "opendrive"
28 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
29 / Pcloud
   \ "pcloud"
30 / Put.io
   \ "putio"
31 / QingCloud Object Storage
   \ "qingstor"
32 / SSH/SFTP Connection
   \ "sftp"
33 / Sugarsync
   \ "sugarsync"
34 / Tardigrade Decentralized Cloud Storage
   \ "tardigrade"
35 / Transparently chunk/split large files
   \ "chunker"
36 / Union merges the contents of several upstream fs
   \ "union"
37 / Webdav
   \ "webdav"
38 / Yandex Disk
   \ "yandex"
39 / Zoho
   \ "zoho"
40 / http Connection
   \ "http"
41 / premiumize.me
   \ "premiumizeme"
42 / seafile
   \ "seafile"
Storage> 26		//第四步 输入要配置的网盘类型 因为我们要配置Microsoft OneDrive 因此输入26
** See help for onedrive backend at: https://rclone.org/onedrive/ **

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> 			   //第六步 直接回车       
Choose national cloud region for OneDrive.
Enter a string value. Press Enter for the default ("global").
Choose a number from below, or type in your own value
 1 / Microsoft Cloud Global
   \ "global"
 2 / Microsoft Cloud for US Government
   \ "us"
 3 / Microsoft Cloud Germany
   \ "de"
 4 / Azure and Office 365 operated by 21Vianet in China
   \ "cn"
region> 1					//第七步 设置帐号类型
Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> n						//第八步 输入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> y					 //第九步 输入y 使用自动配置授权
If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=2f6IGDMT3O7AnSvKYilWrQ
Log in and authorize rclone for access
Waiting for code...
Got code
Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Sharepoint site name or URL (e.g. mysite or https://contoso.sharepoint.com/sites/mysite)
   \ "url"
 4 / Search for a Sharepoint site
   \ "search"
 5 / Type in driveID (advanced)
   \ "driveid"
 6 / Type in SiteID (advanced)
   \ "siteid"
 7 / Sharepoint server-relative path (advanced, e.g. /teams/hr)
   \ "path"
Your choice> 1		 //第十步 输入1 因为现在我配置的是OneDrive Personal or Business 类型的网盘
Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=b!ylrmAa4F8061b3XptjtPVbEkmHZ-1d9OnvK88tHEeCqbU4zDALcRSKmzxwyvI10E
Chose drive to use:> 0
Found drive 'root' of type 'business', URL: https://zoutao-my.sharepoint.com/personal/oe001_microco_net/Documents
Is that okay?
y) Yes (default)
n) No
y/n> y		 //第十一步 输入y
--------------------
[OneDrive]
type = onedrive
region = global
token = {"access_token":"eyJ0eXAiOiV7fk","expiry":"2021-04-11T23:17:24.214971421+08:00"}
drive_id = b!ylrmAa4F8061b3LcRSKmzxwyvI10E
drive_type = business
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y			 //第十二步 输入y
Current remotes:

Name                 Type
====                 ====
OneDrive             onedrive

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		 //第十三步 输入y

挂载

rclone mount <网盘名称>:<网盘路径> <本地路径> <参数> --daemon
# 挂载命令
fusermount -qzu <本地路径>
# 卸载挂载

可以使用如下例子:

mkdir ./OneDrive
# 创建本地挂载目录
rclone mount OneDrive: ./OneDrive --copy-links --allow-other --allow-non-empty --umask 000 --daemon
# 挂载命令

Q.E.D.


于浩歌狂热之际中寒;于天上看见深渊。于一切眼中看见无所有;于无所希望中得救。