4

The logind.conf man page says:

IdleAction=

Configures the action to take when the system is idle. Takes one of "ignore", "poweroff", "reboot", "halt", "kexec", "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate", and "lock". Defaults to "ignore".

I've not seen the kexec value explained anywhere. What exactly does kexec do here?

Is there an equivalent kexec(8) command line that it runs?

In what cases would it be useful to hot reboot into a new kernel on system idle anyway?

1 Answer 1

6

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!)

2
  • 1
    Thanks, but which kernel is chosen when systemd takes the kexec action? What is the equivalent kexec(8) command line that it would run?
    – Tom Hale
    Feb 23, 2019 at 14:03
  • Updated the question to include the trail of events of what a kexec triggers.
    – filbranden
    Feb 24, 2019 at 12:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .