[systemd-devel] ConditionPathExists vs mount unit

Böszörményi Zoltán zboszor at pr.hu
Wed Aug 12 14:31:18 UTC 2020


2020. 08. 10. 20:12 keltezéssel, Böszörményi Zoltán írta:
> 2020. 08. 10. 20:08 keltezéssel, Lennart Poettering írta:
>> 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.
> 
> Thanks, I will look into it.

It turned out to be working nicely.

I use libblkid and libuuid from util-linux and iniparser to implement
the desired functionality. I published the code here:

https://github.com/zboszor/systemd-optional-mount-generator

Thanks for the hints!

> 
>>
>> Lennart
>>
>> -- 
>> Lennart Poettering, Berlin
>>
> 
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel



More information about the systemd-devel mailing list