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

    挂载死活挂不上,rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 这步,
    root@vultr:~# rclone mount Rats:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
    2019/01/12 18:33:18 Fatal error: failed to mount FUSE fs: mountpoint does not exist: /root/LocalFolder

    1. Rat's
      @lee

      大概的意思是说你本地挂载得文件夹不存在,也就是/root/LocalFolder,看下我挂载那里得说明。

  2. 橙子77

    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

    我也遇到这个了,以前挂载过很多次不知道啥原因。大鼠兄弟,我给你VPS账号和od账号能否帮忙挂载下 2018/12/29 21:22:32 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": "e6271faa-e2d2-4ad0-829a-275ed42fba8a",rn "date": "2018-12-29T13:22:33"rn }rn }rn}"

    1. Rat's
      @橙子77

      这个问题楼下有同学遇到并解决了,方法也说了,你先看看,实在不行的话我再帮你。

      1. 橙子77
        @Rat's

        看里下面留言了还是没办法。 能否帮下忙

        1. Rat's
          @橙子77

          加我下面留的微信。

          1. 橙子
            @Rat's

            没看到啊

  3. 橙子

    rclone 配置时添加onedrive令牌 显示这个怎么回事 2018/12/28 14:10:33 Failed to configure token: parsing time ""20181228T22:52:11.3593771+08:00"" as ""2006-01-02T15:04:05Z07:00"": cannot parse "1228T22:52:11.3593771+08:00"" as "-"字面是无法解析令牌时间-,- 以前安装都没遇到过字面是无法解析令牌时间-,- 以前安装都没遇到过

    1. Rat's
      @橙子

      这问题我还没遇到过,你本地时间和服务器一样么?不同步一般都会绑定失败。

      1. 橙子77
        @Rat's

        cmd默认换新复制到TXT 是- 符号。 全替换-为空导致时间那里的-为空了

  4. 小白

    请问一下,rclone可以把A账号onedrive的内容rclone到B账号onedrive下么?不是一个主账号。或者,reclone到其他网盘,比如Google。

    1. 橙子
      @小白

      教育版的onedrive,pc获取的令牌时候没让选择。教育还是个人版。 获取令牌成功。 vps上配置不成功,显示上面那个。系统是大便

      1. Rat's
        @橙子

        现在好像没选择了,都是直接弹出令牌。

    2. Rat's
      @小白

      你可以挂载onedrive和Google,先将一个挂载盘移动到服务器中,再移动到另一个挂载盘。别直接在两个挂载盘移动,不然可能会出现问题。

  5. 梁Sir

    老哥
    bash /etc/init.d/rcloned start
    显示rclone启动失败 但是手动挂载可以挂载上 这个是什么情况呢?

    1. Rat's
      @梁Sir

      什么系统?还有自启脚本里填的参数正确么?

      1. 梁Sir
        @Rat's

        centos7 参数是正确的

        1. Rat's
          @梁Sir

          这个自启命令是给debian/ubuntu用的,centos我还试过。你先yum install sudo看看?

          1. 梁Sir
            @Rat's

            老哥
            设置自启的第三步
            我是添加了服务 chkconfig rcloned on
            自启脚本里的参数是我copy另一台自启挂载正常的centos7上的
            yum install sudo Nothing to do

            1. Rat's
              @梁Sir

              你把自启脚本里的挂载sudo命令去掉看看,自启的话用这2个命令chkconfig --add rcloned、chkconfig rcloned on

              1. 梁Sir
                @Rat's

                删掉自启脚本内的sudo /usr/bin/字段后
                可以手动挂载成功了
                使用chkconfig --add rcloned和chkconfig rcloned on添加自启了
                chkconfig --list 列表内有rcloned
                但是重启后没有自动挂载上
                时间也是对的 有点假..

                1. Rat's
                  @梁Sir

                  你装个sudo吧,然后加上sudo /usr/bin/,还不行的话,有时间我自己测试一下CentOS。

                  1. 梁Sir
                    @Rat's

                    感觉有毒 sudo装了的 加上sudo /usr/bin/ 之后手动挂载就是启动失败 删了之后就能手动挂载上

                    1. Rat's
                      @梁Sir

                      可以看看这篇教程,CentOS 7、Debian 8+、Ubuntu 16+使用Systemctl守护Rclone开机自启,https://www.moerats.com/archives/870/

  6. 咕咕咕

    请问一下。我之前搭建的aria2下载文件后用oneindex自动上传到onedrive,后来想说能不能直接挂载onedrive到本机进行管理。挂载成功后没做其他改动,但是oneindex没办法上传文件到onedrive了,只有几个临时文件,怎么办啊?需要更改oneindex的路径到本机吗?

    1. Rat's
      @咕咕咕

      你是说将Onedrive挂载到服务器上管理?上传的话,你试试这个脚本:https://www.moerats.com/archives/697/。

      1. 咕咕咕
        @Rat's

        谢谢大佬回复,我是想说想个办法将Onedrive挂载到服务器上管理。我新建了个主机搭了nextcloud,想说在vps通过rclone挂载onedrive后用nextcloud的外部储存管理。但是在vps里看是能看到onedrive文件的,在nextcloud外部储存里没有东西,而且也没办法进行上传文件操作

        1. Rat's
          @咕咕咕

          rclone挂载的网盘只能读取和移动进去,但不能直接写入。

          1. 咕咕咕
            @Rat's

            请问我挂载之后会老是会断掉,有没有检测断掉后让它自动重新挂载的办法啊?

            1. Rat's
              @咕咕咕

              断掉貌似是内存的问题,这东西挺耗内存的,你加几G虚拟内存就好些。

  7. 输入得到的代码后提示Failed to configure token: failed to get token: Post https://accounts.google.com/o/oauth2/token: dial tcp 74.125.204.84:443: i/o timeout

    1. @力

      我是在openwrt软路由上挂载

      1. Rat's
        @力

        有种网络的原因。多试几次看看。

  8. 碧水

    2018/11/19 11:59:42 Failed to query available drives: Get https://graph.microsoft.com/v1.0/me/drives: oauth2: canno
    t fetch token: 401 Unauthorized
    Response: {"error":"invalid_client","error_description":"AADSTS70002: Error validating credentials. AADSTS50012: In
    valid client secret is provided.rnTrace ID: b9e8d0d4-c407-4738-a8ee-d7456d664000rnCorrelation ID: 9eaa7329-6484
    -4de0-9393-17f4bef1725frnTimestamp: 2018-11-19 03:59:42Z","error_codes":[70002,50012],"timestamp":"2018-11-19 03:
    59:42Z","trace_id":"b9e8d0d4-c407-4738-a8ee-d7456d664000","correlation_id":"9eaa7329-6484-4de0-9393-17f4bef1725f"}

    1. Rat's
      @碧水

      重新来吧,按步骤走是没问题的,检查下TOKEN,需要复制{"access_token":"xxxx"}整体,包括{},还不能有空格。而且配置的时候貌似多了个授权,选择1就行了。

  9. 匿名.

    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": "2e0e9370-e197-423a-9726-9a08059c2bbb",rn "date": "2018-11-17T07:54:34"rn }rn }rn}"

    请问这个是什么原因呢 重新获取TOKEN后还是提示这个

    1. Rat's
      @匿名.

      复制的TOKEN貌似不对,需要复制{"access_token":"xxxx"}整体,包括{},还不能有空格。

      1. 匿名.
        @Rat's

        的确是复制的{"access_token":"xxxx"}整体 空格检查了好几遍了 没有的

        1. Rat's
          @匿名.

          仔细看了下错误,会不会是你权限没给?如果不是的话,我就没法了,我自己没出现过这问题。

          1. 匿名
            @Rat's

            发现只让选择账户登陆了 登陆之后 没有什么是否允许授权的那个页面了 直接显示Success!

            1. 七剑下面条
              @匿名

              我之前也是这样,发现是XSHELL版本的问题,从xshell6换成xshell5就可以了

            2. Rat's
              @匿名

              我前几天重新试的时候,好像有几个权限选项。

              1. 涵墨轻笙
                @Rat's

                我知道这个原因了
                我遇到的情况是我本身的系统是Linux,与VPS系统不同的发行版
                所以我选择和VPS共同从官网下载同一个rpm包使用,就没有这种情况(简单的说就是可以换一个包试试,或者全部从官网上下载)

                估计不同的人编译的软件特征不同,导致获取到的docken不能共用

                1. Rat's
                  @涵墨轻笙

                  涨姿势了,可以给遇到这个问题的人参考下。

  10. 碧水

    Failed to configure token: parsing time ""2018-11-15T11:07:57.9235216 +08:00"" as ""2006-01-02T15:04:05Z07:00"": cannot parse " +08:00"" as "Z07:00"
    这个是什么问题??

    1. Rat's
      @碧水

      貌似时间不同步,VPS和本地电脑。

      1. 碧水
        @Rat's

        Failed to save new token in config file: section 'onedrive' not found
        又出现这个了

        1. Rat's
          @碧水

          会不会是你配置文件复制不对,或者空格没消除?感觉就是你配置的时候出了问题。

      2. 碧水
        @Rat's

        我用date看了vps时间,和本地差不多啊