使用systemd的mount模块开机挂载rclone存储

Assatur 142 2024-05-21

1、安装rclone

使用 Linux 自带的 apt/yum/dnf 等皆可, 或者使用 rclone 官方安装脚本

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

2、设置 rclone

$ which rclone
/usr/bin/rclone
$ ln -s /usr/bin/rclone /sbin/mount.rclone

3、配置挂载

使用命令rclone config配置存储,配置完成后,配置文件保存在~/.config/rclone/rclone.conf

4、配置 systemd

/etc/systemd/system目录下新建.mount文件,新文件名应与挂载目标点对应。

例如挂载点为:/mnt/alist,则文件名应为:mnt-alist.mount

按以下内容编辑文件:

[Unit]
Description=alist_webdav
After=network.target

[Mount]
Type=rclone
What=alist:
Where=/mnt/alist
Options=rw,allow_other,args2env,vfs-cache-mode=writes,config=/root/.config/rclone/rclone.conf,cache-dir=/tmp/rclone

[Install]
WantedBy=multi-user.target

而后重载配置文件并启动:

$ systemctl daemon-reload
$ systemctl start mnt-alist.mount

开机自启,自动挂载:

同路径下新增一个同名前缀,后缀automount的文件,例如mnt-alist.automount

[Unit]
After=network-online.target
Before=remote-fs.target

[Automount]
Where=/mnt/alist
TimeoutIdleSec=600

[Install]
WantedBy=multi-user.target

启动方式改为systemctl start mnt-alist.automount

$ systemctl enable mnt-mount.automount	#开机自启

成功后,automount将会通过同名mount进行挂载,无需start .mount服务。


# linux