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

发表评论

342 条评论

  1. viiber

    大佬,请问access token 只有一个小时的有效期,我copy的时候开始有速度,一小时后就跑不动,需要重新获取token,请问有什么解决办法?(自建的api)

  2. XLLILY

    大佬,我现在用rclone copy ,来复制同步本地文件到云盘。想问下,出现同名文件不同哈希(传输中断或者出错导致的有文件只传输了一部分),用什么方法,什么指令,使用本体文件来覆盖这些同名不同哈希的文件。

    1. XLLILY
      @XLLILY

      还有就是上传缓存的问题,如何更改上传缓存文件的位置(上次找个资料看到过 vfs-xx-cash = **啥的,结果配置文件弄丢了,我也忘记在那里加这个了)我是在esxi里弄了个小的ubuntu,然后第一次分配的空间太小25g,挂载了2t的硬盘下载视频来上传,然后我又分配了15g打算作为上传缓存文件区域。只能作为一个新分区,不能给原本的分区扩容。

      1. Rat's
        @XLLILY

        这个不太清楚,好久没用了,你试试从官方文档找找

  3. vfvf

    AADSTS900144: The request body must contain the following parameter: 'client_id'.

    傻逼rclone 急死了

  4. 绘梨衣

    2021/05/23 00:25:01 Failed to configure token: parsing time ""2021-05-23T16:23:11. 3261349+08:00"" as ""2006-01-02T15:04:05Z07:00"": cannot parse ". 3261349+08:00"" as "Z07:00"该怎么办授权完出现的

    1. Rat's
      @绘梨衣

      看着好像是时间不一致引起的,本地和服务端

  5. xllily

    rclone.service - Rclone

    Loaded: loaded (/etc/systemd/system/rclone.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sat 2021-05-08 23:04:45 CST; 12min ago Process: 10443 ExecStart=/usr/bin/rclone mount onedrive:VV /home/xllily/onedrive --copy-links --no-gzip-en>

    Main PID: 10443 (code=exited, status=1/FAILURE)

    5月 08 23:04:44 virtual-machine systemd[1]: Started Rclone.
    5月 08 23:04:45 virtual-machine rclone[10443]: Failed to create file system for "onedrive:VV": failed to get r>
    5月 08 23:04:45 virtual-machine systemd[1]: rclone.service: Main process exited, code=exited, status=1/FAILURE
    5月 08 23:04:45 virtual-machine systemd[1]: rclone.service: Failed with result 'exit-code'.

    大佬你好。我是从本地复制文件给挂载的onedrive上传备份。然后传着传着就发现onedrive的挂载盘打开显示为空了。然后文件系统显示仍旧挂载着,不过容量从以前的 25t,变成了1pb。然后我重启rclone,查看状态就出现这个错误报告。不过每次出了这个问题,我就重启ubuntu,就会变正常。

    1. Rat's
      @xllily

      这个不太清楚,好像挂掉了似的

  6. 小草

    请问一下,按照onedrive那篇教程挂载onedrive出现NOTICE: One drive root 'backup': --vfs-cache-mode writes or full is recommended for this remote as it can't stream,是什么问题

  7. 鸡毛

    rclone mount od: /www/wwwroot/mov.jimao.me/od --allow-other --allow-non-empty --vfs-cache-mode writes
    2021/02/17 16:44:39 Failed to create file system for "od:": failed to get root: serviceNotAvailable: Service unavailable
    换了很多路径都是提示这个,大佬救我

    1. Rat's
      @鸡毛

      重新初始化获取令牌试试?

  8. 杯葛

    大佬你好,我在配置rclone.service文件时,systemctl start rclone 一直遇到报错
    "Executable path is not absolute, ignoring: =/usr/bin/rclone ...",但是我在配置文件里写的确实是绝对路径,文件内容如下:
    [Unit]
    Description=rclone
    After=network-online.target

    [Service]
    Type=simple
    ExecStart=/usr/bin/rclone mount onedrive:<具体配置省略...>
    Restart=on-abort
    User=root

    [Install]
    WantedBy=default.target

    我之前使用rclone命令手动运行是成功的,onedrive也已经成功挂载到本地了,但是自启动一直没法配置。command -v rclone 得到的结果就是 /usr/bin/rclone
    请问是哪里出问题了呢?

    1. Rat's
      @杯葛

      好像看不出啥来

  9. yaronzz

    有用

  10. RWBYYang

    大佬,我挂上onedrive之后,h5ai里面死活不显示咋整啊,其余文件都显示,不挂载也可以看到,只要一挂载就没有了

    1. Rat's
      @RWBYYang

      不太清楚,如果只是想把onedrive文件列表出来的话,可以试试onelist。rclone只用来同步就行了