Ubuntu/Debian上使用rclone挂载OneDrive网盘

一键安装rclone:

curl https://rclone.org/install.sh | sudo bash

客户端授权

在本地Windows电脑上下载rclone,下载地址:https://rclone.org/downloads/。然后解压出来,比如我解压到D盘,文件夹命名rclone,此时进入rclone文件夹,按住shift,右击,选择在此处打开powershell窗口。再输入以下命令:

rclone authorize "onedrive"

接下来会弹出浏览器,要求你登录账号进行授权

Log in and authorize rclone for access
Waiting for code...
Got code
Paste the following into your remote machine --->
{"access_token":"xxxx"}  #请复制{xx}整个内容,后面需要用到

官方一键安装rclone

curl https://rclone.org/install.sh | sudo bash

安装完后,输入 rclone config 命令进入交互式配置选项,按照提示一步一步来进行操作即可。

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> n
name> drive
Option Storage.
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value.
 1 / 1Fichier
   \ "fichier"
 2 / Alias for an existing remote
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, SeaweedFS, and Tencent COS
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Better checksums for other remotes
   \ "hasher"
 7 / Box
   \ "box"
 8 / Cache a remote
   \ "cache"
 9 / Citrix Sharefile
   \ "sharefile"
10 / Compress a remote
   \ "compress"
11 / Dropbox
   \ "dropbox"
12 / Encrypt/Decrypt a remote
   \ "crypt"
13 / Enterprise File Fabric
   \ "filefabric"
14 / FTP Connection
   \ "ftp"
15 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
16 / Google Drive
   \ "drive"
17 / Google Photos
   \ "google photos"
18 / Hadoop distributed file system
   \ "hdfs"
19 / Hubic
   \ "hubic"
20 / In memory object storage system.
   \ "memory"
21 / Jottacloud
   \ "jottacloud"
22 / Koofr
   \ "koofr"
23 / Local Disk
   \ "local"
24 / Mail.ru Cloud
   \ "mailru"
25 / Mega
   \ "mega"
26 / Microsoft Azure Blob Storage
   \ "azureblob"
27 / Microsoft OneDrive
   \ "onedrive"
28 / OpenDrive
   \ "opendrive"
29 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
30 / Pcloud
   \ "pcloud"
31 / Put.io
   \ "putio"
32 / QingCloud Object Storage
   \ "qingstor"
33 / SSH/SFTP Connection
   \ "sftp"
34 / Sia Decentralized Cloud
   \ "sia"
35 / Sugarsync
   \ "sugarsync"
36 / Tardigrade Decentralized Cloud Storage
   \ "tardigrade"
37 / Transparently chunk/split large files
   \ "chunker"
38 / Union merges the contents of several upstream fs
   \ "union"
39 / Uptobox
   \ "uptobox"
40 / Webdav
   \ "webdav"
41 / Yandex Disk
   \ "yandex"
42 / Zoho
   \ "zoho"
43 / http Connection
   \ "http"
44 / premiumize.me
   \ "premiumizeme"
45 / seafile
   \ "seafile"
Storage> 27
Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>
Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>
Option region.
Choose national cloud region for OneDrive.
Enter a string value. Press Enter for the default ("global").
Choose a number from below, or type in your own value.
 1 / Microsoft Cloud Global
   \ "global"
 2 / Microsoft Cloud for US Government
   \ "us"
 3 / Microsoft Cloud Germany
   \ "de"
 4 / Azure and Office 365 operated by 21Vianet in China
   \ "cn"
region> 1
Edit advanced config?
y) Yes
n) No (default)
y/n>
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine

y) Yes (default)
n) No
y/n> n
Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
        rclone authorize "onedrive"
Then paste the result.
Enter a string value. Press Enter for the default ("").
config_token> #输入之前在客户端授权的内容
--------------------中间省略
 #最后选择q退出

挂载

1、挂载为磁盘

#新建本地文件夹,路径自己定
mkdir /root/OneDrive

挂载网盘:

rclone mount drive:/ /root/GoogleDrive --copy-links --allow-other --allow-non-empty --umask 000 --daemon

然后输入 df -h 命令查看挂载情况。

————————————————————

取消挂载:

fusermount -qzu /Onedrive

开机自动挂载

  • 下载并编辑自启脚本
wget -N git.io/rcloned && nano rcloned
  • 修改内容:
NAME="Onedrive" #Rclone配置时填写的name
REMOTE=''  #远程文件夹,网盘里的挂载的一个文件夹,留空为整个网盘
LOCAL='/Onedrive'  #挂载地址,VPS本地挂载目录
  • 设置开机自启
mv rcloned /etc/init.d/rcloned
chmod +x /etc/init.d/rcloned
update-rc.d -f rcloned defaults # Debian/Ubuntu
chkconfig rcloned on # CentOS
bash /etc/init.d/rcloned start

看到 [信息] rclone 启动成功 ! 即可。

管理

开始挂载 bash /etc/init.d/rcloned start

停止挂载 bash /etc/init.d/rcloned stop

重新挂载 bash /etc/init.d/rcloned restart

查看日志 tail -f /$HOME/.rclone/rcloned.log

卸载自启挂载

bash /etc/init.d/rcloned stop
update-rc.d -f rcloned remove # Debian/Ubuntu
chkconfig rcloned off # CentOS
rm -f /etc/init.d/rcloned