[systemd-devel] need some help understanding systemd-based initramfs

Lennart Poettering mzerqung at 0pointer.de
Mon Apr 29 09:26:39 UTC 2019

On So, 28.04.19 13:42, Ellis (contact at xogium.me) wrote:

> Hi,
> subject pretty much says it all. I am currently working on an embeded system
> and wish to use systemd in both the rootfs and the initramfs. These are both
> built via buildroot, making a full rootfs for one and a minimal rootfs for
> the other. However the documentation on how to make a proper initramfs seems
> to be very sparse, and I wish to understand this process better. Note that I
> am manually creating a cpio archive containing a minimal OS in this case, as
> buildroot can't make use of dracut or any tools to generate a proper
> initramfs. I did get quite far already, but I'm still missing one important
> thing it seems.
> I am using systemd 242 in both initramfs and full rootfs. The rootfs is a
> squashfs filesystem, hence read-only. I wish to use the new overlayfs
> support to provide a writable layer on top of the filesystem, and I do think
> I've gotten it working quite well. However I don't know if this is as a
> result of using 'systemd.volatile=overlay' on my kernel command line, or if
> I really am missing something inside my initramfs, but when the initramfs
> terminates itself and switches to the real root, obviously systemd-journald
> is getting killed and then a new one spawns in the real root, with all the
> messages from the boot to the termination of the initramfs missing if I
> consult journalctl. The journal on the real root starts off with 'Received
> sigterm from PID 1'. So, what is going on here, and how could I fix
> this ?

We'll kill every remaining process as part of the switch root
operation. We do so from the "old" systemd instance (i.e. the one
included in the inird), but we don't wait for it, and transition to
the host anyway. Since this runs asynchronously this means the
SIGTERMs might be handled and processed after the transition and in
particular we'll see the SIGCHLD for them only after the
transition. This is hence expected.

> The only documentation I found was about the boot up process in man
> bootup(7), and some kind of wiki article on freedesktop describing the
> initrd interface of systemd which seemed rather vague, located at
> https://www.freedesktop.org/wiki/Software/systemd/InitrdInterface/
> . I'd really appreciate any insight into this, and would be glad to document
> the process in the end, for other people possibly struggling with the same
> use case as I.

yes, this is only vaguely documented. And yes we should move that wiki
document into our own tree so that it appears on
https://systemd.io/. Happy to take patches for that ;-)

The best way to learn about all of this is looking at the sources of
systemd I guess, looking at dracut and asking here...


Lennart Poettering, Berlin

More information about the systemd-devel mailing list