# 前言

前段时间用自己的教育邮箱白嫖了微软 1T 的 OneDrive 空间,结果在本地挂载的时候发现因为主域名无管理员(也就是学校没弄管理员账号),因此无法使用 API 挂载,导致无法正常映射到本地。

时隔多日在今天再次折腾时发现可以用 rclone 的 WebDav 挂载。

# 开始

首先安装新版本的 rclone https://rclone.org/downloads/

下载安装完成 rclone 后使用下面命令进行配置

1
rclone config

然后按照下面步骤完成配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
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> n #选择创建新的remote

Enter name for new remote.
name> test #取一个名字

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 S3 Compliant Storage Providers including AWS, Alibaba, ArvanCloud, Ceph, ChinaMobile, Cloudflare, DigitalOcean, Dreamhost, GCS, HuaweiOBS, IBMCOS, IDrive, IONOS, LyveCloud, Leviia, Liara, Linode, Minio, Netease, Petabox, RackCorp, Rclone, Scaleway, SeaweedFS, StackPath, Storj, Synology, TencentCOS, Wasabi, Qiniu and others
\ (s3)
5 / Backblaze B2
\ (b2)
6 / Better checksums for other remotes
\ (hasher)
7 / Box
\ (box)
8 / Cache a remote
\ (cache)
9 / Citrix Sharefile
\ (sharefile)
10 / Combine several remotes into one
\ (combine)
11 / Compress a remote
\ (compress)
12 / Dropbox
\ (dropbox)
13 / Encrypt/Decrypt a remote
\ (crypt)
14 / Enterprise File Fabric
\ (filefabric)
15 / FTP
\ (ftp)
16 / Google Cloud Storage (this is not Google Drive)
\ (google cloud storage)
17 / Google Drive
\ (drive)
18 / Google Photos
\ (google photos)
19 / HTTP
\ (http)
20 / Hadoop distributed file system
\ (hdfs)
21 / HiDrive
\ (hidrive)
22 / ImageKit.io
\ (imagekit)
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 / Linkbox
\ (linkbox)
28 / Local Disk
\ (local)
29 / Mail.ru Cloud
\ (mailru)
30 / Mega
\ (mega)
31 / Microsoft Azure Blob Storage
\ (azureblob)
32 / Microsoft Azure Files
\ (azurefiles)
33 / Microsoft OneDrive
\ (onedrive)
34 / OpenDrive
\ (opendrive)
35 / OpenStack Swift (Rackspace Cloud Files, Blomp Cloud Storage, Memset Memstore, OVH)
\ (swift)
36 / Oracle Cloud Infrastructure Object Storage
\ (oracleobjectstorage)
37 / Pcloud
\ (pcloud)
38 / PikPak
\ (pikpak)
39 / Proton Drive
\ (protondrive)
40 / Put.io
\ (putio)
41 / QingCloud Object Storage
\ (qingstor)
42 / Quatrix by Maytech
\ (quatrix)
43 / SMB / CIFS
\ (smb)
44 / SSH/SFTP
\ (sftp)
45 / Sia Decentralized Cloud
\ (sia)
46 / Storj Decentralized Cloud Storage
\ (storj)
47 / Sugarsync
\ (sugarsync)
48 / Transparently chunk/split large files
\ (chunker)
49 / Union merges the contents of several upstream fs
\ (union)
50 / Uptobox
\ (uptobox)
51 / WebDAV
\ (webdav)
52 / Yandex Disk
\ (yandex)
53 / Zoho
\ (zoho)
54 / premiumize.me
\ (premiumizeme)
55 / seafile
\ (seafile)
Storage> 51 #选择WebDav(是什么就输入什么数字,不一定是一样的)

Option url.
URL of http host to connect to.
E.g. https://example.com.
Enter a value.
url> https://xxx-my.sharepoint.com/personal/xxxxxxxxx_edu_cn/Documents #你的sharepoint地址,登录网页版OneDrive后在地址栏即可看到,一般为https://xxx-my.sharepoint.com/personal/xxxxxxxxx_edu_cn/_layouts/xx/onedrive.aspx?view=0,将后面没用的路径删除然后加上Documents

Option vendor.
Name of the WebDAV site/service/software you are using.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
1 / Fastmail Files
\ (fastmail)
2 / Nextcloud
\ (nextcloud)
3 / Owncloud
\ (owncloud)
4 / Sharepoint Online, authenticated by Microsoft account
\ (sharepoint)
5 / Sharepoint with NTLM authentication, usually self-hosted or on-premises
\ (sharepoint-ntlm)
6 / rclone WebDAV server to serve a remote over HTTP via the WebDAV protocol
\ (rclone)
7 / Other site/service or software
\ (other)
vendor> 4 #这里选择SharePoint Online, authenticated by Microsoft account

Option user.
User name.
In case NTLM authentication is used, the username should be in the format 'Domain\User'.
Enter a value. Press Enter to leave empty.
user> xxx@xxx.edu.cn #用户名为你的微软账号用户名

Option pass.
Password.
Choose an alternative below. Press Enter for the default (n).
y) Yes, type in my own password
g) Generate random password
n) No, leave this optional password blank (default)
y/g/n> y #这里选择已有密码
Enter the password:
password: #输入你的密码(不会显示)
Confirm the password:
password: #再次输入(不会显示)

Option bearer_token.
Bearer token instead of user/pass (e.g. a Macaroon).
Enter a value. Press Enter to leave empty.
bearer_token> #直接回车

Edit advanced config?
y) Yes
n) No (default)
y/n> #直接回车

Configuration complete.
Options:
- type: webdav
- url: https://xxx-my.sharepoint.com/personal/xxx/Documents
- vendor: sharepoint
- user: xxx@xxx.edu.cn
- pass: *** ENCRYPTED ***
Keep this "test" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> #直接回车

Current remotes:

Name Type
==== ====
test webdav

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 #退出配置交互

配置完成后我们开始挂载。

创建挂载点文件夹,例如 /mnt/onedrive

1
mkdir /mnt/onedrive

最后挂载

1
rclone mount test:/path/you/want/to/mount /mnt/onedrive --allow-other --vfs-cache-mode writes --allow-non-empty

/path/you/want/to/mount 替换为你的实际路径

tips: 如果没安装 fuse3 包可能会出现 failed to mount FUSE fs: fusermount: exec: "fusermount3": executable file not found in $PATH ,导致无法完成挂载。

# 开机挂载

创建一个 service 就行了,我习惯用 nano,你们按照自己的习惯来就行。

1
sudo nano /etc/systemd/system/onedrive.service
1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=Rclone_Onedrive
After=network-online.target

[Service]
Type=simple
ExecStart=将上面挂载的命令复制过来即可
Restart=on-abort
User=root

[Install]
WantedBy=default.target

最后就是 enable+start 了

1
2
systemctl enable onedrive
systemctl start onedrive

# 后记

听说使用这种方式挂载好像性能和稳定性不是很好?不过对于我来说能用就行。

而且好像也就 rclone 挂载成功了,Windows 自带的文件资源管理器无法通过添加网络位置来进行 WebDav 挂载,我电脑上的 RaiDrive 也无法挂载,显示 403 forbidden。