[systemd-devel] About systemd in initrd support

Tom Gundersen teg at jklm.no
Mon Aug 25 12:49:02 PDT 2014


On Mon, Aug 25, 2014 at 9:04 PM, Luca Bruno <lethalman88 at gmail.com> wrote:
> Thank you all for the replies. After the first answers I've ported the
> initrd to systemd (only the basic stuff, no luks, lvm, etc.) and works very
> fine.
> Except one thing, that I hoped to find in dracut but does not seem to do
> anything special about it. It just goes through switch-root it seems.
>
> As I understood it, systemctl switch-root will either run the specified
> init, or exec to the systemd in the new root. Looking a little through the
> code, it seems to do some kind of state-passing that I still have to study
> (--switched-root --deserialize etc.).
>
> Problem: in NixOS we need to run a further stage in the new root, before
> starting systemd. For example /etc is a symlink to a configuration tree
> which gets created at boot (we call it activation), and so on.
> Our init script activates the NixOS system and ultimately exec to systemd.
>
> initrd init -> setup some env vars and mount points -> systemd/initrd ->
> switch-root -> system activation script -> systemd.
>
> Questions:
> 1) What are the advantages to let switch-root exec to systemd directly? Does
> executing it from our init is the same thing?

As you already mentioned, you'd have to make sure you manage to pass
through the state correctly.

> 2) In case it's not the same thing, where is the best place to run that
> script? As a service in the new-root systemd?

I'd do any non-standard setup of the new-root from a regular service
in the initrd, that way you are not doing any magic on a running
system.

-t


More information about the systemd-devel mailing list