20.8. 使用 systemd.automount 通过挂载单元根据需要挂载文件系统
当挂载点由挂载单元定义时,请使用自动挂载 systemd 单元来按需挂载文件系统。您必须为每个挂载添加自动挂载单元并启用它。
流程
创建挂载单元。例如:
mount-point.mount [Mount] What=/dev/disk/by-uuid/f5755511-a714-44c1-a123-cfde0e4ac688 Where=/mount/point Type=xfs
mount-point.mount [Mount] What=/dev/disk/by-uuid/f5755511-a714-44c1-a123-cfde0e4ac688 Where=/mount/point Type=xfs
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
创建一个名称与挂载单元相同的单元文件,但带有
.automount
扩展。 打开文件并创建
[Automount]
部分。将Where=
选项设置为挂载路径:[Automount] Where=/mount/point [Install] WantedBy=multi-user.target
[Automount] Where=/mount/point [Install] WantedBy=multi-user.target
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 加载新创建的单元,以便您的系统注册新配置:
systemctl daemon-reload
# systemctl daemon-reload
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 启用并启动自动挂载单元:
systemctl enable --now mount-point.automount
# systemctl enable --now mount-point.automount
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
验证
检查
mount-point.automount
是否正在运行:systemctl status mount-point.automount
# systemctl status mount-point.automount
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 检查自动挂载的目录是否有所需的内容:
ls /mount/point
# ls /mount/point
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
如需更多信息,请参阅管理 systemd