1KEXEC_LOAD(2) Linux Programmer's Manual KEXEC_LOAD(2)
2
3
4
6 kexec_load, kexec_file_load - load a new kernel for later execution
7
9 #include <linux/kexec.h> /* Definition of KEXEC_* constants */
10 #include <sys/syscall.h> /* Definition of SYS_* constants */
11 #include <unistd.h>
12
13 long syscall(SYS_kexec_load, unsigned long entry,
14 unsigned long nr_segments, struct kexec_segment *segments,
15 unsigned long flags);
16 long syscall(SYS_kexec_file_load, int kernel_fd, int initrd_fd,
17 unsigned long cmdline_len, const char *cmdline,
18 unsigned long flags);
19
20 Note: glibc provides no wrappers for these system calls, necessitating
21 the use of syscall(2).
22
24 The kexec_load() system call loads a new kernel that can be executed
25 later by reboot(2).
26
27 The flags argument is a bit mask that controls the operation of the
28 call. The following values can be specified in flags:
29
30 KEXEC_ON_CRASH (since Linux 2.6.13)
31 Execute the new kernel automatically on a system crash. This
32 "crash kernel" is loaded into an area of reserved memory that is
33 determined at boot time using the crashkernel kernel command-
34 line parameter. The location of this reserved memory is ex‐
35 ported to user space via the /proc/iomem file, in an entry la‐
36 beled "Crash kernel". A user-space application can parse this
37 file and prepare a list of segments (see below) that specify
38 this reserved memory as destination. If this flag is specified,
39 the kernel checks that the target segments specified in segments
40 fall within the reserved region.
41
42 KEXEC_PRESERVE_CONTEXT (since Linux 2.6.27)
43 Preserve the system hardware and software states before execut‐
44 ing the new kernel. This could be used for system suspend.
45 This flag is available only if the kernel was configured with
46 CONFIG_KEXEC_JUMP, and is effective only if nr_segments is
47 greater than 0.
48
49 The high-order bits (corresponding to the mask 0xffff0000) of flags
50 contain the architecture of the to-be-executed kernel. Specify (OR)
51 the constant KEXEC_ARCH_DEFAULT to use the current architecture, or one
52 of the following architecture constants KEXEC_ARCH_386, KEXEC_ARCH_68K,
53 KEXEC_ARCH_X86_64, KEXEC_ARCH_PPC, KEXEC_ARCH_PPC64, KEXEC_ARCH_IA_64,
54 KEXEC_ARCH_ARM, KEXEC_ARCH_S390, KEXEC_ARCH_SH, KEXEC_ARCH_MIPS, and
55 KEXEC_ARCH_MIPS_LE. The architecture must be executable on the CPU of
56 the system.
57
58 The entry argument is the physical entry address in the kernel image.
59 The nr_segments argument is the number of segments pointed to by the
60 segments pointer; the kernel imposes an (arbitrary) limit of 16 on the
61 number of segments. The segments argument is an array of kexec_segment
62 structures which define the kernel layout:
63
64 struct kexec_segment {
65 void *buf; /* Buffer in user space */
66 size_t bufsz; /* Buffer length in user space */
67 void *mem; /* Physical address of kernel */
68 size_t memsz; /* Physical address length */
69 };
70
71 The kernel image defined by segments is copied from the calling process
72 into the kernel either in regular memory or in reserved memory (if
73 KEXEC_ON_CRASH is set). The kernel first performs various sanity
74 checks on the information passed in segments. If these checks pass,
75 the kernel copies the segment data to kernel memory. Each segment
76 specified in segments is copied as follows:
77
78 * buf and bufsz identify a memory region in the caller's virtual ad‐
79 dress space that is the source of the copy. The value in bufsz may
80 not exceed the value in the memsz field.
81
82 * mem and memsz specify a physical address range that is the target of
83 the copy. The values specified in both fields must be multiples of
84 the system page size.
85
86 * bufsz bytes are copied from the source buffer to the target kernel
87 buffer. If bufsz is less than memsz, then the excess bytes in the
88 kernel buffer are zeroed out.
89
90 In case of a normal kexec (i.e., the KEXEC_ON_CRASH flag is not set),
91 the segment data is loaded in any available memory and is moved to the
92 final destination at kexec reboot time (e.g., when the kexec(8) command
93 is executed with the -e option).
94
95 In case of kexec on panic (i.e., the KEXEC_ON_CRASH flag is set), the
96 segment data is loaded to reserved memory at the time of the call, and,
97 after a crash, the kexec mechanism simply passes control to that ker‐
98 nel.
99
100 The kexec_load() system call is available only if the kernel was con‐
101 figured with CONFIG_KEXEC.
102
103 kexec_file_load()
104 The kexec_file_load() system call is similar to kexec_load(), but it
105 takes a different set of arguments. It reads the kernel to be loaded
106 from the file referred to by the file descriptor kernel_fd, and the
107 initrd (initial RAM disk) to be loaded from file referred to by the
108 file descriptor initrd_fd. The cmdline argument is a pointer to a buf‐
109 fer containing the command line for the new kernel. The cmdline_len
110 argument specifies size of the buffer. The last byte in the buffer
111 must be a null byte ('\0').
112
113 The flags argument is a bit mask which modifies the behavior of the
114 call. The following values can be specified in flags:
115
116 KEXEC_FILE_UNLOAD
117 Unload the currently loaded kernel.
118
119 KEXEC_FILE_ON_CRASH
120 Load the new kernel in the memory region reserved for the crash
121 kernel (as for KEXEC_ON_CRASH). This kernel is booted if the
122 currently running kernel crashes.
123
124 KEXEC_FILE_NO_INITRAMFS
125 Loading initrd/initramfs is optional. Specify this flag if no
126 initramfs is being loaded. If this flag is set, the value
127 passed in initrd_fd is ignored.
128
129 The kexec_file_load() system call was added to provide support for sys‐
130 tems where "kexec" loading should be restricted to only kernels that
131 are signed. This system call is available only if the kernel was con‐
132 figured with CONFIG_KEXEC_FILE.
133
135 On success, these system calls returns 0. On error, -1 is returned and
136 errno is set to indicate the error.
137
139 EADDRNOTAVAIL
140 The KEXEC_ON_CRASH flags was specified, but the region specified
141 by the mem and memsz fields of one of the segments entries lies
142 outside the range of memory reserved for the crash kernel.
143
144 EADDRNOTAVAIL
145 The value in a mem or memsz field in one of the segments entries
146 is not a multiple of the system page size.
147
148 EBADF kernel_fd or initrd_fd is not a valid file descriptor.
149
150 EBUSY Another crash kernel is already being loaded or a crash kernel
151 is already in use.
152
153 EINVAL flags is invalid.
154
155 EINVAL The value of a bufsz field in one of the segments entries ex‐
156 ceeds the value in the corresponding memsz field.
157
158 EINVAL nr_segments exceeds KEXEC_SEGMENT_MAX (16).
159
160 EINVAL Two or more of the kernel target buffers overlap.
161
162 EINVAL The value in cmdline[cmdline_len-1] is not '\0'.
163
164 EINVAL The file referred to by kernel_fd or initrd_fd is empty (length
165 zero).
166
167 ENOEXEC
168 kernel_fd does not refer to an open file, or the kernel can't
169 load this file. Currently, the file must be a bzImage and con‐
170 tain an x86 kernel that is loadable above 4 GiB in memory (see
171 the kernel source file Documentation/x86/boot.txt).
172
173 ENOMEM Could not allocate memory.
174
175 EPERM The caller does not have the CAP_SYS_BOOT capability.
176
178 The kexec_load() system call first appeared in Linux 2.6.13. The
179 kexec_file_load() system call first appeared in Linux 3.17.
180
182 These system calls are Linux-specific.
183
185 reboot(2), syscall(2), kexec(8)
186
187 The kernel source files Documentation/kdump/kdump.txt and Documenta‐
188 tion/admin-guide/kernel-parameters.txt
189
191 This page is part of release 5.13 of the Linux man-pages project. A
192 description of the project, information about reporting bugs, and the
193 latest version of this page, can be found at
194 https://www.kernel.org/doc/man-pages/.
195
196
197
198Linux 2021-03-22 KEXEC_LOAD(2)