1kexec_load(2)                 System Calls Manual                kexec_load(2)
2
3
4

NAME

6       kexec_load, kexec_file_load - load a new kernel for later execution
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <linux/kexec.h>      /* Definition of KEXEC_* constants */
13       #include <sys/syscall.h>      /* Definition of SYS_* constants */
14       #include <unistd.h>
15
16       long syscall(SYS_kexec_load, unsigned long entry,
17                    unsigned long nr_segments, struct kexec_segment *segments,
18                    unsigned long flags);
19       long syscall(SYS_kexec_file_load, int kernel_fd, int initrd_fd,
20                    unsigned long cmdline_len, const char *cmdline,
21                    unsigned long flags);
22
23       Note:  glibc provides no wrappers for these system calls, necessitating
24       the use of syscall(2).
25

DESCRIPTION

27       The kexec_load() system call loads a new kernel that  can  be  executed
28       later by reboot(2).
29
30       The  flags  argument  is  a bit mask that controls the operation of the
31       call.  The following values can be specified in flags:
32
33       KEXEC_ON_CRASH (since Linux 2.6.13)
34              Execute the new kernel automatically on a  system  crash.   This
35              "crash kernel" is loaded into an area of reserved memory that is
36              determined at boot time using the  crashkernel  kernel  command-
37              line  parameter.   The  location  of this reserved memory is ex‐
38              ported to user space via the /proc/iomem file, in an  entry  la‐
39              beled  "Crash  kernel".  A user-space application can parse this
40              file and prepare a list of segments  (see  below)  that  specify
41              this reserved memory as destination.  If this flag is specified,
42              the kernel checks that the target segments specified in segments
43              fall within the reserved region.
44
45       KEXEC_PRESERVE_CONTEXT (since Linux 2.6.27)
46              Preserve  the system hardware and software states before execut‐
47              ing the new kernel.  This could  be  used  for  system  suspend.
48              This  flag  is  available only if the kernel was configured with
49              CONFIG_KEXEC_JUMP, and  is  effective  only  if  nr_segments  is
50              greater than 0.
51
52       The  high-order  bits  (corresponding  to the mask 0xffff0000) of flags
53       contain the architecture of the to-be-executed  kernel.   Specify  (OR)
54       the constant KEXEC_ARCH_DEFAULT to use the current architecture, or one
55       of the following architecture constants KEXEC_ARCH_386, KEXEC_ARCH_68K,
56       KEXEC_ARCH_X86_64,  KEXEC_ARCH_PPC, KEXEC_ARCH_PPC64, KEXEC_ARCH_IA_64,
57       KEXEC_ARCH_ARM, KEXEC_ARCH_S390,  KEXEC_ARCH_SH,  KEXEC_ARCH_MIPS,  and
58       KEXEC_ARCH_MIPS_LE.   The architecture must be executable on the CPU of
59       the system.
60
61       The entry argument is the physical entry address in the  kernel  image.
62       The  nr_segments  argument  is the number of segments pointed to by the
63       segments pointer; the kernel imposes an (arbitrary) limit of 16 on  the
64       number of segments.  The segments argument is an array of kexec_segment
65       structures which define the kernel layout:
66
67           struct kexec_segment {
68               void   *buf;        /* Buffer in user space */
69               size_t  bufsz;      /* Buffer length in user space */
70               void   *mem;        /* Physical address of kernel */
71               size_t  memsz;      /* Physical address length */
72           };
73
74       The kernel image defined by segments is copied from the calling process
75       into  the  kernel  either  in  regular memory or in reserved memory (if
76       KEXEC_ON_CRASH is set).   The  kernel  first  performs  various  sanity
77       checks  on  the  information passed in segments.  If these checks pass,
78       the kernel copies the segment data  to  kernel  memory.   Each  segment
79       specified in segments is copied as follows:
80
81buf  and  bufsz identify a memory region in the caller's virtual ad‐
82          dress space that is the source of the copy.  The value in bufsz  may
83          not exceed the value in the memsz field.
84
85mem and memsz specify a physical address range that is the target of
86          the copy.  The values specified in both fields must be multiples  of
87          the system page size.
88
89bufsz  bytes  are copied from the source buffer to the target kernel
90          buffer.  If bufsz is less than memsz, then the excess bytes  in  the
91          kernel buffer are zeroed out.
92
93       In  case  of a normal kexec (i.e., the KEXEC_ON_CRASH flag is not set),
94       the segment data is loaded in any available memory and is moved to  the
95       final destination at kexec reboot time (e.g., when the kexec(8) command
96       is executed with the -e option).
97
98       In case of kexec on panic (i.e., the KEXEC_ON_CRASH flag is  set),  the
99       segment data is loaded to reserved memory at the time of the call, and,
100       after a crash, the kexec mechanism simply passes control to  that  ker‐
101       nel.
102
103       The  kexec_load()  system call is available only if the kernel was con‐
104       figured with CONFIG_KEXEC.
105
106   kexec_file_load()
107       The kexec_file_load() system call is similar to  kexec_load(),  but  it
108       takes  a  different set of arguments.  It reads the kernel to be loaded
109       from the file referred to by the file  descriptor  kernel_fd,  and  the
110       initrd  (initial  RAM  disk)  to be loaded from file referred to by the
111       file descriptor initrd_fd.  The cmdline argument is a pointer to a buf‐
112       fer  containing  the  command line for the new kernel.  The cmdline_len
113       argument specifies size of the buffer.  The last  byte  in  the  buffer
114       must be a null byte ('\0').
115
116       The  flags  argument  is  a bit mask which modifies the behavior of the
117       call.  The following values can be specified in flags:
118
119       KEXEC_FILE_UNLOAD
120              Unload the currently loaded kernel.
121
122       KEXEC_FILE_ON_CRASH
123              Load the new kernel in the memory region reserved for the  crash
124              kernel  (as  for  KEXEC_ON_CRASH).  This kernel is booted if the
125              currently running kernel crashes.
126
127       KEXEC_FILE_NO_INITRAMFS
128              Loading initrd/initramfs is optional.  Specify this flag  if  no
129              initramfs  is  being  loaded.   If  this  flag is set, the value
130              passed in initrd_fd is ignored.
131
132       The kexec_file_load() system call was added to provide support for sys‐
133       tems  where  "kexec"  loading should be restricted to only kernels that
134       are signed.  This system call is available only if the kernel was  con‐
135       figured with CONFIG_KEXEC_FILE.
136

RETURN VALUE

138       On success, these system calls returns 0.  On error, -1 is returned and
139       errno is set to indicate the error.
140

ERRORS

142       EADDRNOTAVAIL
143              The KEXEC_ON_CRASH flags was specified, but the region specified
144              by  the mem and memsz fields of one of the segments entries lies
145              outside the range of memory reserved for the crash kernel.
146
147       EADDRNOTAVAIL
148              The value in a mem or memsz field in one of the segments entries
149              is not a multiple of the system page size.
150
151       EBADF  kernel_fd or initrd_fd is not a valid file descriptor.
152
153       EBUSY  Another  crash  kernel is already being loaded or a crash kernel
154              is already in use.
155
156       EINVAL flags is invalid.
157
158       EINVAL The value of a bufsz field in one of the  segments  entries  ex‐
159              ceeds the value in the corresponding memsz field.
160
161       EINVAL nr_segments exceeds KEXEC_SEGMENT_MAX (16).
162
163       EINVAL Two or more of the kernel target buffers overlap.
164
165       EINVAL The value in cmdline[cmdline_len-1] is not '\0'.
166
167       EINVAL The  file referred to by kernel_fd or initrd_fd is empty (length
168              zero).
169
170       ENOEXEC
171              kernel_fd does not refer to an open file, or  the  kernel  can't
172              load  this file.  Currently, the file must be a bzImage and con‐
173              tain an x86 kernel that is loadable above 4 GiB in  memory  (see
174              the kernel source file Documentation/x86/boot.txt).
175
176       ENOMEM Could not allocate memory.
177
178       EPERM  The caller does not have the CAP_SYS_BOOT capability.
179

STANDARDS

181       Linux.
182

HISTORY

184       kexec_load()
185              Linux 2.6.13.
186
187       kexec_file_load()
188              Linux 3.17.
189

SEE ALSO

191       reboot(2), syscall(2), kexec(8)
192
193       The  kernel  source  files Documentation/kdump/kdump.txt and Documenta‐
194       tion/admin-guide/kernel-parameters.txt
195
196
197
198Linux man-pages 6.04              2023-03-30                     kexec_load(2)
Impressum