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

    请问下,如果咱想让vps的两个不同的文件夹,分别挂载同一个onedrive里的不同的两个文件夹,这个/etc/init.d/rcloned脚本应该如何修改?

    1. Rat's
      @SCGabriel

      那你就重复一些参数,区分下就行了,相信你会搞。

  2. whrs

    Failed to create file system for "cs:asd": failed to get root: activityLimitReached: throttledRequest: The request has been throttled
    之前挂载成功了,不知什么情况现在不行

    1. Rat's
      @whrs

      这问题没遇到过,估计次数多了暂时被限制了。

  3. whrs

    Failed to create file system for "cs:cs1": failed to get root: unauthenticated: Must be authenticated to use '/drive' syntax
    请问这是什么问题?

    1. Rat's
      @whrs

      授权成功了没?

      1. whrs
        @Rat's

        可以挂载了,之前粘贴问题可能xshell版本引起的。现在的话是自启失败
        bash /etc/init.d/rcloned start
        [错误] rclone 启动失败 !

        NAME="cs"
        REMOTE='cs1'
        LOCAL='/www/wwwroot/'

        rclone mount cs:cs1 /www/wwwroot --copy-links
        不清楚什么问题,这样设置应该是对的吧

        1. Rat's
          @whrs

          什么系统?

          1. whrs
            @Rat's

            debian 8

            1. Rat's
              @whrs

              你运行下命令apt install sudo -y。

  4. whrs

    Then paste the result below:
    result> {"access_token":""} #输入之前在客户端授权的内容

    token格式是{"access_token":""}?
    客户端获取的是{"access_token":"xxx","token_type":"Bearer","refresh_token":"xxx","expiry":"xxx"}
    是要把后面的都去掉留{"access_token":"xxx"}这样的格式吗?
    但我这样复制粘贴过去xxx只粘贴了一点,后面还有好多没粘贴进

    1. Rat's
      @whrs

      按要求复制,你可以复制到文本去掉空格后,再一起复制进去。

  5. Sicem

    博主,您好~
    为什么执行挂载命令后总是卡主呢?测试用命令新建onedrive里的文件夹也是可以表示链接上了。
    唯独执行挂载命令后就没有反映了,挂载磁盘需要的时间长么?
    rclone mount kazewo:backup /root/oned --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

    1. Rat's
      @Sicem

      卡住正常,不过显示挂载好了就行了。

      1. Sicem
        @Rat's

        不过^C了之后 进行df -h 查看并没有挂载上去。

        1. Rat's
          @Sicem

          挂载命令那项不出错的话,你就等等,然后额外开个ssh窗口用df -h查看成功没。

          1. Sicem
            @Rat's

            感谢了,额外开了个SSH成功了~~~

  6. whrs

    输入授权码时自动换行了,怎么回事?

    1. Rat's
      @whrs

      复制到txt文本,消掉空格再输入。

  7. weige

    2018/05/09 11:18:26 Failed to create file system for "233:123": failed to get root: Get https://api.onedrive.com/v1.0/drive/root:/: dial tcp: lookup api.onedrive.com on 8.8.4.4:53: read udp 0.0.0.0:35289->8.8.4.4:53: i/o timeout

    1. Rat's
      @weige

      估计是Rclone的问题。

      1. weige
        @Rat's

        添加完token 后悔提示这个
        2018/05/09 12:38:23 ERROR : Failed to save new token in config file: section '233' not found

        1. Rat's
          @weige

          233不存在,你再仔细检查下。

          1. weige
            @Rat's

            创建这个第一步不是要名字吗,这个233我是设置的名字啊咋会不存在的啊很迷

            1. Rat's
              @weige

              别用数字,用英文看看。

  8. SCGabriel

    问下mandb是不是只有centos7有?装rclone一直报mandb: command not found

  9. Overnightneko

    大佬你好,我现在挂载好了onedrive,自启动脚本也已经设置好,但是为什么会出现mv文件时挂载的网盘掉了,只能重新用bash /etc/init.d/rcloned start启动,文件不到500mb
    root@AppropriateVicious-VM:~# mv lineage-14.1-20180420-nightly-kenzo-signed.zip /root/onedrive
    mv: failed to close '/root/onedrive/lineage-14.1-20180420-nightly-kenzo-signed.zip': Software caused connection abort

    1. Overnightneko
      @Overnightneko

      貌似还是文件太大了?(才500mb啊),刚才试了一个二十多mb的mp4文件

      1. SCGabriel
        @Overnightneko

        咱花了点时间研究,发现在/etc/init.d/rcloned里添加“ --buffer-size 0 --transfers 1 ”这个参数能有效降低内存占用。
        --buffer-size 0 是禁用禁用缓冲区,--transfers 1 是将文件传输的并发数由默认的4改为1 。
        最后最好还是给vps分配10GB左右的swap比较能撑的住。

        1. Rat's
          @SCGabriel

          首先你需要个很大的硬盘,10g有点多,估计效率不会那么高。

      2. Rat's
        @Overnightneko

        OneDrive好像是以4G为界限,不过听说rclone很占内存,如果内存太小,会被杀掉进程。

        1. SCGabriel
          @Rat's

          内存占用接近97%,每次传到1.17GB的时候就失败orz
          咱vps是2G ram
          cp: failed to close ‘/root/onedrive/Alice/Breaking.Bad.S01E01.2008.BluRay.720p.x264.AC3-CMCT.mkv’: Software caused connection abort

          1. Rat's
            @SCGabriel

            我都是8G内存玩挂载,进程被杀掉的基本没遇到。

            1. SCGabriel
              @Rat's

              后面给了10GB的swap就没出错了

  10. Z

    使用sudo会导致脚本无法启动

    1. Rat's
      @Z

      重启脚本?那不用sudo。

      1. Z
        @Rat's

        脚本里挂载为磁盘用的是sudo,所以脚本无法启动

        1. Rat's
          @Z

          这个我测试的时候,是可以的,或者你再安装下apt-get install sudo -y。