“kexec” is a Linux system call that enables the kernel to load and boot into another kernel, bypassing the BIOS or firmware boot loader. This allows the system to reboot directly into a new kernel without going through the process of shutting down and restarting the system.
The kexec system call is useful in several scenarios, such as:
- Developers who are testing new kernels and want to quickly switch between different versions without the need for a complete reboot.
- It can be used in situations where the system is unable to boot due to a problem with the current kernel, and a new kernel is needed to fix the issue.
The kexec system call requires the kernel and initrd (initial ramdisk) of the new kernel to be loaded into memory before executing the kexec system call. This means that the new kernel must be compatible with the current hardware and must have the necessary drivers and modules required to boot the system.
It’s important to note that kexec is not a replacement for a full reboot and is not suitable for all cases. Also, it should be used with care as it may cause data loss and system instability if not used properly.
If you encounter the below error while running the command kexec:
kexec: command not found
you may try installing the below package as per your choice of distribution:
|Debian||apt-get install kexec-tools|
|Ubuntu||apt-get install kexec-tools|
|Arch Linux||pacman -S kexec-tools|
|Kali Linux||apt-get install kexec-tools|
|CentOS||yum install kexec-tools|
|Fedora||dnf install kexec-tools|
|Raspbian||apt-get install kexec-tools|
kexec Command Examples
1. Load a new kernel:
# kexec -l path/to/kernel --initrd=path/to/initrd --command-line=arguments
2. Load a new kernel with current boot parameters:
# kexec -l path/to/kernel --initrd=path/to/initrd --reuse-cmdline
3. Execute a currently loaded kernel:
# kexec -e
4. Unload current kexec target kernel:
# kexec -u