Debian Codegraph @

upstream/debian-unstable/man2/kexec_load.2

raw
1 .\" Copyright 2010, Intel Corp.
2 .\" Copyright 2014, Vivek Goyal <[email protected]>
3 .\" Copyright 2015, Michael Kerrisk <[email protected]>
4 .\" Copyright, the authors of the Linux man-pages project
5 .\"
6 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .\"
8 .TH kexec_load 2 2026-02-08 "Linux man-pages 6.18"
9 .SH NAME
10 kexec_load, kexec_file_load \- load a new kernel for later execution
11 .SH LIBRARY
12 Standard C library
13 .RI ( libc ,\~ \-lc )
14 .SH SYNOPSIS
15 .nf
16 .BR "#include <linux/kexec.h>" " /* Definition of " KEXEC_* " constants */"
17 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
18 .B #include <unistd.h>
19 .P
20 .BI "long syscall(SYS_kexec_load, unsigned long " entry ,
21 .BI " unsigned long " nr_segments ,
22 .BI " struct kexec_segment " segments [ nr_segments ],
23 .BI " unsigned long " flags );
24 .BI "long syscall(SYS_kexec_file_load, int " kernel_fd ", int " initrd_fd ,
25 .BI " unsigned long " cmdline_len ", const char " cmdline [ cmdline_len ],
26 .BI " unsigned long " flags );
27 .fi
28 .P
29 .IR Note :
30 glibc provides no wrappers for these system calls,
31 necessitating the use of
32 .BR syscall (2).
33 .SH DESCRIPTION
34 The
35 .BR kexec_load ()
36 system call loads a new kernel that can be executed later by
37 .BR reboot (2).
38 .P
39 The
40 .I flags
41 argument is a bit mask that controls the operation of the call.
42 The following values can be specified in
43 .IR flags :
44 .TP
45 .BR KEXEC_ON_CRASH " (since Linux 2.6.13)"
46 Execute the new kernel automatically on a system crash.
47 This "crash kernel" is loaded into an area of reserved memory that
48 is determined at boot time using the
49 .I crashkernel
50 kernel command-line parameter.
51 The location of this reserved memory is exported to user space via the
52 .I /proc/iomem
53 file, in an entry labeled "Crash kernel".
54 A user-space application can parse this file and prepare a list of
55 segments (see below) that specify this reserved memory as destination.
56 If this flag is specified, the kernel checks that the
57 target segments specified in
58 .I segments
59 fall within the reserved region.
60 .TP
61 .BR KEXEC_PRESERVE_CONTEXT " (since Linux 2.6.27)"
62 Preserve the system hardware and
63 software states before executing the new kernel.
64 This could be used for system suspend.
65 This flag is available only if the kernel was configured with
66 .BR CONFIG_KEXEC_JUMP ,
67 and is effective only if
68 .I nr_segments
69 is greater than 0.
70 .P
71 The high-order bits (corresponding to the mask 0xffff0000) of
72 .I flags
73 contain the architecture of the to-be-executed kernel.
74 Specify (OR) the constant
75 .B KEXEC_ARCH_DEFAULT
76 to use the current architecture,
77 or one of the following architecture constants
78 .BR KEXEC_ARCH_386 ,
79 .BR KEXEC_ARCH_68K ,
80 .BR KEXEC_ARCH_X86_64 ,
81 .BR KEXEC_ARCH_PPC ,
82 .BR KEXEC_ARCH_PPC64 ,
83 .BR KEXEC_ARCH_IA_64 ,
84 .BR KEXEC_ARCH_ARM ,
85 .BR KEXEC_ARCH_S390 ,
86 .BR KEXEC_ARCH_SH ,
87 .BR KEXEC_ARCH_MIPS ,
88 and
89 .BR KEXEC_ARCH_MIPS_LE .
90 The architecture must be executable on the CPU of the system.
91 .P
92 The
93 .I entry
94 argument is the physical entry address in the kernel image.
95 The
96 .I nr_segments
97 argument is the number of segments pointed to by the
98 .I segments
99 pointer;
100 the kernel imposes an (arbitrary) limit of 16 on the number of segments.
101 The
102 .I segments
103 argument is an array of
104 .I kexec_segment
105 structures which define the kernel layout:
106 .P
107 .in +4n
108 .EX
109 struct kexec_segment {
110 void *buf; /* Buffer in user space */
111 size_t bufsz; /* Buffer length in user space */
112 void *mem; /* Physical address of kernel */
113 size_t memsz; /* Physical address length */
114 };
115 .EE
116 .in
117 .P
118 The kernel image defined by
119 .I segments
120 is copied from the calling process into
121 the kernel either in regular
122 memory or in reserved memory (if
123 .B KEXEC_ON_CRASH
124 is set).
125 The kernel first performs various sanity checks on the
126 information passed in
127 .IR segments .
128 If these checks pass, the kernel copies the segment data to kernel memory.
129 Each segment specified in
130 .I segments
131 is copied as follows:
132 .IP \[bu] 3
133 .I buf
134 and
135 .I bufsz
136 identify a memory region in the caller's virtual address space
137 that is the source of the copy.
138 The value in
139 .I bufsz
140 may not exceed the value in the
141 .I memsz
142 field.
143 .IP \[bu]
144 .I mem
145 and
146 .I memsz
147 specify a physical address range that is the target of the copy.
148 The values specified in both fields must be multiples of
149 the system page size.
150 .IP \[bu]
151 .I bufsz
152 bytes are copied from the source buffer to the target kernel buffer.
153 If
154 .I bufsz
155 is less than
156 .IR memsz ,
157 then the excess bytes in the kernel buffer are zeroed out.
158 .P
159 In case of a normal kexec (i.e., the
160 .B KEXEC_ON_CRASH
161 flag is not set), the segment data is loaded in any available memory
162 and is moved to the final destination at kexec reboot time (e.g., when the
163 .BR kexec (8)
164 command is executed with the
165 .I \-e
166 option).
167 .P
168 In case of kexec on panic (i.e., the
169 .B KEXEC_ON_CRASH
170 flag is set), the segment data is
171 loaded to reserved memory at the time of the call, and, after a crash,
172 the kexec mechanism simply passes control to that kernel.
173 .P
174 The
175 .BR kexec_load ()
176 system call is available only if the kernel was configured with
177 .BR CONFIG_KEXEC .
178 .SS kexec_file_load()
179 The
180 .BR kexec_file_load ()
181 system call is similar to
182 .BR kexec_load (),
183 but it takes a different set of arguments.
184 It reads the kernel to be loaded from the file referred to by
185 the file descriptor
186 .IR kernel_fd ,
187 and the initrd (initial RAM disk)
188 to be loaded from file referred to by the file descriptor
189 .IR initrd_fd .
190 The
191 .I cmdline
192 argument is a pointer to a buffer containing the command line
193 for the new kernel.
194 The
195 .I cmdline_len
196 argument specifies size of the buffer.
197 The last byte in the buffer must be a null byte (\[aq]\[rs]0\[aq]).
198 .P
199 The
200 .I flags
201 argument is a bit mask which modifies the behavior of the call.
202 The following values can be specified in
203 .IR flags :
204 .TP
205 .B KEXEC_FILE_UNLOAD
206 Unload the currently loaded kernel.
207 .TP
208 .B KEXEC_FILE_ON_CRASH
209 Load the new kernel in the memory region reserved for the crash kernel
210 (as for
211 .BR KEXEC_ON_CRASH ).
212 This kernel is booted if the currently running kernel crashes.
213 .TP
214 .B KEXEC_FILE_NO_INITRAMFS
215 Loading initrd/initramfs is optional.
216 Specify this flag if no initramfs is being loaded.
217 If this flag is set, the value passed in
218 .I initrd_fd
219 is ignored.
220 .P
221 The
222 .BR kexec_file_load ()
223 .\" See also http://lwn.net/Articles/603116/
224 system call was added to provide support for systems
225 where "kexec" loading should be restricted to
226 only kernels that are signed.
227 This system call is available only if the kernel was configured with
228 .BR CONFIG_KEXEC_FILE .
229 .SH RETURN VALUE
230 On success, these system calls returns 0.
231 On error, \-1 is returned and
232 .I errno
233 is set to indicate the error.
234 .SH ERRORS
235 .TP
236 .B EADDRNOTAVAIL
237 .\" See kernel/kexec.::sanity_check_segment_list in the 3.19 kernel source
238 The
239 .B KEXEC_ON_CRASH
240 flags was specified, but the region specified by the
241 .I mem
242 and
243 .I memsz
244 fields of one of the
245 .I segments
246 entries lies outside the range of memory reserved for the crash kernel.
247 .TP
248 .B EADDRNOTAVAIL
249 The value in a
250 .I mem
251 or
252 .I memsz
253 field in one of the
254 .I segments
255 entries is not a multiple of the system page size.
256 .TP
257 .B EBADF
258 .I kernel_fd
259 or
260 .I initrd_fd
261 is not a valid file descriptor.
262 .TP
263 .B EBUSY
264 Another crash kernel is already being loaded
265 or a crash kernel is already in use.
266 .TP
267 .B EINVAL
268 .I flags
269 is invalid.
270 .TP
271 .B EINVAL
272 The value of a
273 .I bufsz
274 field in one of the
275 .I segments
276 entries exceeds the value in the corresponding
277 .I memsz
278 field.
279 .TP
280 .B EINVAL
281 .I nr_segments
282 exceeds
283 .B KEXEC_SEGMENT_MAX
284 (16).
285 .TP
286 .B EINVAL
287 Two or more of the kernel target buffers overlap.
288 .TP
289 .B EINVAL
290 The value in
291 .I cmdline[cmdline_len\-1]
292 is not \[aq]\[rs]0\[aq].
293 .TP
294 .B EINVAL
295 The file referred to by
296 .I kernel_fd
297 or
298 .I initrd_fd
299 is empty (length zero).
300 .TP
301 .B ENOEXEC
302 .I kernel_fd
303 does not refer to an open file, or the kernel can't load this file.
304 Currently, the file must be a bzImage and contain an x86 kernel that
305 is loadable above 4\ GiB in memory (see the kernel source file
306 .IR Documentation/arch/x86/boot.rst ).
307 .TP
308 .B ENOMEM
309 Could not allocate memory.
310 .TP
311 .B EPERM
312 The caller does not have the
313 .B CAP_SYS_BOOT
314 capability.
315 .SH STANDARDS
316 Linux.
317 .SH HISTORY
318 .TP
319 .BR kexec_load ()
320 Linux 2.6.13.
321 .TP
322 .BR kexec_file_load ()
323 Linux 3.17.
324 .SH SEE ALSO
325 .BR reboot (2),
326 .BR syscall (2),
327 .BR kexec (8)
328 .P
329 The kernel source files
330 .I Documentation/kdump/kdump.rst
331 and
332 .I Documentation/admin\-guide/kernel\-parameters.txt