[systemd-devel] ConditionPathExists vs mount unit
Lennart Poettering
lennart at poettering.net
Mon Aug 10 18:08:09 UTC 2020
On Mo, 10.08.20 19:46, Böszörményi Zoltán (zboszor at pr.hu) wrote:
> Is there a way to describe optional mounts via such Conditions* options?
No.
.mount units automatically gain dependencies on the devices they are
mounted from. Only after all dependencies are fulfilled (i.e. the
backing device showed up) the mount is executed, and as first step of
that the conditions are checked, i.e. much too late for your case.
My recommendation to you: write a generator, see
systemd.generator(7) for details. The existing
systemd-gpt-auto-generator(8) does pretty much what you want to do
already, maybe use that as inspiration. It only supports GPT disk
images however, and it auto-detects /var/ partitions only since v245.
Generators run very very early at boot and generate units and
dependencies. this is where you should genreate your var.mount
depending on the partition table. But note you have to implement that
very carefuly, and do raw disk accesses, since udev and such is not
running that early, nor do you even have the guarantee the kernel
itself noticed your extra partition or not yet. The only guarantee you
get is that the root partition was already found, everything else
might happen concurrently.
Lennart
--
Lennart Poettering, Berlin
More information about the systemd-devel
mailing list