You are not logged in.

#1 2017-02-28 08:49:22

dominicm
Member
Registered: 2015-01-03
Posts: 92

Add multiple systemd dependencies with wildcards (*)

I have a fuse based mount that works fine when mounted manually or in fstab using wildcards but I can't get the same replicated with systemd without manually adding each dependency.

fstab example mount:

/mnt/disk* /mnt/virtual -fs- -options- 0 0

Translating this into native systemd unit  as below gives invalid option errors in the log and the two options with * wildcard are ignored.

[Unit]
Description = Mount mergerfs volume
Requires = mnt-disk*.mount
After = mnt-disk*.mount
# removing '.mount' doesn't work either.

[Mount]
What = /mnt/disk*
Where = /mnt/virtual
Type = -fs-
Options = -options-

[Install]
WantedBy = multi-user.target

I was unable to find any documentation about wildcards being used specifically with systemd. What is the correct way to achieve this?

Last edited by dominicm (2017-02-28 08:51:15)

Offline

#2 2017-02-28 10:26:29

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,304

Re: Add multiple systemd dependencies with wildcards (*)

I don't think this is possible in systemd; from 'man systemd.mount':

Note that mount units cannot be templated, nor is possible to add multiple names to a mount unit by creating additional symlinks to it.

And

In general, configuring mount points through /etc/fstab is the preferred approach.
See systemd-fstab-generator(8) for details about the conversion.

Offline

#3 2017-02-28 10:33:46

dominicm
Member
Registered: 2015-01-03
Posts: 92

Re: Add multiple systemd dependencies with wildcards (*)

I would have thought that the first quote applies to mounts rather than dependencies meaning that you can only mount one device per mount so it doesn't mean multiple dependencies can't be added. In fact they can it just needs to be done manually, one by one instead of using the wildcard as I am trying to do.

My other mounts are generated from fstab, could that be the reason why it fails? I doubt it as it says the option is invalid, so it would seem syntax related.

Entries in fstab are converted into native systemd mounts, is there a way to view what it generates? I don't see any mount units in /tmp/ directory.

Last edited by dominicm (2017-02-28 10:34:56)

Offline

#4 2017-02-28 22:15:17

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,304

Re: Add multiple systemd dependencies with wildcards (*)

The mount units generated by systemd from /etc/fstab are in '/run/systemd/generator'.

Why do you want to not use /etc/fstab which is said to be the preferred approach and which works for you as expected?

it says the option is invalid, so it would seem syntax related

Give the exact text in the log about the mount unit you manually created.

But I suggest you stay with the /etc/fstab approach. It seems simpler to me.

Offline

#5 2017-02-28 23:32:06

dominicm
Member
Registered: 2015-01-03
Posts: 92

Re: Add multiple systemd dependencies with wildcards (*)

At this point it's more curiosity than anything else. Generated mounts don't use Require or After options which raises the question how it handles dependencies and mount order..?

Exact errors are:

Feb 28 23:19:54 workstation systemd[1]: [/etc/systemd/system/mnt-pool.mount:3] Failed to add dependency on mnt-disk*.mount, ignoring: Invalid argument
Feb 28 23:19:54 workstation systemd[1]: [/etc/systemd/system/mnt-pool.mount:4] Failed to add dependency on mnt-disk*.mount, ignoring: Invalid argument

After some more testing Required=/mnt/disk* works fine and so does Required=mnt-disk1.mount but not Required=mnt-disk*.mount. Seeing as the disks are all mounted in fstab this is quite odd behaviour  where wildcard seems to be invalid with certain notation.

Offline

#6 2017-03-01 09:50:37

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,304

Re: Add multiple systemd dependencies with wildcards (*)

Generated mounts by systemd do use Requires or After options. For example here is my home.mount unit:

# Automatically generated by systemd-fstab-generator

[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
Before=local-fs.target
Requires=systemd-fsck@dev-disk-by\x2duuid-18e98c7e\x2dc8ae\x2d4363\x2daf41\x2dxxxxxxxxxxxx.service
After=systemd-fsck@dev-disk-by\x2duuid-18e98c7e\x2dc8ae\x2d4363\x2daf41\x2dxxxxxxxxxxxx.service

[Mount]
What=/dev/disk/by-uuid/18e98c7e-c8ae-4363-af41-xxxxxxxxxxxx
Where=/home
Type=ext4
Options=rw,relatime,data=ordered

(I partially masked the uuid)

See also 'man systemd.mount' the 'AUTOMATIC DEPENDENCIES' part, where it is written:

Mount units referring to local file systems automatically gain an After= dependency on local-fs-pre.target.


The error messages show that systemd cannot use 'mnt-disk*.mount', it doesn't intepret  * as a wildcard character but takes it literally.

You say that 'Required=/mnt/disk* works fine', I presume you mean 'Requires=/mnt/disk* works fine', but I doubt it is the case.

You also say 'the disks are all mounted in fstab', this is not clear what you mean here: if the disks are all mounted in fstab, why do you want a manually written mount unit?

If you want to continue this thread, post your /etc/fstab file and the exact mount unit you want to use.
But I don't see the point of all this, if you already have a working means of doing this.

Last edited by berbae (2017-03-01 09:57:50)

Offline

#7 2017-03-01 10:29:39

dominicm
Member
Registered: 2015-01-03
Posts: 92

Re: Add multiple systemd dependencies with wildcards (*)

You are correct, it does use After= and Requires= though not for the virtual pool mount. I would assume it's because I am mounting directories and not actual disks as that's the main difference.

I just tried again with Requires=/mnt/disk* and you are correct same errors, I must have missed them yesterday.

Most units are mounted in fstab except the virtual volume. I wanted more control over this unit particular others are standard mounts. I do not see a way to have fstab generate systemd units with required/after options. All I want to know is how (if possible) I can have multiple Required= conditions without manually listing them one by one which is somewhat impractical. Why does What=/mnt/disk* expands the wildcard but not Required=?. This is purely systemd issue. I couldn't find any documentation saying it is one way or another hence the question.

Offline

#8 2017-03-01 16:31:24

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,304

Re: Add multiple systemd dependencies with wildcards (*)

I do not see a way to have fstab generate systemd units with required/after options.

You can use the 'x-systemd.requires=' mount option in /etc/fstab which can be specified more than once:
see 'man systemd.mount' 'FSTAB' section.

But I don't think wildcard characters are permitted there. In fact I could not find any examples of wildcard usage in /etc/fstab, and I don't think systemd understands them in unit files too (I am perplexed that systemd understands 'What=/mnt/disk*' and expands it). But I may be wrong as I don't know virtual pool mounting and mounting directories and not actual disks in this context, but this seems curious to me.

Please post your /etc/fstab file and the output of the 'mount' command after a fresh boot.

Offline

#9 2017-03-01 16:53:29

dominicm
Member
Registered: 2015-01-03
Posts: 92

Re: Add multiple systemd dependencies with wildcards (*)

I notices the x.system.requires but it's uglier even than just repeating Requires= in systemd unit. I think you may be right i that neither fstab nor systemd supports wildcards. It seems like it is filesystem that handles the expansion so it's nothing to do with fstab or systemd.

Offline

#10 2017-03-01 19:34:13

Azured
Member
Registered: 2014-02-08
Posts: 9

Re: Add multiple systemd dependencies with wildcards (*)

Note that even if you do successfully make your mounts work with Systemd, you will break a lot of other standard functionality, e.g. "# mount -a" won't mount all your volumes and gvfs based disk management applications won't correctly identify your disks as automounting, as it doesn't read manually created systemd mount units.

In short, it's "expected" that your /etc/fstab contains all your auto-mount points, and it's best to leave it like that!

Offline

#11 2017-03-01 21:04:27

dominicm
Member
Registered: 2015-01-03
Posts: 92

Re: Add multiple systemd dependencies with wildcards (*)

Azured wrote:

Note that even if you do successfully make your mounts work with Systemd, you will break a lot of other standard functionality, e.g. "# mount -a" won't mount all your volumes and gvfs based disk management applications won't correctly identify your disks as automounting, as it doesn't read manually created systemd mount units.

In short, it's "expected" that your /etc/fstab contains all your auto-mount points, and it's best to leave it like that!

I never mounted all disks with systemd but haven't had any issues yet mounting just the pooled volume (different fs before now). I would stick with fstab but in this case it's cleaner to add dependencies in systemd unit than it is in fstab.

Offline

Board footer

Powered by FluxBB