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

    401错误的,一般都是在windows里处理换行符出问题了。我是直接从cmd里复制到UE里替换n,把换行符去掉。确保格式变成unix格式后再粘贴到terminal就可以了。

    1. Rat's
      @eric

      感谢提供,给遇到的人看看。

      1. Suwen
        @Rat's

        博主你好,我想问一下可以用sync先同步所有文件到本地吗,实时下载好慢啊

        1. Rat's
          @Suwen

          不会用的国内网络下载的吧?

  2. lmr

    rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
    这句会执行多久?我已经过5分钟了

    1. Rat's
      @lmr

      再开个窗口使用df -h看看,应该挂好了。

      1. lmr
        @Rat's

        挂上了!谢大佬!

  3. bajins

    还有你文章应该加标签的,直接搜索不到想要的效果,比如搜索同步

    1. Rat's
      @bajins

      博客搜索,标签啥的,没咋设置,很随意搞的

  4. bajins

    请问我要如何把文件夹a同步到OneDrive,文件夹a在/home/下,OneDrive挂载文件夹在/root/下

    1. Rat's
      @bajins

      试试mutagen?地址:https://www.moerats.com/archives/980/,你就同步文件夹a和挂载的就可以了。如果挂载盘产生很多缓存文件夹的话,请回复我,我教你。不过这也是我猜的。

      1. bajins
        @Rat's

        我直接用的 rclone sync

  5. Garasu

    教育邮箱注册的onedrive1T那种,用rclone挂载获取token时候 提示这个 换了号换了电脑试都这样,两天了 不知道为啥, 教育邮箱的不能吗? 希望大佬有时间可以答疑一下。。

    2019/08/12 22:40:08 Failed to configure token: failed to get token: oauth2: cannot fetch token: 401 Unauthorized
    Response: {"error":"invalid_client","error_description":"AADSTS7000215: Invalid client secret is provided.rnTrace ID: a608fbb7-42c3-46db-8865-4d592e2f9700rnCorrelation ID: 7887f12f-ee14-43fe-88ef-21f811081a42rnTimestamp: 2019-08-12 14:40:07Z","error_codes":[7000215],"timestamp":"2019-08-12 14:40:07Z","trace_id":"a608fbb7-42c3-46db-8865-4d592e2f9700","correlation_id":"7887f12f-ee14-43fe-88ef-21f811081a42","error_uri":"https://login.microsoftonline.com/error?code=7000215"}

    1. spider
      @Garasu

      你把windows的rclone更新到最新版本试一下,我之前也遇到了这个问题,更新了rclone之后就成功了

    2. Rat's
      @Garasu

      这问题好像情况遇到过几种,你能说下具体哪个步骤吗,是win上获取token,还是挂载的时候

      1. Garasu
        @Rat's

        另外,绑定oneindex是成功的。

      2. Garasu
        @Rat's

        在win上获取token的时候。选的bessness 然后自动,网页输入账号后 显示成功,但是cmd里返回的这个,我用我个人账号 就成功了。

        1. Rat's
          @Garasu

          你这个教育版咋搞的?好像以前有很多教育版封了管理员但是子账号还在的,这种就无法使用api。大概我就知道这些了。

          1. Garasu
            @Rat's -就是网上找到 方法注册的, 但是可以绑 oneindex呀,而且用rclone 获取token的时候 网页端也显示 成功,但是rclone 却显示失败。
            可以手动 获取像oneindex 的client id 哪个一样设置吗? 我看microsoft azure 上可以手动申请client id。
            1. Rat's
              @Garasu

              好像这里可以检测管理员翻车没,你试试?教程地址:https://moeclub.org/2019/01/18/730/

              1. Garasu
  6. 找先森

    请教一下rclone来挂载onedrive到linux服务器上的网站,直接挂载都我存储图片的位置,最后的结果是图片在网站上不显示,没有权限访问,这个要怎么解决呢

    1. Rat's
      @找先森

      微软的api有请求频率限制,网站图片这种估计是gg。

  7. Linon

    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...
    vps一直卡在这

    1. Linon
      @Linon

      好了

  8. actanble

    你怎么搞到1P的容量的,,教教我

    1. Rat's
      @actanble

      显示问题,你挂载也会显示这么多

  9. 123

    请问这个搭建出来的东西vps下载后东西会继续占用vps的硬盘空间吗,需要手动删除吗

    1. Rat's
      @123

      不占用vps空间

  10. Clarke

    在墙内安装的时候下载rclone.zip都是几K/秒,能不能优化一下呢?还有大佬能做一个在docker里装rclone的教程吗?我在网上搜了,都没有这个教程

    1. Rat's
      @Clarke

      这个速度的话加BBR啥的试试,Docker感觉不太好操作,我有空看看吧