banner
xingli

xingli

猫娘爱好者

onedrive雲端硬碟掛載

Onedrive 網盤掛載到 linux 系統#

1. 獲取 Token#

在 Windows 電腦上下載 Rclone,下載地址:https://rclone.org/downloads/ ,然後解壓,使用 cmd 進入解壓後的文件夾

rclone.exe authorize  "onedrive"

然後會跳轉到瀏覽器的登錄頁面,輸入帳號密碼登錄成功後 cmd 命令框就會返回你的 token
框起來的就是要複製保存的,後期會用

2.Linux 安裝 onedrive#

官方提供的腳本

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

image

3. 配置#

安裝好之後輸入:

rclone config

會看到:

2022/04/27 09:01:17  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 新建配置。
name 可以隨便輸入,
然後會出現掛載的服務類型,如下:

Option Storage.
Type of  storage  to  configure.
Choose a  number  from  below,  or  type  in  your  own  value.
1 /  1Fichier
\ (fichier)
2 /  Akamai  NetStorage
\ (netstorage)
3 /  Alias  for  an  existing  remote
\ (alias)
4 /  Amazon  Drive
\ (amazon cloud  drive)
5 /  Amazon  S3  Compliant  Storage  Providers  including  AWS,  Alibaba,  Ceph,  Digital  Ocean,  Dreamhost,  IBM  COS,  Lyve  Cloud,  Minio,  RackCorp,  SeaweedFS,  and  Tencent  COS
\ (s3)
6 /  Backblaze  B2
\ (b2)
7 /  Better  checksums  for  other  remotes
\ (hasher)
8 /  Box
\ (box)
9 /  Cache  a  remote
\ (cache)
10 /  Citrix  Sharefile
\ (sharefile)
11 /  Compress  a  remote
\ (compress)
12 /  Dropbox
\ (dropbox)
13 /  Encrypt/Decrypt  a  remote
\ (crypt)
14 /  Enterprise  File  Fabric
\ (filefabric)
15 /  FTP  Connection
\ (ftp)
16 /  Google  Cloud  Storage (this is  not  Google  Drive)
\ (google cloud  storage)
17 /  Google  Drive
\ (drive)
18 /  Google  Photos
\ (google photos)
19 /  Hadoop  distributed  file  system
\ (hdfs)
20 /  Hubic
\ (hubic)
21 /  In  memory  object  storage  system.
\ (memory)
22 /  Jottacloud
\ (jottacloud)
23 /  Koofr,  Digi  Storage  and  other  Koofr-compatible  storage  providers
\ (koofr)
24 /  Local  Disk
\ (local)
25 /  Mail.ru  Cloud
\ (mailru)
26 /  Mega
\ (mega)
27 /  Microsoft  Azure  Blob  Storage
\ (azureblob)
28 /  Microsoft  OneDrive
\ (onedrive)
29 /  OpenDrive
\ (opendrive)
30 /  OpenStack  Swift (Rackspace Cloud  Files,  Memset  Memstore,  OVH)
\ (swift)
31 /  Pcloud
\ (pcloud)
32 /  Put.io
\ (putio)
33 /  QingCloud  Object  Storage
\ (qingstor)
34 /  SSH/SFTP  Connection
\ (sftp)
35 /  Sia  Decentralized  Cloud
\ (sia)
36 /  Storj  Decentralized  Cloud  Storage
\ (storj)
37 /  Sugarsync
\ (sugarsync)
38 /  Transparently  chunk/split  large  files
\ (chunker)
39 /  Union  merges  the  contents  of  several  upstream  fs
\ (union)
40 /  Uptobox
\ (uptobox)
41 /  Webdav
\ (webdav)
42 /  Yandex  Disk
\ (yandex)
43 /  Zoho
\ (zoho)
44 /  http  Connection
\ (http)
45 /  premiumize.me
\ (premiumizeme)
46 /  seafile
\ (seafile)
Storage>

直接輸入序號,比如我掛載的是 OneDrive 就可以輸入 28
client_id 可以直接回車默認,
client_secret 也可以直接回車默認,
然後會出現 OneDrive 區域選擇,如下:

1234567891011Choose 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 選擇全球,
然後是選擇是否進行高級配置,如下:

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

可以輸入 n
接著是自動配置選擇,如下:

123456Remote 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
這裡需要獲取授權碼:

Copy1234567891011For 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:

然後複製剛剛保存的 token 包括首尾的 {} ,到 Linux 終端粘貼。
然後是選擇 OneDrive 的類型,如下:

123456789101112131415Choose 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 帳戶,如下:

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

根據提示輸入序號,
這裡會根據你輸入的序號查找帳戶,如下:

1234Found 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 保存配置。

4. 掛載#

輸入:

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

其中的 configName 就是配置名稱,OneDriveLocation 就是要掛載的 OneDrive 目錄,dir 就是要掛載到的本地目錄。
例如我要把一個名為 myonedrive 的配置掛載到本地的 /myonedrive 目錄
沒有目錄的話先創建:mkdir myonedrive
我可以這樣寫:

nohup rclone  mount  myonedrive:/  /root/myonedrive  --vfs-cache-mode  writes  --vfs-cache-max-age  10s  --onedrive-chunk-size  100M >/dev/null 2>&1 &

我這裡掛載的是整個 OneDrive 網盤,所以我寫的是 OneDrive 的根目錄 /
掛載完成後不會顯示任何內容,可以再開一個終端,輸入 df -h 查看磁碟空間,如下:
image
成功掛載!!
有些系統可能掛載有很大延遲,等待 30s 左右再查看試試,一般不報錯就問題不大
常用指令

rclone copy  複製
rclone sync  同步  將目錄內容同步到網盤目錄
rclone move  移動  將目錄內文件移動到網盤,默認刪除路徑文件
rclone purge  刪除路徑及所有文件
rclone delete  刪除路徑所有文件但不刪除路徑
rclone mkdir  創建目錄
rclone rmdir  刪除目錄
rclone check  檢查目標文件與源文件是否匹配
rclone ls  列出指定路徑下的所有的文件以及文件大小
rclone lsl  僅列出對象的修改時間,大小和路徑
rclone lsd  僅列出目錄
載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。