Rclone是一款类似Windows端RaiDrive的挂载硬盘。使用Rclone,你可以将你OneDrive或者Google Drive硬盘挂载到VPS作为一个单独的分区使用。我们可以利用服务器的大带宽+云端硬盘来看小电影,免去了家里小水管下载的烦恼

安装

利用Curl来进行安装Rclone:

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

安装成功则提示

rclone v1.45 has successfully installed.
Now run "rclone config" for setup. Check https://rclone.org/docs/ for more details.

或者你也可以自己下载安装包安装
Rclone官网:https://rclone.org/downloads/

设置

安装完成后,开始添加挂载
输入rclone config来开始设置
首先添加一个新的挂载

[root@Nathosts-201885913 ~]# rclone config
2019/01/19 08:31:26 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n     #选择n添加一个新的挂载
name> googledrive   #输入新挂载的名字

然后他会让我们选择硬盘类型
OneDrive就选择MicroSoft OneDrive
Google Drive就选择Google Drive
选择谷歌云端硬盘的时候注意不要错选成Google Cloud 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 / A stackable unification remote, which can appear to merge the contents of several remotes
   \ "union"
 2 / Alias for a existing remote
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Providers (AWS, Ceph, Dreamhost, IBM COS, Minio)
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Dropbox
   \ "dropbox"
 9 / Encrypt/Decrypt a remote
   \ "crypt"
10 / FTP Connection
   \ "ftp"
11 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
12 / Google Drive
   \ "drive"
13 / Hubic
   \ "hubic"
14 / JottaCloud
   \ "jottacloud"
15 / Local Disk
   \ "local"
16 / Mega
   \ "mega"
17 / Microsoft Azure Blob Storage
   \ "azureblob"
18 / Microsoft OneDrive
   \ "onedrive"
19 / OpenDrive
   \ "opendrive"
20 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
21 / Pcloud
   \ "pcloud"
22 / QingCloud Object Storage
   \ "qingstor"
23 / SSH/SFTP Connection
   \ "sftp"
24 / Webdav
   \ "webdav"
25 / Yandex Disk
   \ "yandex"
26 / http Connection
   \ "http"
Storage> 12   #根据自己要添加的硬盘类型选择
** See help for drive backend at: https://rclone.org/drive/ **

谷歌云盘

两种的挂载方式不一样,这里就分开写,按需求选择阅读

跳过client的选项,并且给Rclone全局管理

Google Application Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>      #略过不填,直接回车
Google Application Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>      #略过不填
Scope that rclone should use when requesting access from drive.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / Full access all files, excluding Application Data Folder.
   \ "drive"
 2 / Read-only access to file metadata and file contents.
   \ "drive.readonly"
   / Access to files created by rclone only.
 3 | These are visible in the drive website.
   | File authorization is revoked when the user deauthorizes the app.
   \ "drive.file"
   / Allows read and write access to the Application Data folder.
 4 | This is not visible in the drive website.
   \ "drive.appfolder"
   / Allows read-only access to file metadata but
 5 | does not allow any access to read or download file content.
   \ "drive.metadata.readonly"
scope> 1     #选择权限,1为全局管理

接下来两项也不填
跳过高级选项和自动设置

ID of the root folder
Leave blank normally.
Fill in to access "Computers" folders. (see docs).
Enter a string value. Press Enter for the default ("").
root_folder_id>      #留空不用填
Service Account Credentials JSON file path 
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default ("").
service_account_file>      #不用填
Edit advanced config? (y/n)
y) Yes
n) No
y/n> n     #不编辑高级设置
Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine or Y didn't work
y) Yes
n) No
y/n> n     #不自动设置

这时会给你一个链接,复制到浏览器打开,登陆你想要挂载的账号即可。登陆后会给你一串Token,复制到命令行即可

If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=202264815644.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=********************************  #复制此处链接到浏览器打开
Log in and authorize rclone for access
Enter verification code> 4/1w**********************-keP-8j5T-B*************  #输入密钥
Configure this as a team drive?
y) Yes
n) No
y/n> n     #不挂载团队硬盘

确认后就成功挂载

--------------------
[googledrive]
type = drive
scope = drive
token = {"access_token":"ya29.G**********************************************************************************","token_type":"Bearer","refresh_token":"1/if9***************************5Mwu7dO-dMxq745g","expiry":"2019-01-19T09:32:31.189404582-05:00"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y   #确认
Current remotes:

Name                 Type
====                 ====
googledrive          drive

OneDrive

前面这几个步骤跟GoogleDrive一样

Microsoft App Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>          #不填
Microsoft App Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>        #不填
Edit advanced config? (y/n)
y) Yes
n) No
y/n> n     #选n
Remote config
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

接下来,我们需要下载Windows的Rclone


选择对应版本下载并解压,然后将文件放入C:\Users\用户名。然后打开CMD,执行下面的命令

rclone authorize "onedrive"

这时会自动打开你的浏览器,登陆你的OneDrive账号即可
成功后浏览器会显示sucess,CMD窗口会有一串Token


{"access_token":"****"}到日期那一行完整地整段复制下来。例如:

{"access_token":"eyJ0eXAiOiJKV1QiLCJub25jZSI6IkFRQUJBQUFBQUFDRWZleFh4amFtUWIzT2VHUTRHdWd2em5rNGtBN284R2R4X21QbEt6YV********************************************************************************************************************************************************************************************************************************************************************************************************190Y2R0IjoxNTM4MDE4NzYxfQ.FD-g0WLV12r
-Ak6lxedpYDPsGt_LF7qzIiE3CJNHs5w5vbLosbL9-cfcT0dxRIAOIbiCTw4_cS_6jEHbIQev6zB6eDMsSjzL7x8Md-j6omgy7bhAVfY4AO_iLu2je_JQq6FBhpvSBvLQRSuIuXX4bEDJ-pCBAFFKpgpWRzNH90iN4KiHEJeKwBT-i8x3R87g2bXHwCRFTPBVvi04gcADXKrwam2JZClW3tO6VbjipEg6E1fcvQEBeGJjOVjn4DK7y_7VV5uG3kRUnUvdVRRww_z537a4HToIZh1nrp7Rr-hSHJEkrNOTPLchjgIYenbd_9QNfLJPPdiwLKt1VK-Ykg","token_type":"Bearer","refresh_token":"OAQABAAAAAACEfexXxjamQb3OeGQ4GugvGPBfOhJu5kfwj**************************************************************************************************************************************************************************************************************************************************************-klf_AWWbqj7PdByqu5QYDVJrGP0FbTd_sbHgA3lcgAA","expiry":
"2019-01-19T23:27:37.5265257+08:00"}

回到SSH,把你复制的Token复制到result中

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>           #粘贴你获得的Token

如果失败,会直接退出Rclone,请确认你的Token是否有按照我写的规则填写正确
成功则如下,输入1即可

Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Type in driveID
   \ "driveid"
 4 / Type in SiteID
   \ "siteid"
 5 / Search a Sharepoint site
   \ "search"
Your choice> 1     #输入1

然后会让你选择你想使用的账户的硬盘,选择你想要的即可,我只有一个,直接选择0

Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=*********************************************
Chose drive to use:> 0     #选择你想要挂载的盘

随后会给你一个链接,这个链接重定向到你的OneDrive网页版,复制到浏览器看看是不是你想要添加的即可
然后会让你确认,全选yes即可(y)

Found drive 'root' of type 'business', URL: https://***************************/Documents
Is that okay?
y) Yes
n) No
y/n> y
--------------------
[onedrive]
type = onedrive
token = {"access_token":}
drive_id = *********************************************************
drive_type = business
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

到这里,OneDrive的挂载就完成了

挂载硬盘

不管你选择了哪种硬盘,添加完毕后,我们都需要将它挂载到磁盘

#新建本地文件夹
mkdir /root/Drive
#挂载为磁盘
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

DriveName是你上面填的name,Folder为Google Drive里的文件夹,LocalFolder为VPS上你刚刚创建的文件夹
示例

rclone mount googledrive:download Drive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

这里有个坑,就是你挂载为磁盘后,他就卡住不动了,其实是已经成功挂载了。但你无法操作,这里建议利用screen在后台进行挂载

安装screen

# Centos
yum -y install screen
# ubuntu/debian
sudo apt-get install screen

新建窗口

screen -a googledrive

这样就新建了一个名为googledrive的screen窗口,在里面执行挂载硬盘的命令即可

挂载成功后,输入df -h可以查看分区情况

如需卸载磁盘,则使用以下命令

fusermount -qzu LocalFolder

常见问题FAQ

  1. 挂载硬盘后提示NOTICE: One drive root 'test': poll-interval is not supported by this remote
    解决方法:略过即可
  2. 挂载硬盘后提示
    Fatal error: failed to mount FUSE fs: fusermount: exec: "fusermount": executable file not found in $PATH
    解决方法:安装FUSE即可

    # Centos 
    yum install fuse
    # Debian/Ubuntu
    apt-get install fuse
最后修改:2022 年 08 月 25 日
如果觉得我的文章对你有用,能不能v我50参加疯狂星期四