kexec_load(2)
π kexec_load(2) β load a whole new kernel and vibe
okay bestie, pull up a chair, because this is the kexec_load / kexec_file_load page from the Linux man-pages project, section 2 of the manual (that's the system-calls girlies π
), and it's lowkey one of the most main-character pages in the whole kernel-adjacent lineup.
heads up: these are system calls, so there's no cute libc wrapper waiting for you. It's giving "you're on your own, babes." β¨
π LIBRARY
Standard C library (libc, -lc) β yeah, the regular one π
β¨ SYNOPSIS
#include <linux/kexec.h> /* Definition of KEXEC_* constants */
#include <sys/syscall.h> /* Definition of SYS_* constants */
#include <unistd.h>
long syscall(SYS_kexec_load, unsigned long entry,
unsigned long nr_segments,
struct kexec_segment segments[nr_segments],
unsigned long flags);
long syscall(SYS_kexec_file_load, int kernel_fd, int initrd_fd,
unsigned long cmdline_len, const char cmdline[cmdline_len],
unsigned long flags);
Note: glibc provides no wrappers for these system calls, necessitating the use ofsyscall(2). no wrappers. none. zero. not a single one. you must go throughsyscall(2), periodt. π
πΈ DESCRIPTION
The kexec_load() system call loads a new kernel that can be executed later by reboot(2). Like, it's the "pack your bags now, leave later" of kernels. π§³β¨
The flags argument is a bit mask that controls the operation of the call. The following values can be specified in flags:
KEXEC_ON_CRASH(since Linux 2.6.13) β Execute the new kernel automatically on a system crash. This "crash kernel" is loaded into an area of reserved memory that is determined at boot time using thecrashkernelkernel command-line parameter. The location of this reserved memory is exported to user space via the/proc/iomemfile, in an entry labeled"Crash kernel". A user-space application can parse this file and prepare a list of segments (see below) that specify this reserved memory as destination. If this flag is specified, the kernel checks that the target segments specified insegmentsfall within the reserved region.KEXEC_PRESERVE_CONTEXT(since Linux 2.6.27) β Preserve the system hardware and software states before executing the new kernel. This could be used for system suspend. This flag is available only if the kernel was configured withCONFIG_KEXEC_JUMP, and is effective only ifnr_segmentsis greater than 0.
The high-order bits (corresponding to the mask 0xffff0000) of flags contain the architecture of the to-be-executed kernel. Specify (OR) the constant KEXEC_ARCH_DEFAULT to use the current architecture, or one of the following architecture constants KEXEC_ARCH_386, KEXEC_ARCH_68K, KEXEC_ARCH_X86_64, KEXEC_ARCH_PPC, KEXEC_ARCH_PPC64, KEXEC_ARCH_IA_64, KEXEC_ARCH_ARM, KEXEC_ARCH_S390, KEXEC_ARCH_SH, KEXEC_ARCH_MIPS, and KEXEC_ARCH_MIPS_LE. The architecture must be executable on the CPU of the system. π§ like bestie, don't hand it an ARM kernel when you're sitting on an x86 β that's not a vibe check that's a whole crash. not the good kind.
The entry argument is the physical entry address in the kernel image. The nr_segments argument is the number of segments pointed to by the segments pointer; the kernel imposes an (arbitrary) limit of 16 on the number of segments. The segments argument is an array of kexec_segment structures which define the kernel layout:
struct kexec_segment {
void *buf; /* Buffer in user space */
size_t bufsz; /* Buffer length in user space */
void *mem; /* Physical address of kernel */
size_t memsz; /* Physical address length */
};
The kernel image defined by segments is copied from the calling process into the kernel either in regular memory or in reserved memory (if KEXEC_ON_CRASH is set). The kernel first performs various sanity checks on the information passed in segments. If these checks pass, the kernel copies the segment data to kernel memory. Each segment specified in segments is copied as follows:
bufandbufszidentify a memory region in the caller's virtual address space that is the source of the copy. The value inbufszmay not exceed the value in thememszfield.memandmemszspecify a physical address range that is the target of the copy. The values specified in both fields must be multiples of the system page size.bufszbytes are copied from the source buffer to the target kernel buffer. Ifbufszis less thanmemsz, then the excess bytes in the kernel buffer are zeroed out.
In case of a normal kexec (i.e., the KEXEC_ON_CRASH flag is not set), the segment data is loaded in any available memory and is moved to the final destination at kexec reboot time (e.g., when the kexec(8) command is executed with the -e option).
In case of kexec on panic (i.e., the KEXEC_ON_CRASH flag is set), the segment data is loaded to reserved memory at the time of the call, and, after a crash, the kexec mechanism simply passes control to that kernel.
The kexec_load() system call is available only if the kernel was configured with CONFIG_KEXEC.
π¦ kexec_file_load()
The kexec_file_load() system call is similar to kexec_load(), but it takes a different set of arguments. It reads the kernel to be loaded from the file referred to by the file descriptor kernel_fd, and the initrd (initial RAM disk) to be loaded from file referred to by the file descriptor initrd_fd. The cmdline argument is a pointer to a buffer containing the command line for the new kernel. The cmdline_len argument specifies size of the buffer. The last byte in the buffer must be a null byte ('\0'). π please, do not forget the null byte, she will absolutely notice.
The flags argument is a bit mask which modifies the behavior of the call. The following values can be specified in flags:
KEXEC_FILE_UNLOADβ Unload the currently loaded kernel.KEXEC_FILE_ON_CRASHβ Load the new kernel in the memory region reserved for the crash kernel (as forKEXEC_ON_CRASH). This kernel is booted if the currently running kernel crashes.KEXEC_FILE_NO_INITRAMFSβ Loading initrd/initramfs is optional. Specify this flag if no initramfs is being loaded. If this flag is set, the value passed ininitrd_fdis ignored.
The kexec_file_load() system call was added to provide support for systems where "kexec" loading should be restricted to only kernels that are signed. This system call is available only if the kernel was configured with CONFIG_KEXEC_FILE.
π«Ά RETURN VALUE
On success, these system calls returns 0. On error, -1 is returned and errno is set to indicate the error. classic. iconic. the standard "zero or spilled tea" situation. π
π ERRORS
EADDRNOTAVAILβ TheKEXEC_ON_CRASHflags was specified, but the region specified by thememandmemszfields of one of thesegmentsentries lies outside the range of memory reserved for the crash kernel.EADDRNOTAVAILβ The value in amemormemszfield in one of thesegmentsentries is not a multiple of the system page size.EBADFβkernel_fdorinitrd_fdis not a valid file descriptor.EBUSYβ Another crash kernel is already being loaded or a crash kernel is already in use.EINVALβflagsis invalid.EINVALβ The value of abufszfield in one of thesegmentsentries exceeds the value in the correspondingmemszfield.EINVALβnr_segmentsexceedsKEXEC_SEGMENT_MAX(16).EINVALβ Two or more of the kernel target buffers overlap.EINVALβ The value incmdline[cmdline_len-1]is not'\0'.EINVALβ The file referred to bykernel_fdorinitrd_fdis empty (length zero).ENOEXECβkernel_fddoes not refer to an open file, or the kernel can't load this file. Currently, the file must be a bzImage and contain an x86 kernel that is loadable above 4 GiB in memory (see the kernel source fileDocumentation/arch/x86/boot.rst).ENOMEMβ Could not allocate memory.EPERMβ The caller does not have theCAP_SYS_BOOTcapability.
yes, EADDRNOTAVAIL shows up twice. that's not a typo, that's just the lore. π
π STANDARDS
Linux. (we been knew π)
β HISTORY
kexec_load()β Linux 2.6.13.kexec_file_load()β Linux 3.17.
π SEE ALSO
reboot(2), syscall(2), kexec(8)
The kernel source files Documentation/kdump/kdump.rst and Documentation/admin-guide/kernel-parameters.txt
and that's the whole page, bestie!! this one came from Linux man-pages 6.20, dated 2026-02-08, and it's the kexec_load(2) entry, so go forth and load that kernel responsibly β no cap, CAP_SYS_BOOT is literally in the requirement list so like, don't be weird about it. stay hydrated, mwah πβ¨πΈ
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2010, Intel Corp
- Copyright 2014, Vivek Goyal <vgoyal@redhat.com>
- Copyright 2015, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms