1 .\" Copyright (C) 2010 Intel Corporation, Author: Andi Kleen
2 .\" and Copyright 2014, Vivek Goyal <vgoyal@redhat.com>
3 .\" and Copyright (c) 2015, Michael Kerrisk <mtk.manpages@gmail.com>
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .TH KEXEC_LOAD 2 2021-03-22 "Linux" "Linux Programmer's Manual"
9 kexec_load, kexec_file_load \- load a new kernel for later execution
12 .RI ( libc ", " \-lc )
15 .BR "#include <linux/kexec.h>" " /* Definition of " KEXEC_* " constants */"
16 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
17 .B #include <unistd.h>
19 .BI "long syscall(SYS_kexec_load, unsigned long " entry ,
20 .BI " unsigned long " nr_segments \
21 ", struct kexec_segment *" segments ,
22 .BI " unsigned long " flags );
23 .BI "long syscall(SYS_kexec_file_load, int " kernel_fd ", int " initrd_fd ,
24 .BI " unsigned long " cmdline_len ", const char *" cmdline ,
25 .BI " unsigned long " flags );
29 glibc provides no wrappers for these system calls,
30 necessitating the use of
35 system call loads a new kernel that can be executed later by
40 argument is a bit mask that controls the operation of the call.
41 The following values can be specified in
44 .BR KEXEC_ON_CRASH " (since Linux 2.6.13)"
45 Execute the new kernel automatically on a system crash.
46 This "crash kernel" is loaded into an area of reserved memory that
47 is determined at boot time using the
49 kernel command-line parameter.
50 The location of this reserved memory is exported to user space via the
52 file, in an entry labeled "Crash kernel".
53 A user-space application can parse this file and prepare a list of
54 segments (see below) that specify this reserved memory as destination.
55 If this flag is specified, the kernel checks that the
56 target segments specified in
58 fall within the reserved region.
60 .BR KEXEC_PRESERVE_CONTEXT " (since Linux 2.6.27)"
61 Preserve the system hardware and
62 software states before executing the new kernel.
63 This could be used for system suspend.
64 This flag is available only if the kernel was configured with
65 .BR CONFIG_KEXEC_JUMP ,
66 and is effective only if
70 The high-order bits (corresponding to the mask 0xffff0000) of
72 contain the architecture of the to-be-executed kernel.
73 Specify (OR) the constant
75 to use the current architecture,
76 or one of the following architecture constants
79 .BR KEXEC_ARCH_X86_64 ,
81 .BR KEXEC_ARCH_PPC64 ,
82 .BR KEXEC_ARCH_IA_64 ,
88 .BR KEXEC_ARCH_MIPS_LE .
89 The architecture must be executable on the CPU of the system.
93 argument is the physical entry address in the kernel image.
96 argument is the number of segments pointed to by the
99 the kernel imposes an (arbitrary) limit of 16 on the number of segments.
102 argument is an array of
104 structures which define the kernel layout:
108 struct kexec_segment {
109 void *buf; /* Buffer in user space */
110 size_t bufsz; /* Buffer length in user space */
111 void *mem; /* Physical address of kernel */
112 size_t memsz; /* Physical address length */
117 The kernel image defined by
119 is copied from the calling process into
120 the kernel either in regular
121 memory or in reserved memory (if
124 The kernel first performs various sanity checks on the
125 information passed in
127 If these checks pass, the kernel copies the segment data to kernel memory.
128 Each segment specified in
130 is copied as follows:
135 identify a memory region in the caller's virtual address space
136 that is the source of the copy.
139 may not exceed the value in the
146 specify a physical address range that is the target of the copy.
147 The values specified in both fields must be multiples of
148 the system page size.
151 bytes are copied from the source buffer to the target kernel buffer.
156 then the excess bytes in the kernel buffer are zeroed out.
158 In case of a normal kexec (i.e., the
160 flag is not set), the segment data is loaded in any available memory
161 and is moved to the final destination at kexec reboot time (e.g., when the
163 command is executed with the
167 In case of kexec on panic (i.e., the
169 flag is set), the segment data is
170 loaded to reserved memory at the time of the call, and, after a crash,
171 the kexec mechanism simply passes control to that kernel.
175 system call is available only if the kernel was configured with
177 .SS kexec_file_load()
179 .BR kexec_file_load ()
180 system call is similar to
182 but it takes a different set of arguments.
183 It reads the kernel to be loaded from the file referred to by
186 and the initrd (initial RAM disk)
187 to be loaded from file referred to by the file descriptor
191 argument is a pointer to a buffer containing the command line
195 argument specifies size of the buffer.
196 The last byte in the buffer must be a null byte (\(aq\e0\(aq).
200 argument is a bit mask which modifies the behavior of the call.
201 The following values can be specified in
205 Unload the currently loaded kernel.
207 .B KEXEC_FILE_ON_CRASH
208 Load the new kernel in the memory region reserved for the crash kernel
210 .BR KEXEC_ON_CRASH ).
211 This kernel is booted if the currently running kernel crashes.
213 .B KEXEC_FILE_NO_INITRAMFS
214 Loading initrd/initramfs is optional.
215 Specify this flag if no initramfs is being loaded.
216 If this flag is set, the value passed in
221 .BR kexec_file_load ()
222 .\" See also http://lwn.net/Articles/603116/
223 system call was added to provide support for systems
224 where "kexec" loading should be restricted to
225 only kernels that are signed.
226 This system call is available only if the kernel was configured with
227 .BR CONFIG_KEXEC_FILE .
229 On success, these system calls returns 0.
230 On error, \-1 is returned and
232 is set to indicate the error.
236 .\" See kernel/kexec.::sanity_check_segment_list in the 3.19 kernel source
239 flags was specified, but the region specified by the
245 entries lies outside the range of memory reserved for the crash kernel.
254 entries is not a multiple of the system page size.
260 is not a valid file descriptor.
263 Another crash kernel is already being loaded
264 or a crash kernel is already in use.
275 entries exceeds the value in the corresponding
286 Two or more of the kernel target buffers overlap.
290 .I cmdline[cmdline_len\-1]
294 The file referred to by
298 is empty (length zero).
302 does not refer to an open file, or the kernel can't load this file.
303 Currently, the file must be a bzImage and contain an x86 kernel that
304 is loadable above 4\ GiB in memory (see the kernel source file
305 .IR Documentation/x86/boot.txt ).
308 Could not allocate memory.
311 The caller does not have the
317 system call first appeared in Linux 2.6.13.
319 .BR kexec_file_load ()
320 system call first appeared in Linux 3.17.
322 These system calls are Linux-specific.
328 The kernel source files
329 .I Documentation/kdump/kdump.txt
331 .I Documentation/admin\-guide/kernel\-parameters.txt