國外主機測評之前寫過很多掛載 第三方存儲教程,比如Google Drive ,但是Google Drive空間不是很大,而 OneDrive 有 5T 的空間,所以準備把 OneDrive 掛載到搬瓦工的VPS上去使用。OneDrive 的掛載方法和 Google Drive 大部分是差不多的,但 OneDrive 的授權要麻煩一些。這里簡單記錄一下配置的過程。

下載安裝

使用腳本下載安裝 Rclone:

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

初始化配置

安裝完成后輸入:

rclone config

可以看到:

2021/04/14 07:14:46 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 新建配置。

name 可以隨便輸入,

然后會出現掛載的服務類型,如下:

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"

直接輸入序號,比如我掛載的是 OneDrive 就可以輸入 26 ,

client_id 可以直接回車默認,

client_secret 也可以直接回車默認,

然后會出現 OneDrive 區域選擇,如下:

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"

可以直接輸入 1 選擇全球,

然后是選擇是否進行高級配置,如下:

dit advanced config? (y/n)
y) Yes
n) No (default)

可以輸入 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

可以輸入 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:

授權碼需要在本地電腦上獲取,訪問 https://rclone.org/downloads/ 根據你的電腦系統版本下載對應的 Rclone。

下載完成后解壓,進入存放 Rclone 的目錄,以 Win10 為例,打開 Powershell ,我的 Rclone 放在 E:/下載/rclone-v1.55.0-windows-amd64 ,我可以輸入:

cd E:/下載/rclone-v1.55.0-windows-amd64

在存放 Rclone 的目錄可以看到 rclone.exe 的可執行程序,輸入:

./rclone authorize "onedrive"

瀏覽器應該會自動打開,如果瀏覽器沒有打開可以根據提示復制地址訪問。如果瀏覽器登錄了 OneDrive 的話會直接顯示授權確認信息,如果沒有登錄的話會彈出登錄頁面,登錄 OneDrive 后也會顯示授權確認信息,如下:

OneDrive授權確認信息

選擇 接受 后在本地命令行會顯示一串 JSON 格式的授權信息,復制授權信息包括首尾的 {} ,到 Linux 終端粘貼。

然后是選擇 OneDrive 的類型,如下:

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"

可以輸入 1 ,

然后會顯示找到的 OneDrive 賬戶,如下:

Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=b!b_xnJJqyBMSVPjgvhvbP8XmJ_M_dMjhzrbhnaWknnbKqNBm8MTqM3kvEtW67P

根據提示輸入序號,

這里會根據你輸入的序號查找賬戶,如下:

Found drive 'root' of type 'business', URL: https://xxx-my.sharepoint.com/personal/changbin_xxx_onmicrosoft_com/Documents
Is that okay?
y) Yes (default)
n) No

確認無誤后輸入 y ,

接著會顯示你選擇的配置信息,確認無誤后輸入 y 保存配置。

掛載

輸入:

rclone mount configName:OneDriveLocation dir --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

其中的 configName 就是配置名稱,OneDriveLocation 就是要掛載的 OneDrive 目錄,dir 就是要掛載到的本地目錄。

例如我要把一個名為 OneDrive 的配置掛載到本地的 /OneDrive 目錄,我可以這樣寫:

rclone mount OneDrive:/ /OneDrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

我這里掛載的是整個 OneDrive 網盤,所以我寫的是 OneDrive 的根目錄 / 。

掛載完成后不會顯示任何內容,可以再開一個終端,輸入 df -h 查看磁盤空間,如下:

Filesystem         Size  Used Avail Use% Mounted on
devtmpfs           1.5G     0  1.5G   0% /dev
tmpfs              1.5G     0  1.5G   0% /dev/shm
tmpfs              1.5G  153M  1.4G  11% /run
tmpfs              1.5G     0  1.5G   0% /sys/fs/cgroup
/dev/vda1           57G   26G   29G  48% /
tmpfs              301M     0  301M   0% /run/user/0
OneDrive  5.0T  1.1T  4.0T  21% /OneDrive

掛載完成后進入掛載的目錄就可以看到 OneDrive 的文件了,上傳文件可以直接拷貝到掛載目錄,下載也是直接拷貝到本地目錄。

掛載出錯

如果在掛載的時候出現了類似下面的提示:

2021/03/04 18:58:16 Fatal error: failed to mount FUSE fs: fusermount: exec: "fusermount": executable file not found in $PATH

需要安裝 fuse。

CentOS/Fedora 安裝 fuse:

yum install -y fuse

Ubuntu/Debian 安裝 fuse:

apt install -y fuse