Rclone实现开机自动挂载【亲测有效】

makurasho 发布于 2024-07-30 1365 次阅读


参考了网上关于 rclone 开机自动挂载的教程,但在我的 Armbian 系统 N1 盒子上这些方法并未成功。经过一些调整,最终实现了 rclone 的开机自动挂载。本质上是在系统启动时自动执行挂载命令。

一、创建 systemd 服务文件

首先,创建一个新的 systemd 服务文件:

sudo nano /etc/systemd/system/rclone-onedrive.service

二、编辑服务文件内容

在文件中添加以下内容以配置服务:

[Unit]
Description=Mount OneDrive using rclone
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/rclone mount onedrive: /mnt/onedrive --allow-other --allow-non-empty --vfs-cache-mode writes
ExecStop=/bin/fusermount -u /mnt/onedrive
Restart=always
User=root

[Install]
WantedBy=multi-user.target

如果你的机器配置较低,建议使用以下配置并根据实际情况调整来优化性能:

[Unit]
Description=Mount OneDrive using rclone
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/rclone mount onedrive: /mnt/onedrive --allow-other --allow-non-empty --vfs-cache-mode full --vfs-cache-max-age 1h --vfs-cache-max-size 1G --vfs-cache-poll-interval 10m
ExecStop=/bin/fusermount -u /mnt/onedrive
Restart=always
User=root

[Install]
WantedBy=multi-user.target
  • /mnt/onedrive:挂载路径。
  • --vfs-cache-mode full:启用 VFS 完全缓存模式。
  • --vfs-cache-max-age 1h:设置缓存文件的最大存活时间为1小时。
  • --vfs-cache-max-size 1G:设置缓存的最大大小为1GB。
  • --vfs-cache-poll-interval 10m:设置检查缓存文件是否过期的时间间隔为10分钟。
  • User:指定运行服务的用户名。

三、重新加载 systemd 守护进程

使服务配置生效,重新加载 systemd 守护进程:

sudo systemctl daemon-reload

四、启用并启动服务

启动服务并设置为开机自动启动:

sudo systemctl start rclone-onedrive
sudo systemctl enable rclone-onedrive

通过以上步骤,你的 rclone 挂载将会在系统启动时自动完成。

参考文章

此作者没有提供个人介绍
最后更新于 2024-08-04