Allen_Jeo

Allen_Jeo

在Ubuntu上使用rclone掛載OneDrive網盤

VPS 的空間太小怎麼辦,不如用 rclone 掛載 od 盤到本地,豈不妙哉?#


一、獲取 token(本地進行)#

1)win10 方法#

1. 點擊此處下載獲取 token 工具
2. 解壓,並進入rclone.exe所在的目錄
3.Shift + 右鍵點擊在此處打開 powershell
![Snipaste_2021-08-20_21-04-44.png][1]
[1]: https://z-r.cc/usr/uploads/2021/08/3425953120.png
4. 輸入

./rclone.exe authorize "onedrive"

然後按提示操作
5. 複製返回的
從 {"access_token":
複製到
"expiry":"your time"}
並保存到記事本備用
2)win7 方法
1. 點擊此處下載獲取 token 工具
2. 解壓,並進入rclone.exe所在的目錄
3. 將 rclone.exe 複製到 C:\Windows\System32
4. 輸入

rclone authorize "onedrive"
```shell
然後按提示操作
5.複製返回的
{"access_token":
複製到
"expiry":"your time"}
並保存到記事本備用

***
##二、安裝(VPS上進行)
1.安裝rclone
```shell
wget https://z-r.cc/rclone_ubuntu.sh && bash rclone_ubuntu.sh

2. 配置初始化

rclone config

然後會出現一下信息

n) New remote
s) Set configuration password
q) Quit config
n/s/q> 

輸入:n
然後會出現

name>

此處隨便輸入,這裡以 yourname來代稱
然後

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, and Tencent COS
\ "s3"
5 / Backblaze B2
\ "b2"
6 / Box
\ "box"
7 / Cache a remote
\ "cache"
8 / Citrix Sharefile
\ "sharefile"
9 / Compress a remote
\ "compress"
10 / Dropbox
\ "dropbox"
11 / Encrypt/Decrypt a remote
\ "crypt"
12 / Enterprise File Fabric
\ "filefabric"
13 / FTP Connection
\ "ftp"
14 / Google Cloud Storage (this is not Google Drive)
\ "google cloud storage"
15 / Google Drive
\ "drive"
16 / Google Photos
\ "google photos"
17 / Hadoop distributed file system
\ "hdfs"
18 / Hubic
\ "hubic"
19 / In memory object storage system.
\ "memory"
20 / Jottacloud
\ "jottacloud"
21 / Koofr
\ "koofr"
22 / Local Disk
\ "local"
23 / Mail.ru Cloud
\ "mailru"
24 / Mega
\ "mega"
25 / Microsoft Azure Blob Storage
\ "azureblob"
26 / Microsoft OneDrive
\ "onedrive"
27 / OpenDrive
\ "opendrive"
28 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
\ "swift"
29 / Pcloud
\ "pcloud"
30 / Put.io
\ "putio"
31 / QingCloud Object Storage
\ "qingstor"
32 / SSH/SFTP Connection
\ "sftp"
33 / Sugarsync
\ "sugarsync"
34 / Tardigrade Decentralized Cloud Storage
\ "tardigrade"
35 / Transparently chunk/split large files
\ "chunker"
36 / Union merges the contents of several upstream fs
\ "union"
37 / Webdav
\ "webdav"
38 / Yandex Disk
\ "yandex"
39 / Zoho
\ "zoho"
40 / http Connection
\ "http"
41 / premiumize.me
\ "premiumizeme"
42 / seafile
\ "seafile"
Storage>

這裡找到 Microsoft OneDrive
輸入:26(按自己的實際為準)

** See help for onedrive backend at: https://rclone.org/onedrive/ **

OAuth Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> 

直接回車

OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> 

直接回車

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>

這裡以自己實際為準

Edit advanced config? (y/n)
y) Yes
n) No (default)
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
y) Yes (default)
n) No
y/n>

輸入:n

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 below:
result>

這裡把之前獲取的 token 粘貼上去

Choose a number from below, or type in an existing value
1 / OneDrive Personal or Business
\ "onedrive"
2 / Root Sharepoint site
\ "sharepoint"
3 / Sharepoint site name or URL (e.g. mysite or https://contoso.sharepoint.com/sites/mysite)
\ "url"
4 / Search for a Sharepoint site
\ "search"
5 / Type in driveID (advanced)
\ "driveid"
6 / Type in SiteID (advanced)
\ "siteid"
7 / Sharepoint server-relative path (advanced, e.g. /teams/hr)
\ "path"
Your choice>

按自己情況選擇

Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=****
Chose drive to use:> 0
Found drive 'root' of type 'business', URL: ****
Is that okay?
y) Yes (default)
n) No
y/n>

輸入:y

[onedrive]
type = onedrive
region = global
token = {"access_token":"***:"2021-05-12T21:26:23.034940078-04:00"}
drive_id = b!HZQ8fVjEAkirFu8ARagwdQSJ8f6tKihCnEfvBcs_KuyXtvHlOzf1SJDUs8WRpgXq
drive_type = business
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d>

輸入:y

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 退出


## 三、掛載為磁碟

mkdir /root/OneDrive  #新建本地文件夾,路徑自己定,即下面的LocalFolder
rclone mount yourname:/ LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode writes #yourname為初始化配置填的name,/為OneDrive裡根目錄,可以為其他值,LocalFolder為VPS上的本地文件夾。

如果出現下面報錯

NOTICE: One drive root 'test': poll-interval is not supported by this remote

請忽略
掛載成功後,直接斷開連接。重新連接後,輸入 df -h 命令查看即可


## 四、卸載磁碟(如果需要)

fusermount -qzu LocalFolder

五、設置開機自啟#

1. 新建 rclone.service 文件:

command="mount yourname:/ LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode writes"

2. 寫入

#以下是一整條命令,一起複製到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

注意:ExecStart 為之前第三步時輸入的命令
3. 重載 daemon,讓新的服務文件生效:

 systemctl daemon-reload

4. 啟動:

systemctl start rclone
systemctl enable rclone

5. 其他命令:

重啟:systemctl restart rclone 
停止:systemctl stop rclone 
狀態:systemctl status rclone

本文鏈接:https://z-r.cc/2021/08/20/%E5%9C%A8Ubuntu%E4%B8%8A%E4%BD%BF%E7%94%A8rclone%E6%8C%82%E8%BD%BDOneDrive%E7%BD%91%E7%9B%98.html
转载请注明出处!

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。