Rat's

在Debian/Ubuntu上使用rclone挂载OneDrive网盘
说明:之前发了个Google Drive网盘挂载教程,参考:在Debian/Ubuntu上使用rclone挂载Go...
扫描右侧二维码阅读全文
23
2018/01

在Debian/Ubuntu上使用rclone挂载OneDrive网盘

说明:之前发了个Google Drive网盘挂载教程,参考:在Debian/Ubuntu上使用rclone挂载Google Drive网盘,然后博主想用同样的方法试试挂载OneDrive网盘,可是卡在了授权那里,然后只有请求Vicer大佬帮忙解决了,这里分享下挂载教程。

提示:本教程挂载OneDrive for Business和个人版的方法都一样,这里以个人版为参考。

说明

本教程只适用Debian/Ubuntu系统,如果你是CentOS或者其它Linux系统,请使用以下命令安装rclone

curl https://rclone.org/install.sh | sudo bash

客户端授权、初始化配置和挂载方法和下面一样,开机自启可参考该教程→传送门

客户端授权

在本地Windows电脑上下载rclone,下载地址:https://rclone.org/downloads/。然后解压出来,比如我解压到D盘,文件夹命名rclone,此时点击Win+R,然后输入cmd,确定。再输入以下命令:

cd /d d:\rclone
rclone authorize "onedrive"

会出现以下信息:

C:\Users\Administrator>cd /d d:\rclone

d:\rclone>rclone authorize "onedrive"
2018/01/23 20:28:56 NOTICE: Config file "C:\\Users\\Administrator\\.config\\rclo
ne\\rclone.conf" not found - using defaults
Choose OneDrive account type?
 * Say b for a OneDrive business account
 * Say p for a personal OneDrive account
b) Business
p) Personal
b/p> p  #这里选择个人版,你想挂载Business就选择b
If your browser doesn't open automatically go to the following link: http://127.
0.0.1:53682/auth  #接下来会弹出浏览器,要求你登录账号进行授权
Log in and authorize rclone for access
Waiting for code...
Got code
Paste the following into your remote machine --->
{"access_token":"xxxx"}  #请复制{xx}整个内容,后面需要用到
<---End paste

安装rclone

本教程只适用Debian/Ubuntu系统,如果你是CentOS,请参考:https://rclone.org/install/,安装rclone。挂载方法和下面差不多。

1、安装rclone

wget https://www.moerats.com/usr/shell/rclone_debian.sh && bash rclone_debian.sh

2、初始化配置

rclone config

会出现以下信息:

n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> Rats  #随便填,后面要用到
Type of storage to configure.
Choose a number from below, or type in your own value
 1 / Amazon Drive
   \ "amazon cloud drive"
 2 / Amazon S3 (also Dreamhost, Ceph, Minio)
   \ "s3"
 3 / Backblaze B2
   \ "b2"
 4 / Box
   \ "box"
 5 / Cache a remote
   \ "cache"
 6 / Dropbox
   \ "dropbox"
 7 / Encrypt/Decrypt a remote
   \ "crypt"
 8 / FTP Connection
   \ "ftp"
 9 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
10 / Google Drive
   \ "drive"
11 / Hubic
   \ "hubic"
12 / Local Disk
   \ "local"
13 / Microsoft Azure Blob Storage
   \ "azureblob"
14 / Microsoft OneDrive
   \ "onedrive"
15 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
16 / Pcloud
   \ "pcloud"
17 / QingCloud Object Storage
   \ "qingstor"
18 / SSH/SFTP Connection
   \ "sftp"
19 / Webdav
   \ "webdav"
20 / Yandex Disk
   \ "yandex"
21 / http Connection
   \ "http"
Storage> 14  #选择14,Microsoft OneDrive,,注意该序列号会随时变化,看清楚再填
Microsoft App Client Id - leave blank normally.
client_id>  #留空 
Microsoft App Client Secret - leave blank normally.
client_secret>  #留空 
Remote config
Choose OneDrive account type?
 * Say b for a OneDrive business account
 * Say p for a personal OneDrive account
b) Business
p) Personal
b/p> p  #这里选择个人版,你想挂载Business就选择b
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> n  #选择n
For this to work, you will need rclone available on a machine that has a web browser available.
Execute the following on your machine:
    rclone authorize "onedrive"
Then paste the result below:
result> {"access_token":""}  #输入之前在客户端授权的内容
--------------------
[Rats]
client_id = 
client_secret = 
token = {"access_token":""}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y  选择y
Current remotes:

Name                 Type
====                 ====
Rats                 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  #选择q退出

挂载

1、挂载为磁盘

#新建本地文件夹,路径自己定,即下面的LocalFolder
mkdir /root/OneDrive
#挂载为磁盘,下面的DriveName、Folder、LocalFolder参数根据说明自行替换
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

DriveName为初始化配置填的nameFolderOneDrive里的文件夹,LocalFolderVPS上的本地文件夹。

如果挂载过程中出现NOTICE: One drive root 'test': poll-interval is not supported by this remote错误,可以无视该错误。

挂载成功后,输入df -h命令查看即可!
请输入图片描述

2、卸载磁盘

fusermount -qzu LocalFolder

开机自启

先新建systemd配置文件,适用CentOS 7Debian 8+Ubuntu 16+

再使用命令:

#将后面修改成你上面手动运行命令中,除了rclone的全部参数
command="mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000"
#以下是一整条命令,一起复制到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

开始启动:

systemctl start rclone

设置开机自启:

systemctl enable rclone

其他命令:

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

如果你想挂载多个网盘,那么将systemd配置文件的rclone.service改成rclone1.service即可,重启动什么的同样换成rclone1

Vultr新用户注册送100美元/16个机房按小时计费,支持支付宝,【点击查看】。
最后修改:2020 年 04 月 29 日 01 : 00 PM

发表评论

345 条评论

  1. 西瓜

    一直是这个错误,是DNS解析不了吗
    root@aml:~# rclone mount onedrive:/ /root/onedrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
    2020/03/13 19:28:31 Failed to create file system for "onedrive:/": failed to get root: Get https://graph.microsoft.com/v1.0/drives/xxxxxxxxxxxxxxxxbNfR6tEHKBjmNOxMtrA9QnnnzRDbJb9HEpx2RrBeU8HpUnmI/root: dial tcp: lookup graph.microsoft.com on [::1]:53: read udp [1]:53: read: connection refused

    1. Rat's
      @西瓜

      试试其他目录看看,比如/opt

  2. 自作自受

    04:52:42 Failed to query root for drive b!h2y-9SkBDE2C2B1vQI_TGTqnKXc7R71IjRXNh9EZhggalYNisamjTKd6rJNMF1do: HTTP error 429 (429 ) returned body: "{rn "error": {rn "code": "activityLimitReached",rn "message": "The request has been throttled",rn "innerError": {rn "request-id": "8cd55c1f-cc0e-404a-8910-bc7f5ee38316",rn "date": "2020-03-11T08:52:42"rn }rn }rn}"

    一直卡在这了 咋办啊

    1. Rat's
      @自作自受

      提示好像是被限制还是啥的

      1. 自作自受
        @Rat's 挂载为磁盘,下面的DriveName、Folder、LocalFolder参数根据说明自行替换

        rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

        上面那个问题解决拉 但是我输入这个指令的时候,vps就一直没有反应了,那个文件夹名字都改好了

        1. Rat's
          @自作自受

          正常,你重新开一个ssh窗口df -h查看就挂上了,你设置个开机自启就好了

          1. 自作自受
            @Rat's

            但是好像没有挂载上 没有磁盘

  3. Butanediol 丁二

    这个挂载的过程,是将整个 OneDrive 同步下来了,还是只是创建了一个链接呢?

    1. Rat's
      @Butanediol 丁二

      就当中转,你把挂载盘文件取出来的时候,服务器会去下载

      1. Butanediol 丁二
        @Rat's

        也就是说如果服务器的空间小于获取的文件,是会出错的对吗?

        1. Rat's
          @Butanediol 丁二

          理论上是这样的

  4. 闪闪惠子

    你好!我在运行rclone config的时候,选择完网盘类型是OneDrive之后,就是输用户名、密码,然后就结束了!没有输token之类的提示,直接就这么结束了!之前复制的那一大堆用不上!我在网上搜索,都没说这是怎么回事。望告知。

    1. 闪闪惠子
      @闪闪惠子

      额,解决了。我眼瞎,把第24的OpenDrive看成第23的OneDrive了

  5. Mentire

    Active: failed (Result: exit-code) since Mon 2020-02-10 15:15:27 CST; 5s ago
    Process: 19306 ExecStart=/usr/bin/rclone mount vps:vps OD1 --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 (code=exited, status=1/FAILURE)
    Main PID: 19306 (code=exited, status=1/FAILURE)

    Feb 10 15:15:25 TGBigMentire systemd[1]: Started Rclone.
    Feb 10 15:15:27 TGBigMentire rclone[19306]: 2020/02/10 15:15:27 Fatal error: failed to mount FUSE fs: mountpoint does not exist: /OD1
    Feb 10 15:15:27 TGBigMentire systemd[1]: rclone.service: Main process exited, code=exited, status=1/FAILURE
    Feb 10 15:15:27 TGBigMentire systemd[1]: rclone.service: Failed with result 'exit-code'.

    请问设置服务的时候失败了是什么原因呢

    1. Rat's
      @Mentire

      好像是网盘的OD1文件夹不存在?

      1. Mentire
        @Rat's

        本地的OD1文件夹,用不用改成root/OD1 ?

        1. Rat's
          @Mentire

          那你参数填的不对,后面的是网盘的文件夹,你搞反了

  6. TORYS

    挂载为磁盘时出现错误:2020/02/06 01:34:34 Failed to create file system for "DriveName:Folder": didn't find section in config file
    请问如何解决?

    1. Rat's
      @TORYS

      别直接照搬DriveName:Folder这个参数,你改下,具体看文章说明

  7. aue

    最后一步提示404了。。Your choice> 1
    Found 1 drives, please select the one you want to use:

    0: OneDrive (business) id=b!

    2020/01/18 18:00:15 Failed to query root for drive b!xxxx: HTTP error 404 (404 Not Found) returned body: "{rn "error": {rn "code": "UnknownError",rn "message": "404 FILE NOT FOUND",rn "innerError": {rn "request-id": "1fxxxxxd",rn "date": "2020-01-18T10:00:15"rn }rn }rn}"

  8. 维他柠檬茶

    世纪互联能绑定吗?

    1. Moment
      1. wei
        @Moment

        如何绑定,求教,或者给个教程链接,先谢过

    2. Rat's
      @维他柠檬茶

      不清楚,应该不能,你可以试试

  9. 毒药

    脚本里wget rclone的时候要加上nocheck不然会报错了

    1. Rat's
      @毒药

      好像mini这种精简系统会出现,我加一下。

  10. 在座的各位都是弟弟

    我onedrive死活挂载不上,好像driveid中有个!号

    1. Rat's