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