Systemd mount fails. Where= setting doesn’t match unit name

If I use this command :

mount -t xfs -o noatime,nodiratime,logbufs=8 -L d1 /srv/node/d1

all works correctly. But if I try to mount through the systemd mount it fails.

I’ve created a file /etc/systemd/system/mnt-d1.mount with the following content:

[Unit]
Description = Disk 1

[Mount]
What = LABEL=d1
Where = /srv/node/d1
Type = xfs
Options = noatime,nodiratime,logbufs=8

[Install]
WantedBy = multi-user.target

After that I run these commands:

systemctl daemon-reload
systemctl start mnt-d1.mount

The last one showed me:

Failed to start mnt-d1.mount: Unit mnt-d1.mount failed to load: Invalid argument.  
See system logs and 'systemctl status mnt-d1.mount' for details.

systemctl status mnt-d1.mount showed me:

May 16 18:13:52 object1 systemd[1]: Cannot add dependency job for unit mnt-d1.mount, ignoring: Unit mnt-d1.mount failed to ...ectory.
May 16 18:24:05 object1 systemd[1]: mnt-d1.mount's Where= setting doesn't match unit name. Refusing.

Please help me to mount a disk via a systemd mount unit.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The error message explains the cause:

Where= setting doesn't match unit name. Refusing.

though understanding that message requires reading several man pages.
Per systemd.mount man page (emphasize mine):

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.

The “see above” part is:

Mount units must be named after the mount point directories they
control. Example: the mount point /home/lennart must be configured in
a unit file home-lennart.mount. For details about the escaping logic
used to convert a file system path to a unit name, see
systemd.unit(5).

OK, systemd.unit man page states that:

Properly escaped paths can be generated using the systemd-escape(1)
command.

pointing to systemd-escape man page which explains how to do it:

To generate the mount unit for a path:

$ systemd-escape -p --suffix=mount "/tmp//waldi/foobar/"
tmp-waldi-foobar.mount

So, in your case, /srv/node/d1 translates to srv-node-d1.mount

Method 2

If anyone is seeing this error when trying to mount in a local directory that contains a hyphen, be careful when you address that file on your shell, my shell (bash 4) needed the slash escaped, so we are escaping the escape.
Example:

#/etc/systemd/system/mnt-myx2dlocalx2ddir.mount
[Unit]
Description=My mount

[Mount]
What=//some/remote/share
Where=/mnt/my-local-dir
Type=cifs
Options=user=nonrootuser

[Install]
WantedBy=multi-user.target

The absolute file path in this example is :
/etc/systemd/system/mnt-myx2dlocalx2ddir.mount

but to rename your file you need to do this :

mv /my/original/file /etc/systemd/system/mnt-my\x2dlocal\x2ddir.mount

and when you call systemd you need to

systemctl status /etc/systemd/system/mnt-my\x2dlocal\x2ddir.mount

Now you can mount remote shares at boot as a non-root user.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x