Troubleshooting mount unit naming

This does not work. Example here:

$ systemd-escape -p --suffix=mount "/run/media/gerd/fritz-nas"

However, if you name your file accordingly as run-media-gerd-fritz\x2dnas.mount and save it, systemd still complains:

Where= setting doesn't match unit name

Hence, all you can do is avoid dashes in the folder names under all circumstances.

Next thing I found:

This statement in the automount unit prevents it from working here. In accordance with other tutorials on the net (see Automatic mounts using systemd | Anteru's Blog or Systemd: Mount examples for cifs shares ) I removed that statement and voilà, automount worked.

The ConditionPathExists works perfectly, but you need to adapt the path to your Where= statement.

For example:

Your want to mount something to /media/fritzbox , your add to the mount file Where=/media/fritzbox . You would need to add to the automount file Where=/media/fritzbox and in the Unit section ConditionPathExists=/media/fritzbox .

No, dashes work. For example

$ cat 'media-Fritz\x2dbox.mount' 

If you received an error, either your Where statement is wrong, or you named your mount unit not correctly.

Btw., /run/media should not be used for a permanent mount, with a mount unit or a fstab entry. It should only be used for temporary mounts, like a USB stick or if you want temporary mount a partition via a file manager.

I had it this way. Even copy-pasted the path everywhere, to make sure there’s no typo.
Unfortunately, it prevented the automount unit from working. And, the other tutorials do not mention it as well - so I am not sure if it is essential.

In order to use the correct name, I even copy-pasted the name provided by systemd-escape but to no avail.
Looks like systemd does not like the handling of file names with special chars in them.
In my example, with run-media-gerd-fritz\x2dnas.mount as provided filename, names show up as follows:

$ ls -l 
-rw-r--r-- 1 root root 190 10. Sep  15:21 'run-media-gerd-fritz\x2dnas.automount'
-rw-r--r-- 1 root root 385 10. Sep  15:21 'run-media-gerd-fritz\x2dnas.mount'

I assume that systemd does not get the names correctly back from that format (at least on my rig here). Hence, I had to change fritz-nas to fritz only, to get it working.

It is not essential. It is a check to determine if the mount point is available. Usually is not a problem if you decide to use a mount point on a non volatile filesystem (like ext4, xfs, btrfs). Unfortunately you chose a volatile filesystem (tmpfs), which means the mount point is simply not available at boot.

I also believe, this is the reason you have a problem with dashes. Looks like systemd will automatically create a mount point if it contains a dash.

So, basically do not use /run for a static mount point. I will refer you to the second section of this tutorial “Structure and Content of a mount unit”.

But If I intend to use mount on demand / automount - will this work?
At least that’s where all the removable drives are mounted to, as well - so I assumed automount will work with /run/media/, too.
Please correct me if I am wrong.

Corrected - it will not work.

Please read up on the naming convention - which must match the mount point - and you cannot use /run.

An automount unit does not stand alone. It complements the mount unit when that target is a removable device like a network share.

Starting a mount unit will create the path. The automount unit should only attempt to mount the device and path specified by the mount unit - if the path exist.

Don’t assume that - it is clearly stated that /run is a volatile structure which do no persist across restart - even login.
Because you have used /run - the path don’t exist because /run is recreated on system boot and when a user logs in.

It is also clearly stated - avoid using dashes (-) or spaces in your mountpoint.

Dashes in the mountpoint will work but the unit filename must use the escaped sequence - inside the unit file you use the file system name of the mountpoint not the escaped value.

In any case - avoid using special characters in your mountpoint - use only the ascii char table - this will save you a lot of pain

Thanks a lot to everybody for your help. Indeed, it is, as always, desirable to keep things as simple as possible.
So I just set up a mnt-fritz.mount unit like this

Description=Mount Fritz NAS (/mnt/fritz)



accompanied by a corresponding mnt-fritz.automount:

Description=Auto Mount Fritz NAS (/mnt/fritz)



After enabling both of them

$ systemctl enable mnt-fritz.mount
$ systemctl enable mnt-fritz.automount

and starting mnt-fritz.automount with

$ systemctl start mnt-fritz.automount

I had access to the network share.
Looks like that’s all what is required :slight_smile:

Requires and After are not needed (and in fact explicitly discouraged) for .automount units. They should only be specified in the .mount unit.

That came to my attention a couple of days? weeks? ago and I have edited the samples accordingly.

Do not enable the mount unit - the automount unit will fail if the mount unit is enabled.

Just start the mount unit once - to create the mount point - then stop it.

I have never seen a smb option named noserverino - where did you find it?

Amongst other sources, I found that at mount.cifs und smbclient - or [Gelöst]mount des fritzbox nas und "Stale file handle" - (unfortunately, both in German).

In short, -noserverino is supposed to avoid errors mounting a network share offered by a router common in Germany (“FritzBox”). The FritzBox can provide an attached USB stick or USB harddisk as a shared drive in the home network.
When having mounted that share via CIFS on a Linux system, some people experienced errors like


In dmesg, you could observe errors like

In general, mounting shares via CIFS, errors like

were reported.
That’s why I had included that option here as well. Maybe it is not necessary anymore with newer FitzBox firmware versions, but so far, I did not notice any negative impact.

1 Like

Thanks a lot for pointing this out. Looks like at least some of the tutorials found on the net are incorrect at that point as they apparently simply have copied most of the contents of the .mount unit in the .automount unit.

That is interesting and important as well. Thanks a lot for making us aware - most of the SMB/CIFS tutorials appear to be wrong here, too.

So, as a result, it looks like the units shall look like below:

$ cat /etc/systemd/system/mnt-fritz.mount 
Description=Mount Fritz NAS (/mnt/fritz)




$ cat /etc/systemd/system/mnt-fritz.automount 
Description=Auto Mount Fritz NAS (/mnt/fritz)



If you add _netdev to the option list you can omit requires and after because they are inferred by the _nevdev option.

Cool, thank you very much once again!

I have learned a lot of stuff on mount units lately - improving the unit samples.

7 posts were split to a new topic: Cialog on the a section from Arch wiki and using gid and uid with SMB