<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:12.800000190734863px">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.</span><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">
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.</div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">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.).</div>
<div style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">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.</div>
<div style="font-family:arial,sans-serif;font-size:12.800000190734863px">Our init script activates the NixOS system and ultimately exec to systemd.</div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">initrd init -> setup some env vars and mount points -> systemd/initrd -> switch-root -> system activation script -> systemd.</div>
<div style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">Questions:</div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">
1) What are the advantages to let switch-root exec to systemd directly? Does executing it from our init is the same thing?</div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">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?</div>
<div style="font-family:arial,sans-serif;font-size:12.800000190734863px"><br></div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">Thanks.</div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">
<br></div><div style="font-family:arial,sans-serif;font-size:12.800000190734863px">Best regards,</div></div>