问题

使用 systemd 挂载文件系统时报错: Failed to start test.mount,Unit is not loaded properly: Invalid argument.

在 /etc/systemd/system 下创建了名为“test.mount”的挂载单元文件。
创建的挂载点目录为/home/test。
在“Where=”的挂载单元文件选项下,配置的挂载点是/home/test。
将挂载文件系统的设备是 /dev/xvdb1,它是在“What=”选项下定义的。
配置挂载单元文件以挂载文件系统时,失败并显示以下错误:

# systemctl start test.mount
Failed to start test.mount: Unit is not loaded properly: Invalid argument.
无法启动 test.mount:单元未正确加载:参数无效。

See system logs and 'systemctl status test.mount' for details.
# systemctl status test.mount
● test.mount - Test Mount Units
Loaded: error (Reason: Invalid argument)
Active: inactive (dead)
Where: /home/test
What: /dev/xvdb1

/var/log/messages 文件显示相同的错误:

Mar 20 15:34:19 [vm_name] systemd: test.mount's Where= setting doesn't match unit name. Refusing.
使用 systemd 挂载文件系统时报错: Failed to start test.mount
查看更多教程 https://on  itroad.com

解决方案

/etc/systemd/system 下的挂载单元的挂载单元文件名不正确。
根据 systemd.mount 手册页:

# man systemd.mount
...
Where=
Takes an absolute path of a directory of the mount point. If the mount point does not exist at the time of mounting, it is created. This string must be reflected in the unit filename. (See above.) This option is mandatory.

获取挂载点目录的绝对路径。 如果挂载时挂载点不存在,则创建。 该字符串必须反映在单元文件名中。 (见上文。)此选项是强制性的。

手册页中的以上部分显示安装单元必须以其控制的安装点目录命名。
示例:挂载点/home/john 必须配置在单元文件home-john.mount 中。
重要说明字符“/”应该像“-”一样改变

将挂载文件单元的名称更改为正确的名称: test.mount 到 home-test.mount 。
再次测试以安装安装单元。

# systemctl start home-test.mount
# mount | grep test
/dev/xvdb1 on /home/test type ext4 (rw,relatime,seclabel,data=ordered)
日期:2020-09-17 00:13:03 来源:oir作者:oir