Allen_Jeo

Allen_Jeo

在Ubuntu上使用rclone挂载OneDrive网盘

VPS 的空间太小怎么办,不如用 rclone 挂载 od 盘到本地,岂不妙哉?#


一、获取 token(本地进行)#

1)win10 方法#

1. 点击此处下载获取 token 工具
2. 解压,并进入rclone.exe所在的目录
3.Shift + 右键点击在此处打开 powershell
![Snipaste_2021-08-20_21-04-44.png][1]
[1]: https://z-r.cc/usr/uploads/2021/08/3425953120.png
4. 输入

./rclone.exe authorize "onedrive"

然后按提示操作
5. 复制返回的
从 {"access_token":
复制到
"expiry":"your time"}
并保存到记事本备用
2)win7 方法
1. 点击此处下载获取 token 工具
2. 解压,并进入rclone.exe所在的目录
3. 将 rclone.exe 复制到 C:\Windows\System32
4. 输入

rclone authorize "onedrive"
```shell
然后按提示操作
5.复制返回的
{"access_token":
复制到
"expiry":"your time"}
并保存到记事本备用

***
##二、安装(VPS上进行)
1.安装rclone
```shell
wget https://z-r.cc/rclone_ubuntu.sh && bash rclone_ubuntu.sh

2. 配置初始化

rclone config

然后会出现一下信息

n) New remote
s) Set configuration password
q) Quit config
n/s/q> 

输入:n
然后会出现

name>

此处随便输,这里以 yourname来代称
然后

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>

这里找到 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>

这里以自己实际为准

Edit advanced config? (y/n)
y) Yes
n) No (default)
y/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

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:
result>

这里把之前获取的 token 粘贴上去

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>

按自己情况选择

Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=****
Chose drive to use:> 0
Found drive 'root' of type 'business', URL: ****
Is that okay?
y) Yes (default)
n) No
y/n>

输入:y

[onedrive]
type = onedrive
region = global
token = {"access_token":"***:"2021-05-12T21:26:23.034940078-04:00"}
drive_id = b!HZQ8fVjEAkirFu8ARagwdQSJ8f6tKihCnEfvBcs_KuyXtvHlOzf1SJDUs8WRpgXq
drive_type = business
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d>

输入:y

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 退出


## 三、挂载为磁盘

mkdir /root/OneDrive  #新建本地文件夹,路径自己定,即下面的LocalFolder
rclone mount yourname:/ LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode writes #yourname为初始化配置填的name,/为OneDrive里根目录,可以为其他值,LocalFolder为VPS上的本地文件夹。

如果出现下面报错

NOTICE: One drive root 'test': poll-interval is not supported by this remote

请忽略
挂载成功后,直接断开连接。重新连接后,输入 df -h 命令查看即可


## 四、卸载磁盘(如果需要)

fusermount -qzu LocalFolder

五、设置开机自启#

1. 新建 rclone.service 文件:

command="mount yourname:/ LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode writes"

2. 写入

#以下是一整条命令,一起复制到SSH客户端运行
cat > /etc/systemd/system/rclone.service <<EOF
[Unit]
Description=Rclone
After=network-online.target

[Service]
Type=simple
ExecStart=$(command -v rclone) ${command}
Restart=on-abort
User=root

[Install]
WantedBy=default.target
EOF

注意:ExecStart 为之前第三步时输入的命令
3. 重载 daemon,让新的服务文件生效:

 systemctl daemon-reload

4. 启动:

systemctl start rclone
systemctl enable rclone

5. 其他命令:

重启:systemctl restart rclone 
停止:systemctl stop rclone 
状态:systemctl status rclone

本文链接:https://z-r.cc/2021/08/20/%E5%9C%A8Ubuntu%E4%B8%8A%E4%BD%BF%E7%94%A8rclone%E6%8C%82%E8%BD%BDOneDrive%E7%BD%91%E7%9B%98.html
转载请注明出处!

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。