-
Notifications
You must be signed in to change notification settings - Fork 0
/
kexec_load.html
472 lines (350 loc) · 13.3 KB
/
kexec_load.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:27:05 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>KEXEC_LOAD</title>
</head>
<body>
<h1 align="center">KEXEC_LOAD</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#VERSIONS">VERSIONS</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">kexec_load,
kexec_file_load - load a new kernel for later execution</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<linux/kexec.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>long
kexec_load(unsigned long</b> <i>entry</i><b>, unsigned
long</b> <i>nr_segments</i><b>, <br>
struct kexec_segment *</b><i>segments</i><b>, unsigned
long</b> <i>flags</i><b>);</b></p>
<p style="margin-left:11%; margin-top: 1em"><b>long
kexec_file_load(int</b> <i>kernel_fd</i><b>, int</b>
<i>initrd_fd</i><b>, <br>
unsigned long</b> <i>cmdline_len</i><b>, const char
*</b><i>cmdline</i><b>, <br>
unsigned long</b> <i>flags</i><b>);</b></p>
<p style="margin-left:11%; margin-top: 1em"><i>Note</i>:
There are no glibc wrappers for these system calls; see
NOTES.</p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">The
<b>kexec_load</b>() system call loads a new kernel that can
be executed later by <b>reboot</b>(2).</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>flags</i> argument is a bit mask that controls the
operation of the call. The following values can be specified
in <i>flags</i>: <b><br>
KEXEC_ON_CRASH</b> (since Linux 2.6.13)</p>
<p style="margin-left:22%;">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 the <i>crashkernel</i>
kernel command-line parameter. The location of this reserved
memory is exported to user space via the <i>/proc/iomem</i>
file, 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 in <i>segments</i>
fall within the reserved region.</p>
<p style="margin-left:11%;"><b>KEXEC_PRESERVE_CONTEXT</b>
(since Linux 2.6.27)</p>
<p style="margin-left:22%;">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 with
<b>CONFIG_KEXEC_JUMP</b>, and is effective only if
<i>nr_segments</i> is greater than 0.</p>
<p style="margin-left:11%; margin-top: 1em">The high-order
bits (corresponding to the mask 0xffff0000) of <i>flags</i>
contain the architecture of the to-be-executed kernel.
Specify (OR) the constant <b>KEXEC_ARCH_DEFAULT</b> to use
the current architecture, or one of the following
architecture constants <b>KEXEC_ARCH_386</b>,
<b>KEXEC_ARCH_68K</b>, <b>KEXEC_ARCH_X86_64</b>,
<b>KEXEC_ARCH_PPC</b>, <b>KEXEC_ARCH_PPC64</b>,
<b>KEXEC_ARCH_IA_64</b>, <b>KEXEC_ARCH_ARM</b>,
<b>KEXEC_ARCH_S390</b>, <b>KEXEC_ARCH_SH</b>,
<b>KEXEC_ARCH_MIPS</b>, and <b>KEXEC_ARCH_MIPS_LE</b>. The
architecture must be executable on the CPU of the
system.</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>entry</i> argument is the physical entry address in the
kernel image. The <i>nr_segments</i> argument is the number
of segments pointed to by the <i>segments</i> pointer; the
kernel imposes an (arbitrary) limit of 16 on the number of
segments. The <i>segments</i> argument is an array of
<i>kexec_segment</i> structures which define the kernel
layout:</p>
<p style="margin-left:17%; margin-top: 1em">struct
kexec_segment { <br>
void *buf; /* Buffer in user space */ <br>
size_t bufsz; /* Buffer length in user space */ <br>
void *mem; /* Physical address of kernel */ <br>
size_t memsz; /* Physical address length */ <br>
};</p>
<p style="margin-left:11%; margin-top: 1em">The kernel
image defined by <i>segments</i> is copied from the calling
process into the kernel either in regular memory or in
reserved memory (if <b>KEXEC_ON_CRASH</b> is set). The
kernel first performs various sanity checks on the
information passed in <i>segments</i>. If these checks pass,
the kernel copies the segment data to kernel memory. Each
segment specified in <i>segments</i> is copied as
follows:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p><i>buf</i> and <i>bufsz</i> identify a memory region in
the caller’s virtual address space that is the source
of the copy. The value in <i>bufsz</i> may not exceed the
value in the <i>memsz</i> field.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p><i>mem</i> and <i>memsz</i> specify 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.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p><i>bufsz</i> bytes are copied from the source buffer to
the target kernel buffer. If <i>bufsz</i> is less than
<i>memsz</i>, then the excess bytes in the kernel buffer are
zeroed out.</p></td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">In case of a
normal kexec (i.e., the <b>KEXEC_ON_CRASH</b> 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 <b>kexec</b>(8) command is executed with the
<i>-e</i> option).</p>
<p style="margin-left:11%; margin-top: 1em">In case of
kexec on panic (i.e., the <b>KEXEC_ON_CRASH</b> 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.</p>
<p style="margin-left:11%; margin-top: 1em">The
<b>kexec_load</b>() system call is available only if the
kernel was configured with <b>CONFIG_KEXEC</b>.</p>
<p style="margin-left:11%; margin-top: 1em"><b>kexec_file_load()</b>
<br>
The <b>kexec_file_load</b>() system call is similar to
<b>kexec_load</b>(), but it takes a different set of
arguments. It reads the kernel to be loaded from the file
referred to by the file descriptor <i>kernel_fd</i>, and the
initrd (initial RAM disk) to be loaded from file referred to
by the file descriptor <i>initrd_fd</i>. The <i>cmdline</i>
argument is a pointer to a buffer containing the command
line for the new kernel. The <i>cmdline_len</i> argument
specifies size of the buffer. The last byte in the buffer
must be a null byte ('\0').</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>flags</i> argument is a bit mask which modifies the
behavior of the call. The following values can be specified
in <i>flags</i>: <b><br>
KEXEC_FILE_UNLOAD</b></p>
<p style="margin-left:22%;">Unload the currently loaded
kernel.</p>
<p style="margin-left:11%;"><b>KEXEC_FILE_ON_CRASH</b></p>
<p style="margin-left:22%;">Load the new kernel in the
memory region reserved for the crash kernel (as for
<b>KEXEC_ON_CRASH</b>). This kernel is booted if the
currently running kernel crashes.</p>
<p style="margin-left:11%;"><b>KEXEC_FILE_NO_INITRAMFS</b></p>
<p style="margin-left:22%;">Loading initrd/initramfs is
optional. Specify this flag if no initramfs is being loaded.
If this flag is set, the value passed in <i>initrd_fd</i> is
ignored.</p>
<p style="margin-left:11%; margin-top: 1em">The
<b>kexec_file_load</b>() 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
<b>CONFIG_KEXEC_FILE</b>.</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">On success,
these system calls returns 0. On error, -1 is returned and
<i>errno</i> is set to indicate the error.</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>EADDRNOTAVAIL</b></p>
<p style="margin-left:22%;">The <b>KEXEC_ON_CRASH</b> flags
was specified, but the region specified by the <i>mem</i>
and <i>memsz</i> fields of one of the <i>segments</i>
entries lies outside the range of memory reserved for the
crash kernel.</p>
<p style="margin-left:11%;"><b>EADDRNOTAVAIL</b></p>
<p style="margin-left:22%;">The value in a <i>mem</i> or
<i>memsz</i> field in one of the <i>segments</i> entries is
not a multiple of the system page size.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EBADF</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>kernel_fd</i> or <i>initrd_fd</i> is not a valid file
descriptor.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EBUSY</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Another crash kernel is already being loaded or a crash
kernel is already in use.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>flags</i> is invalid.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The value of a <i>bufsz</i> field in one of the
<i>segments</i> entries exceeds the value in the
corresponding <i>memsz</i> field.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>nr_segments</i> exceeds <b>KEXEC_SEGMENT_MAX</b>
(16).</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Two or more of the kernel target buffers overlap.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The value in <i>cmdline[cmdline_len-1]</i> is not
'\0'.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The file referred to by <i>kernel_fd</i> or
<i>initrd_fd</i> is empty (length zero).</p></td></tr>
</table>
<p style="margin-left:11%;"><b>ENOEXEC</b></p>
<p style="margin-left:22%;"><i>kernel_fd</i> does 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 file <i>Documentation/x86/boot.txt</i>).</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOMEM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Could not allocate memory.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EPERM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The caller does not have the <b>CAP_SYS_BOOT</b>
capability.</p> </td></tr>
</table>
<h2>VERSIONS
<a name="VERSIONS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">The
<b>kexec_load</b>() system call first appeared in Linux
2.6.13. The <b>kexec_file_load</b>() system call first
appeared in Linux 3.17.</p>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">These system
calls are Linux-specific.</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Currently,
there is no glibc support for these system calls. Call them
using <b>syscall</b>(2).</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>reboot</b>(2),
<b>syscall</b>(2), <b>kexec</b>(8)</p>
<p style="margin-left:11%; margin-top: 1em">The kernel
source files <i>Documentation/kdump/kdump.txt</i> and
<i>Documentation/admin-guide/kernel-parameters.txt</i></p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>