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. 嘟嘟

    iK5Ezrkw2WxtZYbxlLt7kDXVyEX0nk7SNKn1kJVVZZio6vJvIxB1mPTo7mOUQauwAdb9sKGaPmzZOZpa pY4d0BTjvdlT1YCsQ4rhnqtqsIdzVhNbM0YZVFsapGL2KyEJGloE9usUnL0SVFfuVqvxFLFDUnZSU1ps pB6P6j6c0YXgMQ2kkcaVTwqPYQAQTydrRyBfgDOBDo_EcHTynnc8nGFX10IA0w2GgsvVvveO10kSbsv7 zMqjVj0-HYUejxYJ5QNxMw_Hap_CoTJXdLsPBCx7A23mgRpPTFDePm51QAbQtICdaV3_aCEFVvsZ4NBH P6rbTFd1JCXj8x7MP7fFgAho_hU6hCnKk-pK-hQOyKxuA3-cWGLn4vIpanKps9pVb6qvhItQvta26k29 vtwRnxRm5Xo1wukGrhvnTP69RMlsGpUYXHp04y-_lpCYw88oYMls_fUod3Jiv0mCiB5MlllifXpcjcVi BrS-v7T5pdKeBhAWclZOWvhg9v5O7Vmn5Q-ZAWq1cxIpUOHtTVUGrIcNvbclo7zJmSEJxuTvasDiKQ-F 4G6FZbwcCWaKXGWCwTBRx2AO8MDCGcbLNy7OQnXyXEApzxP3_tFB7-sCteEdUf7GR_WqnyZL6t5aGeKW 01VemzqiNot7HmFZ0tGx0e-qVkBXuTHiXDjHLC_5Ca9BhrSSBIAA","expiry":"2018-11-10T11:38 :43.922932+08:00"}
    Choose a number from below, or type in an existing value
    1 / OneDrive Personal or Business
    "onedrive"
    2 / Root Sharepoint site
    "sharepoint"
    3 / Type in driveID
    "driveid"
    4 / Type in SiteID
    "siteid"
    5 / Search a Sharepoint site
    "search"
    Your choice> 1
    2018/11/10 02:48:26 Failed to query available drives: HTTP error 401 (401 Unauth orized) returned body: "{rn "error": {rn "code": "InvalidAuthentica tionToken",rn "message": "Access token validation failure.",rn " innerError": {rn "request-id": "5faa9199-99eb-4334-ae13-898c38c9115c ",rn "date": "2018-11-10T02:48:26"rn }rn }rn}"
    我在电脑端配置的时候,是先让选择onedrive的版本,但是在服务器端先让我输入result,之后> Choose a number from below, or type in an existing value
    选择1,总是出错,这是什么原因?

    1. Rat's
      @嘟嘟

      貌似说你的access_token不对导致验证失败,你获取到了access_token填入的时候检查下了没,还不要有空格?

      1. 嘟嘟
        @Rat's

        应该是对的,网上有这样说的,我还复制进notepa++里,用替换空格,但是没显示有空格,试了好多遍了,崩溃

        1. 嘟嘟
          @嘟嘟

          大神,能远程帮我看一下吗,想知道什么原因

          1. Rat's
            @嘟嘟

            这个你先折腾下,实在不行就帮你。

            1. 嘟嘟
              @Rat's

              牛逼闪闪的Rat‘s,我把onedrive账号密码,和服务器的怎么给你

  2. jyeric

    最后挂载的内容要nohup吧

    1. Rat's
      @jyeric

      不要

  3. ronson

    输入完授权信息后提示
    2018/10/31 18:34:49 NOTICE: Time may be set wrong - time from "graph.microsoft.com" is 30m57.810754558s different from this computer
    2018/10/31 18:34:49 Failed to query available drives: HTTP error 401 (401 Unauthorized) returned body: "{rn "error": {rn "code": "InvalidAuthenticationToken",rn "message": "Access token validation failure.",rn "innerError": {rn "request-id": "051bd55b-1790-4e0b-831a-d76b3a715e42",rn "date": "2018-10-31T10:03:53"rn }rn }rn}"

    求解

    1. Rat's
      @ronson

      说你的时间不同步,你同步下时间。

      1. ronson
        @Rat's

        那意思是要同步和我这边本地获取授权电脑的时间,还是机器本地的时间啊?

        1. Rat's
          @ronson

          具体我也不是很清楚,没遇见过,你可以都同步下,毕竟很简单。

  4. 风萧萧兮易水寒

    不知道为什么,我装了rcloned,并且确定了基本可以正常使用,但是还是有小问题,如可能是我的vps性能不行超过500M左右的文件就无法保存到指定的local文件夹导致就无法上传,而且我之后又去安装了oneindex后,rcloned就无法再连接上OneDrive了,感觉是不是它俩抢API权限什么的。提示401报错

    1. Rat's
      @风萧萧兮易水寒

      你用rclone的时候是直接把本地挂载盘当下载盘使用?那个oneindex用的哪个上传脚本?

      1. 风萧萧兮易水寒
        @Rat's

        (1)在挂载后,cd /root/xxx,进入文件直接wget测试就要遇到上述情况,如果使用mv来移动进去直接报错。(2)使用的是在oneindex文件夹里面自带的。命令是php one.php upload:file 本地文件 [onedrive文件],就是进入oneindex的目录文件夹执行前面那个命令就可以上传,不过貌似只能上传单个文件。

        1. Rat's
          @风萧萧兮易水寒

          那个oneindex可以上传文件夹,具体你可以查看我那个教程,rclone本身就有点BUG。

    2. 风萧萧兮易水寒
      @风萧萧兮易水寒

      我用oneindex自带的上传可以正常上传,超了500m也稳妥。不过就是不能自动上传要用命令传。

  5. 老几

    萌鼠大
    获得了"access_token",
    在linux上粘贴授权内容后,提示:
    Failed to configure token: invalid character 'e' looking for beginning of value
    是AWS的Lightsail。ubuntu环境。求帮忙萌鼠大~

    1. Rat's
      @老几

      提示你有个e字符无效。

  6. shasha

    请问下挂多个盘是不是重复rclone config命令就行了?

    1. Rat's
      @shasha

      大概是这样的。

      1. 老几
        @Rat's

        哦 自己sabile。没复制完整。

  7. ly

    修改一下内容:
    NAME="" #rclone name名,及配置时输入的Name
    REMOTE='' #远程文件夹,OneDrive网盘里的挂载的一个文件夹
    LOCAL='' #挂载地址,VPS本地挂载目录

    请问下这个如何修改呀

    1. Rat's
      @ly

      NAME是你配置时候填的名称;REMOTE是网盘里需要挂载的一个文件夹,比如MOE;LOCAL是你需要将网盘那个文件夹挂载到服务器的文件夹,比如/root/gd。

  8. xinxin8816

    大佬,挂载时候会有错误,没找到解决方法,是什么情况。 /dev/fuse已有777权限
    2018/08/10 17:10:51 mount helper error: fusermount: failed to open /dev/fuse: Operation not permitted
    2018/08/10 17:10:51 Fatal error: failed to mount FUSE fs: fusermount: exit status 1

    1. Rat's
      @xinxin8816

      什么架构服务器?不支持OVZ。

  9. Lengsir

    你这1PB有点吓人啊

    1. Rat's
      @Lengsir

      显示有问题,感觉不管挂载啥盘,都是显示1PB。

  10. 布丁

    Failed to create file system for "onecoma:sharemove": failed to get root: activityLimitReached: throttledRequest: The request has been throttled

    1. Rat's
      @布丁

      什么系统?是root权限吗。

      1. 布丁
        @Rat's

        是的 就是死活挂载不上 但是可以直接执行 rclone move 文件 onecom:test 可以直接上传 唉 就是挂载不上头痛了

        1. Rat's
          @布丁

          这问题我还没遇到过,具体不是很清楚,你先在挂载命令前面加个sudo试试,比如sudo rclone mount。

          1. HYMN
            @Rat's

            老哥我也是这样,vultr的Debian,搬瓦工的centos好好的