将网盘挂载到本地可以一定程度上解决一些文件同步/备份方面的困难 也可作为不经常访问的文件存储使用(网络io性能感人,别想着当硬盘用)

1.安装Rclone

可直接使用官方提供的安装脚本:

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

lckas4x1.png

2.创建新配置

在命令行输入:

rclone config

随后输入n创建新配置
lckasskn.png

配置名称可随意填写
lckatfzq.png

随后会询问你需要挂载的服务

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, China Mobile, Cloudflare, ArvanCloud, DigitalOcean, Dreamhost, Huawei OBS, IBM COS, IDrive e2, IONOS Cloud, Liara, Lyve Cloud, Minio, Netease, RackCorp, Scaleway, SeaweedFS, StackPath, Storj, Tencent COS, Qiniu and Wasabi
   \ (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 / Combine several remotes into one
   \ (combine)
12 / Compress a remote
   \ (compress)
13 / Dropbox
   \ (dropbox)
14 / Encrypt/Decrypt a remote
   \ (crypt)
15 / Enterprise File Fabric
   \ (filefabric)
16 / FTP
   \ (ftp)
17 / Google Cloud Storage (this is not Google Drive)
   \ (google cloud storage)
18 / Google Drive
   \ (drive)
19 / Google Photos
   \ (google photos)
20 / HTTP
   \ (http)
21 / Hadoop distributed file system
   \ (hdfs)
22 / HiDrive
   \ (hidrive)
23 / In memory object storage system.
   \ (memory)
24 / Internet Archive
   \ (internetarchive)
25 / Jottacloud
   \ (jottacloud)
26 / Koofr, Digi Storage and other Koofr-compatible storage providers
   \ (koofr)
27 / Local Disk
   \ (local)
28 / Mail.ru Cloud
   \ (mailru)
29 / Mega
   \ (mega)
30 / Microsoft Azure Blob Storage
   \ (azureblob)
31 / Microsoft OneDrive
   \ (onedrive)
32 / OpenDrive
   \ (opendrive)
33 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ (swift)
34 / Oracle Cloud Infrastructure Object Storage
   \ (oracleobjectstorage)
35 / Pcloud
   \ (pcloud)
36 / Put.io
   \ (putio)
37 / QingCloud Object Storage
   \ (qingstor)
38 / SMB / CIFS
   \ (smb)
39 / SSH/SFTP
   \ (sftp)
40 / Sia Decentralized Cloud
   \ (sia)
41 / Storj Decentralized Cloud Storage
   \ (storj)
42 / Sugarsync
   \ (sugarsync)
43 / Transparently chunk/split large files
   \ (chunker)
44 / Union merges the contents of several upstream fs
   \ (union)
45 / Uptobox
   \ (uptobox)
46 / WebDAV
   \ (webdav)
47 / Yandex Disk
   \ (yandex)
48 / Zoho
   \ (zoho)
49 / premiumize.me
   \ (premiumizeme)
50 / seafile
   \ (seafile)

因为我们需要的是OneDrive,所以这里直接输入31
client_id 和 client_secret 也可以直接回车默认
lckb2ye9.png

随后会让你选择OneDrive区域 按需选择
lckb3znx.png

1是全球 2是美国政府特供 3是德国特供 4是大陆特供

随后两个都选n
lckb6opx.png

因为我们是在远程ssh操作,所以无法使用浏览器完成验证,只能手动获取验证信息

授权码需要在本地电脑上获取,访问 https://rclone.org/downloads/ 根据你的电脑系统版本下载对应的 Rclone。

进入rclone存放文件夹,shift+鼠标右键目录内空白区域,点击在此打开cmd(或者终端一类的)
lckfpbxc.png

输入以下内容:

.\rclone.exe authorize "onedrive"

完成后本地命令行会显示一串 JSON 格式的授权信息,复制授权信息包括首尾的 {} ,到 Linux 终端粘贴。
lckh1cp9.png

选择 OneDrive 的类型:

 1 / OneDrive Personal or Business
   \ (onedrive)
 2 / Root Sharepoint site
   \ (sharepoint)
   / Sharepoint site name or URL
 3 | 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)
   / Sharepoint server-relative path (advanced)
 7 | E.g. /teams/hr
   \ (path)

这里我选择1
随后会显示查找到的账号,输入对应序号即可
最后直接回车确认

3.挂载目录

输入:

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

我挂载的是整个网盘,所以写的是的根目录 /

挂载时不会显示任何内容,可以再开一个终端,输入 df -h 查看磁盘空间,如下:

Filesystem      Size  Used Avail Use% Mounted on
udev            976M     0  976M   0% /dev
tmpfs           199M  760K  198M   1% /run
/dev/vda1        40G   18G   21G  48% /
tmpfs           992M   44K  992M   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           199M     0  199M   0% /run/user/0
OD1:      1.0T   86G  939G   9% /onedrive

挂载完成后进入挂载的目录就可以看到 OneDrive 的文件了,上传文件可以直接拷贝到挂载目录,下载也是直接拷贝到本地目录。

挂载出错
如果在挂载的时候出现了类似下面的提示:

2023/01/06 19:03:32 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

4.挂载后

因为rclone需要前台运行,因此可考虑使用screen/tmux等软件使其后台运行,或使用supervisior等,可自行研究 我选择的是使用supervisior做进程守护,很方便。

标签:无

1 条评论

  1. hlwdy hlwdy

    建议在Azure注册私用应用,rclone的默认应用Client ID用的人太多了,OneDrive有API速率限制

你的评论