Re: [systemd-devel] What is the shutdown sequence with systemd and dracut?

2022-08-15 Thread Lennart Poettering
On Sa, 13.08.22 20:46, Patrick Schleizer (patrick-mailingli...@whonix.org) 
wrote:

> 2. /lib/systemd/system-shutdown (shutdown.c) runs

Still, this binary is called systemd-shutdown, i.e. with one more 'd'.

> 4. /lib/systemd/system-shutdown performs further cleanup (similar to
> dracut, probably some functionality duplicated with dracut, includes
> kill all remaining processes, unmount remaining file systems)

I am not sure dracut has another killing spree.

> 6. /run/initramfs/shutdown (which is at time of writing only implemented
> in dracut) attempts to kill all remaining processes, unmount remaining
> file systems and calls kernel.

I think the arch initrd also implements this scheme. And IIRC they use
a neat trick, and chainload systemd-shutdown from the initrd, so that
it runs again, and does the actual final shutdown, but that time
without transitioning back into an initrd env. Hence for them PID 1 during
shutdown first transitions from the service manager into
systemd-shutdown, and then from there into into the initrd script, and
then back into systemd-shutdown. I like their approach.

Lennart

--
Lennart Poettering, Berlin


Re: [systemd-devel] What is the shutdown sequence with systemd and dracut?

2022-08-15 Thread Lennart Poettering
On Mo, 08.08.22 12:24, Patrick Schleizer (patrick-mailingli...@whonix.org) 
wrote:

> Hi!
>
> This is what I think but please correct me if I am wrong.
>
> 1. systemd runs systemd units for systemd shutdown.target
>
> 2. /lib/systemd/system-shutdown (shutdown.c) runs

I presume you mean /usr/lib/systemd/systemd-shutdown? (i.e. there's a
*d* in the file name; and the path outside of /usr/ is only done by
legacy distros, who still stick to spit /usr/ setups, which we do not
support anymore)

> 3. /lib/systemd/system-shutdown executes /run/initramfs/shutdown (which
> is dracut)

systemd-shutdown runs as PID 1 at this time, and it then chain loads
/run/initramfs/shutdown also as PID1 – if it exists. Thus, at that
moment no systemd code runs anymore, dracut is the only userspace code
remaining.

> 4. dracut shutdown.sh performs various cleanup tasks (such as kill all
> remaining processes and unmount root disk)

It should have been systemd-shutdown between steps 2 and 3 above which
should have already killed everything. But yeah, dracut is supposed to
detach the root fs.

> 5. /lib/systemd/system-shutdown runs scripts in the
> /usr/lib/systemd/system-shutdown/ folder

This is actually done before step 3 above.

> 6. /lib/systemd/system-shutdown performs further cleanup (similar to
> dracut, probably some functionality duplicated with dracut, includes
> kill all remaining processes, unmount the root risk) and eventually
> halt/reboot/poweroff/kexec.

Nah, the killing of processes it already did between steps 2 and
3. Also, as mentioned systemd-shutdown doesn't run at this time anymore.

Lennart

--
Lennart Poettering, Berlin


Re: [systemd-devel] What is the shutdown sequence with systemd and dracut?

2022-08-08 Thread Andrei Borzenkov
On 08.08.2022 15:24, Patrick Schleizer wrote:
> Hi!
> 
> This is what I think but please correct me if I am wrong.
> 
> 1. systemd runs systemd units for systemd shutdown.target
> 
> 2. /lib/systemd/system-shutdown (shutdown.c) runs
> 
> 3. /lib/systemd/system-shutdown executes /run/initramfs/shutdown (which
> is dracut)
> 
> 4. dracut shutdown.sh performs various cleanup tasks (such as kill all
> remaining processes and unmount root disk)
> 
> 5. /lib/systemd/system-shutdown runs scripts in the
> /usr/lib/systemd/system-shutdown/ folder
> 
> 6. /lib/systemd/system-shutdown performs further cleanup (similar to
> dracut, probably some functionality duplicated with dracut, includes
> kill all remaining processes, unmount the root risk) and eventually
> halt/reboot/poweroff/kexec.
> 

No. The sequence is 1, 2, 5, 6 (up to halt/reboot/poweroff/kexec). Then
if /run/initramfs/shutdown is present, systemd-shutdown executes it.
What happens later is completely outside of systemd scope, there is no
return. If this fails or /run/initramfs/shutdown is not present,
systemd-shutdown calls kernel to actually perform
halt/reboot/poweroff/kexec.

Dracut shutdown script attempts to unmount remaining filesystems and
calls kernel.