[systemd-devel] Right way to do kexec

Lennart Poettering lennart at poettering.net
Wed Mar 21 16:33:53 PDT 2012

On Wed, 21.03.12 12:24, Marti Raudsepp (marti at juffo.org) wrote:

> Hi,
> I've been trying to figure out how to use systemd's kexec functionality right.
> When one runs "systemctl kexec", systemd simply shuts down and
> executes 'kexec -e'. For this to work, a kexec-able kernel has to be
> already loaded.
> Now, when do I load this kernel? Loading at startup means that I'm
> simply wasting the memory most of the time when I'm not rebooting. 

But I think this is the theory of how things are done. I remember some
issues with requiring continious memory which might be hard to come by
if the kernel is loaded only very late.

Might be something to discuss with the kexec folks.

> And if I upgrade the kernel, the old kernel sticks around in memory --
> but the point of rebooting is usually to load the *new* kernel?

presumably yes

> So it probably should be done just before shutdown. I created a
> 'kexec-load.service' file with:
> [Unit]
> DefaultDependencies=no
> Before=shutdown.target umount.target final.target
> [Service]
> Type=oneshot
> ExecStart=/sbin/kexec --load /boot/vmlinuz-linux
> --initrd=/boot/initramfs-linux.img --reuse-cmdline

Sounds reasoanble (under the assumption that the continuous memory thing
is not really a problem)

> And added 'Requires=kexec-load.service' to kexec.target
> Now "systemctl kexec" works, so far so good!
> Maybe we could add an empty kexec-load.service into systemd itself, so
> distros and users just need to override its ExecStart to do what they
> want and it would work automagically?

Hmm, my first reaction to this is that this belongs in kexec-tools, no?

I mean, shutdown with kexec definitely belongs into systemd, since we
need to expose this as first-level command. But the loading of the
kernel is probably better placed in kexec-tools?

We probably should get some kexec folks into the loop, what they are
intending here.

> Next, we have a chicken-and-egg kind of problem. "systemctl reboot"
> has logic like:
> if (strstr(program_invocation_short_name, "reboot")) {
>         if (kexec_loaded())
>                 arg_action = ACTION_KEXEC;
>         else
>                 arg_action = ACTION_REBOOT;
> }
> Obviously the kexec kernel won't be loaded yet at this time, so
> systemd won't actually do a kexec. Dunno what to do about this. Maybe
> drop kexec.{service,target} entirely and do this checking at
> reboot.service time? That would also deprecate the "systemctl kexec"
> command.

Uhmm, we probably should reach clarity on the first two issues before we
deal with this ;-)


Lennart Poettering - Red Hat, Inc.

More information about the systemd-devel mailing list