On my machine (Arch linux), systemd-generator generates some unit files in /run/systemd/generator/
and they seem to be started somehow on boot. What is starting them?
For example, boot.mount
is generated by systemd. systemctl list-dependencies --all
shows that it is linked to local-fs.target
(which is not generated). How are they linked together? There is nothing in those two units that seems to trigger the start of boot.mount
. Well, in boot.mount
, there is Before=local-fs.target
, but that does not start a service, does it?
Best Answer
Generated unit files are not automatically activated by systemd. There's nothing special about them as far as systemd is concerned. Each individual generator has to explicitly create symbolic links that connect a generated unit to a target, so that activating the target activates the generated unit via a dependency in the normal way.
This takes advantage of the fact that not all connections between units are expressed inside the unit files. Wants and Requires dependencies can be expressed with symbolic link farms in
*.wants/
and*.requires/
subdirectories. And those symbolic link farms encompass subdirectories of/run/systemd/
amongst other things.In other words: Rather than write out a unit with
WantedBy=local-fs.target
and then have to explicitly invokesytemctl enable
to make the symbolic link (which is what enabling does), the generator short-circuits the process and makes the symbolic link itself. And it makes it in an ephemeral place, whichsystemctl enable
normally would not, thereby preventing the symbolic link from continuing to exist after the next shutdown and confusing the next startup.Specifically, you'll find on your system that
/run/systemd/generator/boot.mount
is symbolically linked from/run/systemd/generator/local-fs.target.wants/boot.mount
.systemd-fstab-generator
created this symbolic link, and it makesboot.mount
wanted bylocal-fs.target
. The generator is run early in the bootstrap before the system gets around to activatinglocal-fs.target
, which means that when it does get around to activatinglocal-fs.target
the generated dependency is there to be followed.Further reading
systemd.unit
manual page". Errata for systemd doco. Frequently Given Answers.