[systemd-devel] Right way to do kexec

Marti Raudsepp marti at juffo.org
Wed Mar 21 03:24:30 PDT 2012


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. 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?

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

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?


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;
                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"


More information about the systemd-devel mailing list