OSDN Git Service

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