步骤

  1. 下载安装

本文默认使用的Linux系统,但是操作其实都差不多,其他系统也可以借鉴。
运行以下命令,下载并安装Rclone

curl https://rclone.org/install.sh | sudo bash
  1. 配置Rclone

安装完成后输入:

rclone config
  • 输出如下:
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q>

输入n新建配置,名字随意,此处我输入的是:

name> ODrive

然后会要求选择挂载的网盘服务类型:

Option 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> 27

此处OneDrive序号为27,故输入27。

然后会要求输入OAuth client ID,包含client_idclient_secret,可前往我的另一篇文章《创建微软OneDrive API》了解获取方法:

Option client_id.
OAuth Client Id.
Leave blank normally.
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> 填入密钥

然后要选择OneDrive的地区,这里选择全球,即1。

Option region.
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) Yes
n) No (default)
y/n> 

注意此步需要登录,故选n:

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> n

回显如下:

Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
        rclone authorize "onedrive" "API参数" # 此处为之后需要执行的指令
Then paste the result.
Enter a string value. Press Enter for the default ("").
config_token> 

授权码需要在本地电脑获取,根据电脑系统版本在此Rclone downloads下载对应的Rclone。下载后解压并进入该目录,按住shift点击鼠标右键,选择在此处打开 Powershell 窗口。在弹出的窗口中黏贴上面程序给出的命令,格式大致如下:

.\rclone.exe authorize "onedrive" "API参数"

然后浏览器会自动打开,已登录微软账户会直接弹出请求征得的许可窗口,如果不是你所选的账户建议事先退出登录,然后按后面的操作进行;未登录时会弹出登录页面,登录后弹出请求征得的许可窗口。选择接受即可。然后网页会提示可以关闭,同时命令行中会输出授权码,复制后回到服务器进行黏贴。

但如果使用的是VSCode的终端,此步操作可直接选默认的Yes,然后会输出如下内容:

2022/03/19 00:08:19 NOTICE: Make sure your Redirect URL is set to "http://localhost:53682/" in your custom config.
2022/03/19 00:08:19 NOTICE: If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=为避免泄露已打码
2022/03/19 00:08:19 NOTICE: Log in and authorize rclone for access
2022/03/19 00:08:19 NOTICE: Waiting for code...

VSCode会自动对这个端口进行转发,然后按住CTRL点击第2行的链接自动打开,或者复制到本地电脑的浏览器打开,就会在本地电脑的浏览器弹出请求征得的许可窗口,之后的步骤同上。

完成后会输出以下内容:

2022/03/19 00:08:31 NOTICE: Got code

接着要选择OneDrive的类型,根据自己的具体情况进行选择,此处我用的是企业OneDrive,故选1

Option config_type.
Type of connection
Enter a string value. Press Enter for the default ("onedrive").
Choose a number from below, or type in an existing value.
1 / OneDrive Personal or Business
  \ "onedrive"
2 / Root Sharepoint site
  \ "sharepoint"
  / Sharepoint site name or URL
3 | 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"
  / Sharepoint server-relative path (advanced)
7 | E.g. /teams/hr
  \ "path"
config_type> config_type> 1

然后会根据你的输入查找对应账户,确认无误后按回车默认即可:

Drive OK?

Found drive "root" of type "business"
URL: https://呷脯呷脯.喵喵喵

y) Yes (default)
n) No
y/n> 

至此配置结束,会输出所有的网盘配置信息进行确认,确认无误后按回车默认同意,接着输入q退出。然后使用此命令检测是否配置成功,若成功会输出网盘根目录下的目录信息:

rclone lsd <配置的网盘名称>:/
  1. 挂载OneDrive网盘

全网中外文搜索结果大多只给出了简短的OneDrive挂载指令模板,另外我也并不打算挂载,所以照抄一个模板过来。不过需要配置挂载参数的可以参考我的另一篇博客《Linux使用Rclone挂载Google Drive网盘》,以及Rclone官网的相关文档。

rclone mount <配置的云盘名称>:<要挂载的云盘目录> <作为挂载点的本地目录> --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --daemon

如果无法挂载,请使用如下指令再试:

apt install fuse

挂载后使用以下命令测试,看到网盘目录即为成功:

df -h

如果需要取消挂载,使用如下命令:

fusermount -qzu <挂载路径>

引用


转载来源:linux使用rclone挂载onedrive网盘