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. 寒夜方舟

    https://www.coldark.cn/archives/40.html
    rclone自带了http服务,博主可以看看

    1. Rat's
      @寒夜方舟

      可以有。

  2. 千秋Sakina

    Failed to create file system for "onedrive:nextcloud": failed to get root: unauthenticated: Must be authenticated to use '/drive' syntax
    挂载时提示这个
    apt install sudo -y运行过了
    指令前也加了sudo
    但还是不好使,求解

    1. Rat's
      @千秋Sakina

      好像说你还没配置好。

  3. 57021

    Error: Auth Error

    Description: No code found returned by remote server.

    授权的时候出现这种错误怎么回事啊,感谢楼主

    1. 夜色清风
      @57021

      同样问题,似乎是管理没开权限

    2. Rat's
      @57021

      这个我还没遇到过,你多试试看看。

  4. steady

    博主你好 我挂载上OneDrive之后 发现rclone 占用linux内存很大 有没有解决办法呢?
    还有个问题是 我用我们学校的edu 配置onedrive出现了这个错误,就是再客户端登录微软账号后出现的(确定账号密码输入正确)
    Error: Auth Error

    Description: No code found returned by remote server.

    1. Rat's
      @steady

      内存大可以看看这个文章:https://www.moerats.com/archives/877/

  5. steady

    博主你好 我在问一个问题, VPS加载上的OneDrive里的文件可以直接运行吗? 我chmod +x xxx.sh 好像没有加上啊! 有什么解决的办法吗?

    1. Rat's
      @steady

      有些时候别把挂载盘当服务器硬盘使用,不然会有很多问题。

      1. steady
        @Rat's

        好的 谢谢博主, 但是我还是想知道可以在挂载盘上直接运行代码吗? 有什么办法没有?

        1. Rat's
          @steady

          这个按理说是不能的。

  6. steady

    博主你好 我遇到了一个问题,挂在上之后如果linux主机新建文件,windows onedrive会查看到新建的文件。但是windows onedrive新建一个文件,再linux主机里查看不到 设置重启自动挂载之后 重启linux主机之后才能看到。

    1. steady
      @steady

      自问自答:linux主机上多等一会儿。

  7. 左右为男

    多个网盘如何设置自启?

    1. Rat's
      @左右为男

      开机自启参考这篇文章https://www.moerats.com/archives/870/,然后多个网盘的话,把Systemctl文件,区分一下,比如rclone1.service、rclone2.service,启动和设置的时候,也记得改对应的名称

      1. 左右为男
        @Rat's

        感谢!

  8. Xiaow

    如何挂载多盘呢?

    1. Rat's
      @Xiaow

      挂载多个其实差不多,先了解下思路和步骤,然后重复操作就行了。

  9. 何必呢

    帅帅的博主帮忙看一下啊。
    我装的RCLONE版本比示范中的要更新一些了。所以没给我留下输入授权的token的那个环节。
    而是在命令行下,直接出了一个http://127.0.0.1:53682/auth的连接。我用VPS的IP地址,替换掉127.0.0.1,在PC的浏览器中访问,显示不出页面内容来。于是整个安装过程就被卡死在这里了。
    先是挂载Google Drive的时候,是这样的。后来再试,挂载OneDrive的时候,也是如此。总是不留给我输入的机会,直接要VPS自己等token的返回值。
    请问,能不能有其他的办法,恢复出那个输入的界面么?毕竟我已经在PC上,获取了token了呢。
    或者,能不能您出个教程,指点一下,是否可以直接通过编辑配置文件啥的方式,把token给写进去呢?

    1. Rat's
      @何必呢

      这个输出http://127.0.0.1:53682/auth的话,应该是配置文件选项填的不对,你看下是哪个选项出现这个,再重新来一次,选择另一个选项看看。

      1. 何必呢
        @Rat's

        恩恩。您推测得对。是我选错选项的结果。一部一部重做,逐个反着试,果然找到问题了。多谢!

  10. ula

    挂载成功后,没设置自启,重启vps后所有网站都不能访问,包括宝塔,登陆ssh显示───────────────────────────────────────────┐
    │ npm update check failed │
    │ Try running with sudo or get access │
    │ to the local update config store via │
    │ sudo chown -R $USER:$(id -gn $USER) /root/.config │
    └───────────────────────────────────────────────────┘
    这个该怎么解决呢?

    1. Rat's
      @ula

      网站不能访问,貌似与挂载没啥关系,具体得你慢慢查看原因。

      这个提示好像是权限问题,运行 sudo chown -R $USER:$(id -gn $USER) /root/.config看看。

      1. ula
        @Rat's

        嗯,最后发现是硬盘沾满的原因,然后删了一些东西就好了