Featured image of post linux/windows 使用 rclone 挂载 OneDrive E5

linux/windows 使用 rclone 挂载 OneDrive E5

win 配置文件: %USERPROFILE%\AppData\Roaming\rclone\rclone.conf

linux 配置文件: /root/.config/rclone/rclone.conf

0、获取 OneDrive API

  • 获取 OneDrive API
    • 1)进入:https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade
      • 如果你的是 E5 账号,那么请用 E5 账号登录。
    • 2)点击“新注册”,名称随意,选“仅 Microsoft 个人帐户”,重定向 URI,选“WEB”,值是“http://localhost
    • 2023-01-30-rclone1
    • 3)记下这个“应用程序(客户端) ID”的值,这就是待会要填的 client_id
    • 2023-01-30-rclone2.png
    • 4)点击左边的“证书和密码”
    • 2023-01-30-rclone3.png
    • 5)点击“新客户端密码”,截至期限拉满,然后点添加。
      • 记下密码的“值”,这就是待会要填的 client_secret

1、添加权限

  • API 权限»>添加权限»>选择 Microsoft Graph»>应用程序权限,添加以下权限

    • Directory.Read.All
    • Directory.ReadWrite.All
    • Files.Read.All
    • Files.ReadWrite.All
    • Sites.Read.All
    • Sites.ReadWrite.All
    • User.Read
    • User.Read.All
    • 2023-01-30-rclone4.png
  • 然后点击“代表 XXX 授予管理员同意”

2、获取 toekn

  • 获取 token(不要开代理)(不要开代理)(不要开代理)
  • 1)下载客户端
  • 2)解压,打开 cmd 输入:.\rclone.exe authorize "onedrive",登陆,保存 token
    • 注意,是保存全部。{},包括整个括号。
# linux 安装 rclone
apt install -y fuse
curl https://rclone.org/install.sh | sudo bash
rclone config

3、配置

rclone config

No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
$ n/s/q > n


Enter name for new remote.
$ name > one

Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
.........
$ 32 / Microsoft OneDrive
   \ (onedrive)


Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a value. Press Enter to leave empty.
$ client_id > 这里填 client_ID !!!!!!!!!!!!!!!!!!!!!!!!

Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a value. Press Enter to leave empty.
$ client_secret > 这里填 client_secret !!!!!!!!!!!!

Option region.
Choose national cloud region for OneDrive.
Choose a number from below, or type in your own string value.
Press Enter for the default (global).
 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 > 1

Edit advanced config?
y) Yes
n) No (default)
$ y/n> n

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
# 如果前面没有获取 token ,想用浏览器获取则 y.
$ y/n> n

Option config_token.
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 ""
Then paste the result.
Enter a value.
$ config_token > 这里填刚刚用电脑获取到的 token

Option config_type.
Type of connection
Choose a number from below, or type in an existing string value.
Press Enter for the default (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)
$ config_type >  1

# 剩下几个一路回车就可以了

4、挂载到本地硬盘

& 代表后台运行

rclone mount name:挂载目录 挂载位置

apt-get update && apt-get install -y fuse

mkdir /webdav
mkdir /webdav/one

rclone mount one:rn /webdav/one --allow-other --vfs-cache-mode writes --allow-non-empty &

# 取消挂载
fusermount -qzu <本地路径>

5、开机自启

nano /etc/systemd/system/onedrive.service
[Unit]
Description=onedrive

[Service]
User=root
ExecStart=rclone mount one:rn /webdav/one --allow-other --vfs-cache-mode writes --allow-non-empty --vfs-cache-max-age 6h --vfs-cache-max-size 10G
ExecStop=fusermount -qzu /webdav/one
Restart=on-abort

[Install]
WantedBy=multi-user.target
systemctl daemon-reload

systemctl enable onedrive

systemctl stop onedrive
systemctl start onedrive

systemctl status onedrive
Licensed under CC BY-NC-SA 4.0
本博客已稳定运行
发表了53篇文章 · 总计28.17k字
使用 Hugo 构建
主题 StackJimmy 设计