515 lines
11 KiB
HTML
515 lines
11 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of KEXEC_LOAD</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>KEXEC_LOAD</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
kexec_load, kexec_file_load - load a new kernel for later execution
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/linux/kexec.h">linux/kexec.h</A>></B>
|
|
|
|
<B>long kexec_load(unsigned long </B><I>entry</I><B>, unsigned long </B><I>nr_segments</I><B>,</B>
|
|
<B> struct kexec_segment *</B><I>segments</I><B>, unsigned long </B><I>flags</I><B>);</B>
|
|
|
|
<B>long kexec_file_load(int </B><I>kernel_fd</I><B>, int </B><I>initrd_fd</I><B>,</B>
|
|
<B> unsigned long </B><I>cmdline_len</I><B>, const char *</B><I>cmdline</I><B>,</B>
|
|
<B> unsigned long </B><I>flags</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
<I>Note</I>:
|
|
|
|
There are no glibc wrappers for these system calls; see NOTES.
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>kexec_load</B>()
|
|
|
|
system call loads a new kernel that can be executed later by
|
|
<B><A HREF="/cgi-bin/man/man2html?2+reboot">reboot</A></B>(2).
|
|
|
|
<P>
|
|
|
|
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>:
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>KEXEC_ON_CRASH</B> (since Linux 2.6.13)
|
|
|
|
<DD>
|
|
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.
|
|
<DT id="2"><B>KEXEC_PRESERVE_CONTEXT</B> (since Linux 2.6.27)
|
|
|
|
<DD>
|
|
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.
|
|
</DL>
|
|
<P>
|
|
|
|
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>
|
|
|
|
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>
|
|
|
|
|
|
|
|
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 */
|
|
};
|
|
|
|
|
|
<P>
|
|
|
|
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:
|
|
<DL COMPACT>
|
|
<DT id="3">*<DD>
|
|
<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.
|
|
<DT id="4">*<DD>
|
|
<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.
|
|
<DT id="5">*<DD>
|
|
<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.
|
|
</DL>
|
|
<P>
|
|
|
|
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><A HREF="/cgi-bin/man/man2html?8+kexec">kexec</A></B>(8)
|
|
|
|
command is executed with the
|
|
<I>-e</I>
|
|
|
|
option).
|
|
<P>
|
|
|
|
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>
|
|
|
|
The
|
|
<B>kexec_load</B>()
|
|
|
|
system call is available only if the kernel was configured with
|
|
<B>CONFIG_KEXEC</B>.
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>kexec_file_load()</H3>
|
|
|
|
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>
|
|
|
|
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>:
|
|
|
|
<DL COMPACT>
|
|
<DT id="6"><B>KEXEC_FILE_UNLOAD</B>
|
|
|
|
<DD>
|
|
Unload the currently loaded kernel.
|
|
<DT id="7"><B>KEXEC_FILE_ON_CRASH</B>
|
|
|
|
<DD>
|
|
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.
|
|
<DT id="8"><B>KEXEC_FILE_NO_INITRAMFS</B>
|
|
|
|
<DD>
|
|
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.
|
|
</DL>
|
|
<P>
|
|
|
|
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>.
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success, these system calls returns 0.
|
|
On error, -1 is returned and
|
|
<I>errno</I>
|
|
|
|
is set to indicate the error.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="9"><B>EADDRNOTAVAIL</B>
|
|
|
|
<DD>
|
|
|
|
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.
|
|
<DT id="10"><B>EADDRNOTAVAIL</B>
|
|
|
|
<DD>
|
|
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.
|
|
<DT id="11"><B>EBADF</B>
|
|
|
|
<DD>
|
|
<I>kernel_fd</I>
|
|
|
|
or
|
|
<I>initrd_fd</I>
|
|
|
|
is not a valid file descriptor.
|
|
<DT id="12"><B>EBUSY</B>
|
|
|
|
<DD>
|
|
Another crash kernel is already being loaded
|
|
or a crash kernel is already in use.
|
|
<DT id="13"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
<I>flags</I>
|
|
|
|
is invalid.
|
|
<DT id="14"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
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.
|
|
<DT id="15"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
<I>nr_segments</I>
|
|
|
|
exceeds
|
|
<B>KEXEC_SEGMENT_MAX</B>
|
|
|
|
(16).
|
|
<DT id="16"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
Two or more of the kernel target buffers overlap.
|
|
<DT id="17"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
The value in
|
|
<I>cmdline[cmdline_len-1]</I>
|
|
|
|
is not '\0'.
|
|
<DT id="18"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
The file referred to by
|
|
<I>kernel_fd</I>
|
|
|
|
or
|
|
<I>initrd_fd</I>
|
|
|
|
is empty (length zero).
|
|
<DT id="19"><B>ENOEXEC</B>
|
|
|
|
<DD>
|
|
<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>).
|
|
|
|
<DT id="20"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
Could not allocate memory.
|
|
<DT id="21"><B>EPERM</B>
|
|
|
|
<DD>
|
|
The caller does not have the
|
|
<B>CAP_SYS_BOOT</B>
|
|
|
|
capability.
|
|
</DL>
|
|
<A NAME="lbAH"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
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.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
These system calls are Linux-specific.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
Currently, there is no glibc support for these system calls.
|
|
Call them using
|
|
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2).
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+reboot">reboot</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+kexec">kexec</A></B>(8)
|
|
|
|
<P>
|
|
|
|
The kernel source files
|
|
<I>Documentation/kdump/kdump.txt</I>
|
|
|
|
and
|
|
<I>Documentation/admin-guide/kernel-parameters.txt</I>
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 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
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="22"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="23"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="24"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="25"><A HREF="#lbAE">kexec_file_load()</A><DD>
|
|
</DL>
|
|
<DT id="26"><A HREF="#lbAF">RETURN VALUE</A><DD>
|
|
<DT id="27"><A HREF="#lbAG">ERRORS</A><DD>
|
|
<DT id="28"><A HREF="#lbAH">VERSIONS</A><DD>
|
|
<DT id="29"><A HREF="#lbAI">CONFORMING TO</A><DD>
|
|
<DT id="30"><A HREF="#lbAJ">NOTES</A><DD>
|
|
<DT id="31"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="32"><A HREF="#lbAL">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:33 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|