Yes, there is a kexec
command-line tool that you can use to kexec
into a new kernel.
From an user's point of view, using kexec
is about the same as using reboot
, except it tends to be quicker since the current kernel loads the new one and starts executing it (bypassing BIOS, firmware, boot loader, etc.)
The point of logind offering idle actions such as "kexec" (or "reboot") is to help with keeping your system always up-to-date, which for kernel upgrades typically needs a reboot. The idle detection helps figure out when it would be a good time to reboot your system (hopefully at a time when it won't cause too big of a disruption) and rebooting it often (assuming it's idle frequently enough) will ensure it boots into a new kernel not too long after the package manager installs an updated one.
It's, of course, a setting not all users would agree with, so of course it's not the default setting for this option (the default is "ignore" which doesn't do anything...)
To understand what the kexec
action triggers exactly, you can start looking at systemctl kexec
, which is a parallel to systemctl reboot
. Its documentation says:
Shut down and reboot the system via kexec. This is equivalent to systemctl start kexec.target --job-mode=replace-irreversibly --no-block.
So this goes through a special kexec.target, which is typically configured to require a systemd-kexec.service, which then calls the /usr/lib/systemd/systemd-shutdown
tool with a kexec
argument (through a systemctl --force kexec
, it turns out...).
To go further, you need to look at the source code, and you'll see that systemd-shutdown kexec
will simply try to reboot using kexec -e
, with logic to fallback to a "normal" reboot if that fails.
Looking at the kexec(8) man page, you'll see kexec -e
is all that's needed to execute a kexec reboot, so that's all that systemd integrates with.
The other part that's missing is the part that loads the booting kernel into memory, the part that executes the kexec -l
so that the actual execute will work. That's another rabbit hole to follow. I suggest that as an exercise to the reader (or perhaps quite appropriate for a separate question here at U&L!)