kexec
Reboot quickly into another kernel
TLDR
Load a new kernel
Load a new kernel with current boot parameters
Execute a currently loaded kernel
Unload current kexec target kernel
SYNOPSIS
kexec [OPTIONS] --load
kexec [OPTIONS] --exec
kexec [OPTIONS] --unload
kexec [OPTIONS] --crash-load
kexec [OPTIONS] --crash-unload
PARAMETERS
--load
Loads the specified kernel image into memory for later execution.
--initrd
Specifies the initial ramdisk (initrd) to be used with the loaded kernel.
--command-line
Sets the kernel command line arguments.
--exec
Executes the loaded kernel.
--unload
Unloads the previously loaded kernel image from memory.
--crash-load
Loads a crash kernel to be used in case the main kernel crashes. This will prepare a memory region.
--append
Additional options to append to kernel arguments when loading the crashkernel. Typically contains 'crashkernel=...' information.
--crash-unload
Unloads a crashkernel which was previously loaded
-v | --verbose
Enable verbose output.
-h | --help
Display help message.
-l | --load-config=
Load kernel configuration from specified file.
-d | --delay=
Delay before executing the new kernel.
DESCRIPTION
The kexec system call provides a mechanism to boot a new kernel from the currently running kernel.
It bypasses the normal firmware-based boot process, resulting in significantly faster reboot times. This is particularly useful for situations requiring frequent reboots, such as kernel development and testing.
kexec loads the new kernel directly into memory and jumps to its entry point, skipping BIOS/UEFI initialization.
kexec-tools include user-space utilities that configure and manage the use of kexec such as loading the new kernel image and its initrd, creating the crashkernel region, etc.
It is vital that the kernel images are compatible with the system's architecture. Incorrect use can lead to system instability. The main use case is fast rebooting into different kernels. For crash dump purposes, the crashkernel region needs to be pre-allocated using the kernel command line. When a kernel panic happens, the memory range reserved for the crash kernel is preserved, allowing a secondary kernel to boot and save the memory image of the crashed system (vmcore).
CAVEATS
Incorrect use of kexec can lead to system instability or data loss. Ensure that the kernel image and initrd are compatible with the system's architecture and hardware.
Root privileges are required to use kexec.
CRASH KERNEL
The crash kernel feature with kexec enables a system to automatically boot into a separate kernel in the event of a kernel panic. This allows for the capture of a crash dump, which can be used to diagnose the cause of the panic. To enable this feature, a memory region must be reserved for the crash kernel during the initial boot process using the crashkernel= command-line parameter. kexec --crash-load prepares the memory region for the crashkernel. The crashkernel's purpose is to dump the ram of the crashed kernel to allow debugging.
CONFIGURATION FILE
The kexec command can load settings from a file using the --load-config flag. This allows to load kernel, initrd, and commandline arguments, simplifying complex kexec calls.
HISTORY
The kexec system call was introduced into the Linux kernel to provide a faster mechanism for rebooting systems, especially for kernel development and testing. The kexec-tools package was developed to provide user-space utilities for loading and executing kernels with kexec.