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

    我挂载之后,想./运行gd盘里的go程序,提示权限不够。然后chmod +x 发现改不了权限,一直固定666.请教怎么解决~

    1. arbaleast
      @lisaooo

      加个参数吧 --dir-perms 777 --file-perms 777

    2. Rat's
      @lisaooo

      好像这个不能直接当硬盘使用

  2. RaXianch

    博主大佬!
    我在/lib/systemd/system目录下创建rclone.service文件
    文件内容如下:
    [Unit]
    Description=Rclone
    After=network-online.target

    [Service]
    Type=simple
    ExecStart=/usr/bin/rclone mount ZIO-1:RXFiles /home/gdDisk/ZIO-1 --no-check-certificate --no-gzip-encoding --copy-links --umask 0000 --default-permissions --allow-non-empty --allow-other --transfers 1 --buffer-size 64M --low-level-retries 200 --dir-cache-time 12h --vfs-read-chunk-size 32M --vfs-read-chunk-size-limit 1G
    Restart=on-abort
    User=root

    [Install]
    WantedBy=default.target

    vim保存之后,使用命令:
    systemctl daemon-reload
    systemctl start rclone
    systemctl status rclone

    状态内容如下:

    ● rclone.service - Rclone
    Loaded: loaded (/etc/systemd/system/rclone.service; disabled; vendor preset: enabled)
    Active: failed (Result: exit-code) since Sat 2020-05-23 18:44:54 JST; 7s ago
    Process: 13427 ExecStart=/usr/bin/rclone (code=exited, status=1/FAILURE)
    Main PID: 13427 (code=exited, status=1/FAILURE)

    May 23 18:44:54 150-95-179-172 rclone[13427]: size Prints the total size and number of objects in remote:path.
    May 23 18:44:54 150-95-179-172 rclone[13427]: sync Make source and dest identical, modifying destination only.
    May 23 18:44:54 150-95-179-172 rclone[13427]: touch Create new file or change file modification time.
    May 23 18:44:54 150-95-179-172 rclone[13427]: tree List the contents of the remote in a tree like fashion.
    May 23 18:44:54 150-95-179-172 rclone[13427]: version Show the version number.
    May 23 18:44:54 150-95-179-172 rclone[13427]: Use "rclone [command] --help" for more information about a command.
    May 23 18:44:54 150-95-179-172 rclone[13427]: Use "rclone help flags" for to see the global flags.
    May 23 18:44:54 150-95-179-172 rclone[13427]: Use "rclone help backends" for a list of supported services.
    May 23 18:44:54 150-95-179-172 systemd[1]: rclone.service: Main process exited, code=exited, status=1/FAILURE
    May 23 18:44:54 150-95-179-172 systemd[1]: rclone.service: Failed with result 'exit-code'.

    看内容似乎是因为rclone命令有误。

    但是,我直接把ExecStart=后的命令直接复制出来在终端回车,可以正常运行,可以使用rclone move命令传递文件。

    使用supervisor 守护运行命令也可以正常使用,所以就很想知道到底不能通过服务启动rclone的原因在哪里,可以帮我看一下么?谢谢orz

    难道是要Description=Rclone这里面大小写一致?

    1. Rat's
      @RaXianch

      看报错日志好像说后面的命令参数有误

  3. 隔壁老豆

    大佬,为什么开机自启设置失败,查看状态的时候,报异常:
    Loaded: loaded (/etc/systemd/system/rclone.service; enabled; vendor preset: enabled)
    Active: failed (Result: exit-code) since Thu 2020-05-21 09:56:37 EDT; 3s ago
    Process: 20695 ExecStart=/usr/bin/rclone rclone mount Rats:XXXX /XXX/video --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 (code=exited, status=1/FAILURE)
    XXX是我手动打码吧
    Main PID: 20695 (code=exited, status=1/FAILURE)

    1. RaXianch
      @隔壁老豆

      你好,请问层主你的问题解决了吗?我也碰到的了一样情况

      1. Rat's
        @RaXianch

        我才注意到他命令有点问题,/usr/bin/rclone rclone,rclone rclone重复了,你也是?

  4. OvO

    Failed to create file system for "onedrive:downloads": failed to get root: Get https://graph.microsoft.com/v1.0/drives/xxxxxx/root: oauth2: cannot fetch token: 401 Unauthorize
    博主你好,我碰到了这个问题,好像是token只有一个小时有效期,他并不会refresh,当我一个小时没有用后我的token就过期了,这有什么办法解决吗?因为如果我手动换个token是可以用的说明配置没有问题。

  5. 11

    rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
    上面这个命令一直卡着动不了
    少了--allow-other --allow-non-empty --umask 000这一串就可以
    rclone mount DriveName:Folder LocalFolder --daemon --copy-links --no-gzip-encoding --no-check-certificate
    几台服务器都一样

    1. Rat's
      @11

      卡着正常,实际上挂上去了,额外开个窗口就可以看到挂载盘。你挂到后台就行了。或者直接配置开机自启。

  6. Kenshin

    Log in and authorize rclone for access
    Waiting for code...
    我试了很多次我电脑上已经获取了token,但就是一直卡在这里不出现result给我填(我前面的操作都没问题)

    1. Kenshin
      @Kenshin
      该评论仅登录用户及评论双方可见
  7. chancat

    有挂载到本地磁盘的办法嘛?博主

    1. Rat's
      @chancat

      挂载当本地磁盘用那种?

  8. kingmusic

    你好博主.
    我挂载onedrive ,挂载的目录下有onedrive的文件出现了.
    但是df -h 不显示挂载

  9. 西瓜

    一直是这个错误,是DNS解析不了吗
    root@aml:~# rclone mount onedrive:/ /root/onedrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
    2020/03/13 19:28:31 Failed to create file system for "onedrive:/": failed to get root: Get https://graph.microsoft.com/v1.0/drives/xxxxxxxxxxxxxxxxbNfR6tEHKBjmNOxMtrA9QnnnzRDbJb9HEpx2RrBeU8HpUnmI/root: dial tcp: lookup graph.microsoft.com on [::1]:53: read udp [1]:53: read: connection refused

    1. Rat's
      @西瓜

      试试其他目录看看,比如/opt

  10. 自作自受

    04:52:42 Failed to query root for drive b!h2y-9SkBDE2C2B1vQI_TGTqnKXc7R71IjRXNh9EZhggalYNisamjTKd6rJNMF1do: HTTP error 429 (429 ) returned body: "{rn "error": {rn "code": "activityLimitReached",rn "message": "The request has been throttled",rn "innerError": {rn "request-id": "8cd55c1f-cc0e-404a-8910-bc7f5ee38316",rn "date": "2020-03-11T08:52:42"rn }rn }rn}"

    一直卡在这了 咋办啊

    1. Rat's
      @自作自受

      提示好像是被限制还是啥的

      1. 自作自受
        @Rat's 挂载为磁盘,下面的DriveName、Folder、LocalFolder参数根据说明自行替换

        rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

        上面那个问题解决拉 但是我输入这个指令的时候,vps就一直没有反应了,那个文件夹名字都改好了

        1. Rat's
          @自作自受

          正常,你重新开一个ssh窗口df -h查看就挂上了,你设置个开机自启就好了

          1. 自作自受
            @Rat's

            但是好像没有挂载上 没有磁盘