记录一下自己使用rclone挂载onedrive的过程,避免自己忘记了

  1. 下载安装

    使用脚本下载安装rclone:

curl https://rclone.org/install.sh | sudo bash
  1. 初始化配置

    安装完成后输入:

rclone config

可以看到

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

输入 n 新建配置
名字随便取一个
然后会出现挂载的服务类型,如下:

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

因为挂载的是onedrive,所以输入序号26
这里要注意的是并不是每个版本onedrive序号都是26,所以要认准了

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> 

这里也直接回车
然后会出现 OneDrive 区域选择,如下:

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

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

输入 n
然后就需要输入你的授权码了,如下:

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"

Then paste the result below:

获取授权码需要在本地电脑上获取,访问https://rclone.org/downloads/下载
一般情况下在红圈内选择红圈内的即可
rclone下载位置

下载完成后解压,进入存放 Rclone 的目录
首先 win+r 输入 cmd
cd进入rclone解压的位置,例如在 E:downloadrclone-v1.55.0-windows-amd64,依次输入如下:

E:
cd E:\download\rclone-v1.55.0-windows-amd64
rclone authorize "onedrive"

浏览器会自动打开,登录好自己的账号后会给你一串很长的授权信息,复制授权信息包括首尾的 {} ,到 Linux 终端粘贴。
然后选择onedrive类型,如下:

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 账户,如下:

Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=b!A8Vi464bNk2AasdasdddddasdasdasaAbzhsYuasdasdasdd68B2544jAlG
Chose drive to use:> 0

输入序号 0
这里会根据你输入的序号查找账户,如下:

Found drive 'root' of type 'business', URL: https://hkwithedu-my.sharepoint.com/personal/micly2_od_168826_xyz/Documents
Is that okay?
y) Yes (default)
n) No
y/n> y

确认无误后,输入 y

至此,rclone配置完成


使用rclone上传/下载文件到onedrive

上传

rclone copy /home/backup gdrive:backup  # 本地路径 配置名字:网盘文件夹路径

下载

rclone copy gdrive:backup /home/backup  # 配置名字:网盘文件夹路径 本地路径

将命令挂载到后台运行,前面加上 nohup ,后面加上 & ,如下:

nohup rclone copy /home/backup gdrive:backup &

将onedrive挂载为vps硬盘实现文件传输

挂载

/usr/bin/rclone mount DriveName:Folder LocalFolder \

下面整体代码中最上面的这条需要自己修改,不要直接复制,注意代码中有空格

DriveName       #配置时填写的name
Folder          #网盘里要挂载的文件夹名
LocalFolder     #本地要挂载的文件夹绝对路径

例:/usr/bin/rclone mount SUN:/我的文件 /home/OneDrive \

#下面代码是一个整体,全部复制后粘贴运行
/usr/bin/rclone mount DriveName:Folder LocalFolder \
 --umask 0000 \
 --default-permissions \
 --allow-non-empty \
 --allow-other \
 --transfers 1 \                #该参数是最大同时传输任务数量
 --buffer-size 64M \            #该参数为读取每个文件时的内存缓冲区大小,控制rclone上传和挂载的时候的内存占用
 --low-level-retries 200        #该参数为传输文件没速度的时候重试次数,没速度的时候,单个会自动睡眠10ms起,然后再重试

如果你还涉及到读取使用,比如使用H5ai等在线播放,就在后面多加上以下三条参数

--dir-cache-time 12h
--vfs-read-chunk-size 32M
--vfs-read-chunk-size-limit 1G

输入 df -h 查看磁盘空间

本文章参考https://sunpma.com/659.htmlhttps://www.misterma.com/archives/900/