LinuxCommandLibrary

systemctl-kexec

Perform a kexec system reboot

TLDR

Fast reboot using kexec (if kernel is pre-loaded)

$ systemctl kexec
copy

Force normal reboot even if kexec is available
$ systemctl kexec [[-f|--force]]
copy

SYNOPSIS

systemctl kexec

PARAMETERS

--no-block
    Do not wait for the operation to finish.

--dry-run
    Show what would be done without actually making any changes.

DESCRIPTION

The `systemctl kexec` command is used to reboot the Linux system using the kexec mechanism. Unlike a traditional reboot, which involves a full system shutdown, hardware reset, and then a new boot sequence, `kexec` loads a new kernel into memory and then immediately jumps to it. This process bypasses the BIOS/UEFI POST (Power-On Self-Test) and hardware initialization, leading to significantly faster reboots. It's particularly useful in environments where uptime is critical, such as servers or embedded systems, and for kernel development or testing. For `systemctl kexec` to work, the kexec kernel (and often an initramfs) must have been pre-loaded into memory by a service like `kexec-load.service` or manually via the `kexec` command. If no kernel is pre-loaded, `systemctl kexec` will fall back to a traditional reboot, similar to `systemctl reboot`.

CAVEATS

Kernel Pre-loading Required: For `systemctl kexec` to successfully perform a kexec reboot, a new kernel image and optionally an initramfs must have been previously loaded into memory using the `kexec` command or a systemd service like `kexec-load.service`. If no kernel is loaded, `systemctl kexec` will fall back to a traditional reboot.
Hardware Support: While kexec works on most modern hardware, specific BIOS/UEFI implementations or unique hardware configurations might cause issues.
Driver State: Some drivers might not properly re-initialize when jumping directly to a new kernel, potentially leading to instability or hardware detection issues, though this is less common with modern kernels.
Security Implications: Kexec allows bypassing the boot loader and firmware, which can be a security concern if not properly restricted, as it could allow an attacker to boot an arbitrary kernel without authentication. Access to `kexec` commands should be controlled.
Memory Management: Careful memory management is crucial. The loaded kernel must reside in a memory region that won't be overwritten by the currently running kernel.

PREREQUISITES FOR `KEXEC` FUNCTIONALITY

To use `systemctl kexec` effectively, ensure your kernel is compiled with `CONFIG_KEXEC=y`. Additionally, the `kexec-tools` package (or equivalent for your distribution) must be installed. This package provides the `kexec` utility and often includes the `kexec-load.service` for automatic kernel loading during system startup.

TYPICAL USAGE SCENARIO

`systemctl kexec` is frequently used in environments where minimizing downtime is critical, such as production servers requiring a kernel upgrade or security patch. Instead of a full system reboot that could take several minutes, a kexec reboot can complete in seconds, significantly reducing service interruption. It's also valuable for developers testing new kernel versions, allowing rapid iteration without waiting for lengthy boot sequences.

HISTORY

The `kexec` facility itself has been a part of the Linux kernel since version 2.6.13 (released 2005), providing a mechanism for fast reboots by bypassing firmware. Systemd, which became the default init system for many Linux distributions, integrated `kexec` functionality through the `systemctl` command. The `kexec` verb in `systemctl` provides a convenient and standardized way for system administrators to trigger a kexec reboot, leveraging the existing systemd infrastructure for service management, such as ensuring the kexec kernel is loaded before attempting the reboot via `kexec-load.service`. This integration streamlined the use of kexec within modern Linux environments, abstracting away some of the complexities of direct `kexec` command usage.

SEE ALSO

systemctl(1), kexec(8), kexec-load.service(8), reboot(8), systemd(1)

Copied to clipboard