Red Hat Training

A Red Hat training course is available for RHEL 8

19.8. 使用 systemd.automount 通过挂载单元根据需要挂载文件系统

这个步骤演示了如何在由挂载单元定义挂载点时,使用自动挂载 systemd 单元根据需要挂载文件系统。您必须为每个挂载添加自动挂载单元并启用它。

流程

  1. 创建挂载单元。例如:

    mount-point.mount
    [Mount]
    What=/dev/disk/by-uuid/f5755511-a714-44c1-a123-cfde0e4ac688
    Where=/mount/point
    Type=xfs
  2. 创建一个名称与挂载单元相同的单元文件,但扩展 .automount
  3. 打开文件并创建 [Automount] 部分。将 Where= 选项设置为挂载路径:

    [Automount]
    Where=/mount/point
    [Install]
    WantedBy=multi-user.target
  4. 加载新创建的单元,以便您的系统注册新配置:

    # systemctl daemon-reload
  5. 启用并启动自动挂载单元:

    # systemctl enable --now mount-point.automount

验证

  1. 检查 mount-point.automount 是否正在运行:

    # systemctl status mount-point.automount
  2. 检查自动挂载的目录是否有所需的内容:

    # ls /mount/point

其它资源

  • systemd.automount(5) 手册页.
  • systemd.mount(5) 手册页.
  • 管理 systemd.