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

    rat,能不能加我一下帮我看一下啊,真的求求你了,弄了几天了都没弄出来,我用的cloudcone的centos7的vps,参照了https://www.youtube.com/watch?v=whAAyKd58gg和https://www.youtube.com/watch?v=xaZUNyHlorc以及你的教程,我是在rclone之后安装了之后的脚本,onedrive的授权也没问题但是使用aring下载东西vps里面没有,能不能帮帮我啊

    1. Rat's
      @123

      你是直接下到了挂载盘?

      1. 123
        @Rat's

        什么意思,没有哦,我之前是想着挂载硬盘,后来看视频说是是使用rclone可以直接使用移动命令就不需要挂载了,但是不管我挂载不挂载我在aring下载的东西我的vps里面都找不到

  2. 轻风伴梦

    挂载的目录和子目录不能设置WWW权限请问博主咋整

    1. Rat's
      @轻风伴梦

      这个我还没试过改用户组权限。

      1. 轻风伴梦
        @Rat's

        找到原因了,我网站是在/home/wwwroot/xxx.com目录下,如果挂载在/home/wwwroot/onedrive下是无法链接外部存储的,必须挂载在/home/wwwroot/xxx.com/onedrive网站目录下才行

      2. 轻风伴梦
        @Rat's

        现在安装了nextcloud,想挂载onedrive作为外部存储,但是nextcloud只能识别www权限的文件夹,或者博主有别的网盘程序支持权限分组可以外挂onedrive的介绍吗

  3. John

    -bash: rclone: command not found
    debian7

    1. Rat's
      @John

      rclone安装了么?

  4. LYM

    话说为什么我谷歌浏览器访问这一页面一会后会很卡呢?

    1. Rat's
      @LYM

      什么页面?

      1. LYM
        @Rat's

        emmmm关了谷歌自动翻译就没事了。。。看来是谷歌翻译的问题-_-||

  5. LYM

    Creating fuse device...
    /run/udev or .udevdb or .udev presence implies active udev. Aborting MAKEDEV invocation.
    chmod: cannot access '/dev/fuse': No such file or directory
    dpkg: error processing package fuse (--configure):
    subprocess installed post-installation script returned error exit status 1
    Errors were encountered while processing:
    fuse
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    安装fuse出现这种错误-_-||

    1. Rat's
      @LYM

      OVZ服务器?如果是就需要发工单要服务商给你打开fuse

  6. LYM

    mount helper error: fusermount: fuse device not found, try 'modprobe fuse' first
    Fatal error: failed to mount FUSE fs: fusermount: exit status 1

    。。。。。缺少fuse?

  7. hanling dong

    群晖里应该如何使用rclone mount呢

    1. Rat's
      @hanling dong

      群晖没用过,你看下官方安装文档,一般能安装就可以用,地址:https://rclone.org/downloads/

      1. hanling dong
        @Rat's

        谢谢 安装成功了 ,能看到onedrive ,就是不知道群晖里rclone mount 的那个docker该怎么设置 挂载

  8. sand

    rclone下载文件夹里的文件可以包含外面的文件夹吗

    1. Rat's
      @sand

      什么意思

  9. ak4490

    又发现一个问题,rclone mount语句后加了一个&符号,立刻挂载上了

    1. Rat's
      @ak4490

      其实不用&也是挂好了,只是卡住了,&是后台运行,让你觉得立马挂上去了而已。

  10. ak4490

    博主,复制后总是报错,Failed to query available drives: HTTP error 401 (401 Unauthorized) returned body: "{rn "error": {rn "code": "InvalidAuthenticationToken",rn "message": "CompactToken parsing failed with error code: 8004920A",rn "innerError": {rn "request-id": "8278071f-aff4-471c-9f0b-ad28b535617b",rn "date": "2019-04-01T11:04:37"rn }rn }rn}"

    1. ak4490
      @ak4490

      解决了,windows 和linux rclone版本不一样