Blame man2/kexec_load.2

Packit 7cfc04
.\" Copyright (C) 2010 Intel Corporation, Author: Andi Kleen
Packit 7cfc04
.\" and Copyright 2014, Vivek Goyal <vgoyal@redhat.com>
Packit 7cfc04
.\" and Copyright (c) 2015, Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.TH KEXEC_LOAD 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
kexec_load, kexec_file_load \- load a new kernel for later execution
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <linux/kexec.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "long kexec_load(unsigned long " entry ", unsigned long " nr_segments ","
Packit 7cfc04
.BI "                struct kexec_segment *" segments \
Packit 7cfc04
", unsigned long " flags ");"
Packit 7cfc04
.PP
Packit 7cfc04
.BI "long kexec_file_load(int " kernel_fd ", int " initrd_fd ","
Packit 7cfc04
.BI "                    unsigned long " cmdline_len  \
Packit 7cfc04
", const char *" cmdline ","
Packit 7cfc04
.BI "                    unsigned long " flags ");"
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.IR Note :
Packit 7cfc04
There are no glibc wrappers for these system calls; see NOTES.
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
.BR kexec_load ()
Packit 7cfc04
system call loads a new kernel that can be executed later by
Packit 7cfc04
.BR reboot (2).
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I flags
Packit 7cfc04
argument is a bit mask that controls the operation of the call.
Packit 7cfc04
The following values can be specified in
Packit 7cfc04
.IR flags :
Packit 7cfc04
.TP
Packit 7cfc04
.BR KEXEC_ON_CRASH " (since Linux 2.6.13)"
Packit 7cfc04
Execute the new kernel automatically on a system crash.
Packit 7cfc04
This "crash kernel" is loaded into an area of reserved memory that
Packit 7cfc04
is determined at boot time using the
Packit 7cfc04
.I crashkernel
Packit 7cfc04
kernel command-line parameter.
Packit 7cfc04
The location of this reserved memory is exported to user space via the
Packit 7cfc04
.I /proc/iomem
Packit 7cfc04
file, in an entry labeled "Crash kernel".
Packit 7cfc04
A user-space application can parse this file and prepare a list of
Packit 7cfc04
segments (see below) that specify this reserved memory as destination.
Packit 7cfc04
If this flag is specified, the kernel checks that the
Packit 7cfc04
target segments specified in
Packit 7cfc04
.I segments
Packit 7cfc04
fall within the reserved region.
Packit 7cfc04
.TP
Packit 7cfc04
.BR KEXEC_PRESERVE_CONTEXT " (since Linux 2.6.27)"
Packit 7cfc04
Preserve the system hardware and
Packit 7cfc04
software states before executing the new kernel.
Packit 7cfc04
This could be used for system suspend.
Packit 7cfc04
This flag is available only if the kernel was configured with
Packit 7cfc04
.BR CONFIG_KEXEC_JUMP ,
Packit 7cfc04
and is effective only if
Packit 7cfc04
.I nr_segments
Packit 7cfc04
is greater than 0.
Packit 7cfc04
.PP
Packit 7cfc04
The high-order bits (corresponding to the mask 0xffff0000) of
Packit 7cfc04
.I flags
Packit 7cfc04
contain the architecture of the to-be-executed kernel.
Packit 7cfc04
Specify (OR) the constant
Packit 7cfc04
.B KEXEC_ARCH_DEFAULT
Packit 7cfc04
to use the current architecture,
Packit 7cfc04
or one of the following architecture constants
Packit 7cfc04
.BR KEXEC_ARCH_386 ,
Packit 7cfc04
.BR KEXEC_ARCH_68K ,
Packit 7cfc04
.BR KEXEC_ARCH_X86_64 ,
Packit 7cfc04
.BR KEXEC_ARCH_PPC ,
Packit 7cfc04
.BR KEXEC_ARCH_PPC64 ,
Packit 7cfc04
.BR KEXEC_ARCH_IA_64 ,
Packit 7cfc04
.BR KEXEC_ARCH_ARM ,
Packit 7cfc04
.BR KEXEC_ARCH_S390 ,
Packit 7cfc04
.BR KEXEC_ARCH_SH ,
Packit 7cfc04
.BR KEXEC_ARCH_MIPS ,
Packit 7cfc04
and
Packit 7cfc04
.BR KEXEC_ARCH_MIPS_LE .
Packit 7cfc04
The architecture must be executable on the CPU of the system.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I entry
Packit 7cfc04
argument is the physical entry address in the kernel image.
Packit 7cfc04
The
Packit 7cfc04
.I nr_segments
Packit 7cfc04
argument is the number of segments pointed to by the
Packit 7cfc04
.I segments
Packit 7cfc04
pointer;
Packit 7cfc04
the kernel imposes an (arbitrary) limit of 16 on the number of segments.
Packit 7cfc04
The
Packit 7cfc04
.I segments
Packit 7cfc04
argument is an array of
Packit 7cfc04
.I kexec_segment
Packit 7cfc04
structures which define the kernel layout:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct kexec_segment {
Packit 7cfc04
    void   *buf;        /* Buffer in user space */
Packit 7cfc04
    size_t  bufsz;      /* Buffer length in user space */
Packit 7cfc04
    void   *mem;        /* Physical address of kernel */
Packit 7cfc04
    size_t  memsz;      /* Physical address length */
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
The kernel image defined by
Packit 7cfc04
.I segments
Packit 7cfc04
is copied from the calling process into
Packit 7cfc04
the kernel either in regular
Packit 7cfc04
memory or in reserved memory (if
Packit 7cfc04
.BR KEXEC_ON_CRASH
Packit 7cfc04
is set).
Packit 7cfc04
The kernel first performs various sanity checks on the
Packit 7cfc04
information passed in
Packit 7cfc04
.IR segments .
Packit 7cfc04
If these checks pass, the kernel copies the segment data to kernel memory.
Packit 7cfc04
Each segment specified in
Packit 7cfc04
.I segments
Packit 7cfc04
is copied as follows:
Packit 7cfc04
.IP * 3
Packit 7cfc04
.I buf
Packit 7cfc04
and
Packit 7cfc04
.I bufsz
Packit 7cfc04
identify a memory region in the caller's virtual address space
Packit 7cfc04
that is the source of the copy.
Packit 7cfc04
The value in
Packit 7cfc04
.I bufsz
Packit 7cfc04
may not exceed the value in the
Packit 7cfc04
.I memsz
Packit 7cfc04
field.
Packit 7cfc04
.IP *
Packit 7cfc04
.I mem
Packit 7cfc04
and
Packit 7cfc04
.I memsz
Packit 7cfc04
specify a physical address range that is the target of the copy.
Packit 7cfc04
The values specified in both fields must be multiples of
Packit 7cfc04
the system page size.
Packit 7cfc04
.IP *
Packit 7cfc04
.I bufsz
Packit 7cfc04
bytes are copied from the source buffer to the target kernel buffer.
Packit 7cfc04
If
Packit 7cfc04
.I bufsz
Packit 7cfc04
is less than
Packit 7cfc04
.IR memsz ,
Packit 7cfc04
then the excess bytes in the kernel buffer are zeroed out.
Packit 7cfc04
.PP
Packit 7cfc04
In case of a normal kexec (i.e., the
Packit 7cfc04
.BR KEXEC_ON_CRASH
Packit 7cfc04
flag is not set), the segment data is loaded in any available memory
Packit 7cfc04
and is moved to the final destination at kexec reboot time (e.g., when the
Packit 7cfc04
.BR kexec (8)
Packit 7cfc04
command is executed with the
Packit 7cfc04
.I \-e
Packit 7cfc04
option).
Packit 7cfc04
.PP
Packit 7cfc04
In case of kexec on panic (i.e., the
Packit 7cfc04
.BR KEXEC_ON_CRASH
Packit 7cfc04
flag is set), the segment data is
Packit 7cfc04
loaded to reserved memory at the time of the call, and, after a crash,
Packit 7cfc04
the kexec mechanism simply passes control to that kernel.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR kexec_load ()
Packit 7cfc04
system call is available only if the kernel was configured with
Packit 7cfc04
.BR CONFIG_KEXEC .
Packit 7cfc04
.SS kexec_file_load()
Packit 7cfc04
The
Packit 7cfc04
.BR kexec_file_load ()
Packit 7cfc04
system call is similar to
Packit 7cfc04
.BR kexec_load (),
Packit 7cfc04
but it takes a different set of arguments.
Packit 7cfc04
It reads the kernel to be loaded from the file referred to by
Packit 7cfc04
the file descriptor
Packit 7cfc04
.IR kernel_fd ,
Packit 7cfc04
and the initrd (initial RAM disk)
Packit 7cfc04
to be loaded from file referred to by the file descriptor
Packit 7cfc04
.IR initrd_fd .
Packit 7cfc04
The
Packit 7cfc04
.IR cmdline
Packit 7cfc04
argument is a pointer to a buffer containing the command line
Packit 7cfc04
for the new kernel.
Packit 7cfc04
The
Packit 7cfc04
.IR cmdline_len
Packit 7cfc04
argument specifies size of the buffer.
Packit 7cfc04
The last byte in the buffer must be a null byte (\(aq\\0\(aq).
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.IR flags
Packit 7cfc04
argument is a bit mask which modifies the behavior of the call.
Packit 7cfc04
The following values can be specified in
Packit 7cfc04
.IR flags :
Packit 7cfc04
.TP
Packit 7cfc04
.BR KEXEC_FILE_UNLOAD
Packit 7cfc04
Unload the currently loaded kernel.
Packit 7cfc04
.TP
Packit 7cfc04
.BR KEXEC_FILE_ON_CRASH
Packit 7cfc04
Load the new kernel in the memory region reserved for the crash kernel
Packit 7cfc04
(as for
Packit 7cfc04
.BR KEXEC_ON_CRASH).
Packit 7cfc04
This kernel is booted if the currently running kernel crashes.
Packit 7cfc04
.TP
Packit 7cfc04
.BR KEXEC_FILE_NO_INITRAMFS
Packit 7cfc04
Loading initrd/initramfs is optional.
Packit 7cfc04
Specify this flag if no initramfs is being loaded.
Packit 7cfc04
If this flag is set, the value passed in
Packit 7cfc04
.IR initrd_fd
Packit 7cfc04
is ignored.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR kexec_file_load ()
Packit 7cfc04
.\" See also http://lwn.net/Articles/603116/
Packit 7cfc04
system call was added to provide support for systems
Packit 7cfc04
where "kexec" loading should be restricted to
Packit 7cfc04
only kernels that are signed.
Packit 7cfc04
This system call is available only if the kernel was configured with
Packit 7cfc04
.BR CONFIG_KEXEC_FILE .
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success, these system calls returns 0.
Packit 7cfc04
On error, \-1 is returned and
Packit 7cfc04
.I errno
Packit 7cfc04
is set to indicate the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EADDRNOTAVAIL
Packit 7cfc04
.\" See kernel/kexec.::sanity_check_segment_list in the 3.19 kernel source
Packit 7cfc04
The
Packit 7cfc04
.B KEXEC_ON_CRASH
Packit 7cfc04
flags was specified, but the region specified by the
Packit 7cfc04
.I mem
Packit 7cfc04
and
Packit 7cfc04
.I memsz
Packit 7cfc04
fields of one of the
Packit 7cfc04
.I segments
Packit 7cfc04
entries lies outside the range of memory reserved for the crash kernel.
Packit 7cfc04
.TP
Packit 7cfc04
.B EADDRNOTAVAIL
Packit 7cfc04
The value in a
Packit 7cfc04
.I mem
Packit 7cfc04
or
Packit 7cfc04
.I memsz
Packit 7cfc04
field in one of the
Packit 7cfc04
.I segments
Packit 7cfc04
entries is not a multiple of the system page size.
Packit 7cfc04
.TP
Packit 7cfc04
.B EBADF
Packit 7cfc04
.I kernel_fd
Packit 7cfc04
or
Packit 7cfc04
.I initrd_fd
Packit 7cfc04
is not a valid file descriptor.
Packit 7cfc04
.TP
Packit 7cfc04
.B EBUSY
Packit 7cfc04
Another crash kernel is already being loaded
Packit 7cfc04
or a crash kernel is already in use.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.I flags
Packit 7cfc04
is invalid.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
The value of a
Packit 7cfc04
.I bufsz
Packit 7cfc04
field in one of the
Packit 7cfc04
.I segments
Packit 7cfc04
entries exceeds the value in the corresponding
Packit 7cfc04
.I memsz
Packit 7cfc04
field.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.IR nr_segments
Packit 7cfc04
exceeds
Packit 7cfc04
.BR KEXEC_SEGMENT_MAX
Packit 7cfc04
(16).
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
Two or more of the kernel target buffers overlap.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
The value in
Packit 7cfc04
.I cmdline[cmdline_len-1]
Packit 7cfc04
is not \(aq\\0\(aq.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
The file referred to by
Packit 7cfc04
.I kernel_fd
Packit 7cfc04
or
Packit 7cfc04
.I initrd_fd
Packit 7cfc04
is empty (length zero).
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOEXEC
Packit 7cfc04
.I kernel_fd
Packit 7cfc04
does not refer to an open file, or the kernel can't load this file.
Packit 7cfc04
Currently, the file must be a bzImage and contain an x86 kernel that
Packit 7cfc04
is loadable above 4\ GiB in memory (see the kernel source file
Packit 7cfc04
.IR Documentation/x86/boot.txt ).
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOMEM
Packit 7cfc04
Could not allocate memory.
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
The caller does not have the
Packit 7cfc04
.BR CAP_SYS_BOOT
Packit 7cfc04
capability.
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
The
Packit 7cfc04
.BR kexec_load ()
Packit 7cfc04
system call first appeared in Linux 2.6.13.
Packit 7cfc04
The
Packit 7cfc04
.BR kexec_file_load ()
Packit 7cfc04
system call first appeared in Linux 3.17.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
These system calls are Linux-specific.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Currently, there is no glibc support for these system calls.
Packit 7cfc04
Call them using
Packit 7cfc04
.BR syscall (2).
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR reboot (2),
Packit 7cfc04
.BR syscall (2),
Packit 7cfc04
.BR kexec (8)
Packit 7cfc04
.PP
Packit 7cfc04
The kernel source files
Packit 7cfc04
.IR Documentation/kdump/kdump.txt
Packit 7cfc04
and
Packit 7cfc04
.IR Documentation/admin-guide/kernel-parameters.txt
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.