---
name: "kexec_load"
section: "2"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/kexec_load"
---

# kexec\_load(2)

prepare new kernel to reboot into

## NAME

**kexec\_load** – prepare new kernel to reboot into

## SYNOPSIS

Standard C Library (libc, -lc)

**#include \<sys/kexec.h\>**

*int*\

**kexec\_load**(*uint64\_t entry*, *unsigned long count*, *struct kexec\_segment \*segments*, *unsigned long flags*);

## DESCRIPTION

The **kexec\_load**() system call loads a new kernel that can be executed later by [reboot(2)](/reboot/2.md). Subsequent calls will replace previously loaded images.

The *flags* argument is a bitmask of flags that control the operation of the call. This argument is present for compatibility with Linux, although it is currently unused and must be 0.

The *entry* argument is the physical address of the entry point of the new kernel image.

The *count* argument is the number of segments in the image, currently limited to 16. A value of 0 will unload the currently staged image, if one exists, without staging a new image.

The *segments* argument is an array of *count* members of the following structure:

```
struct  kexec_segment {
    void *buf;
    size_t bufsz;
    vm_paddr_t mem;
    vm_size_t memsz;
};
```

The *buf* and *bufsz* members specify a memory region in the caller's address space containing the source of the segment. The *mem* and *memsz* members specify the target physical region of the segment. *bufsz* must be less than or equal to *memsz*, and *mem* and *memsz* must be page aligned. The region covered by *mem* must be in the list covered by the *vm.phys\_segs* sysctl.

The **kexec\_load**() system call stages the kernel image in safe memory along with all machine-dependent image data until [reboot(2)](/reboot/2.md) is called with the *RB\_KEXEC* flag to load the image and execute the new kernel.

## RETURN VALUES

The **kexec\_load**() system call returns 0 on success. On failure, -1 is returned, and *errno* is set to indicate the error. On success any previously loaded image is unloaded and replaced with the new image. On failure, the previously loaded image is unchanged.

## ERRORS

The following errors may be returned:

- \[EINVAL\]

  Too many segments in image.

- \[EINVAL\]

  The value of *bufsz* is larger than *memsz* in one or more segments.

- \[EINVAL\]

  Machine-dependent load error.

- \[EBUSY\]

  Another **kexec\_load**() call is in progress.

## HISTORY

The **kexec\_load** system call appeared in FreeBSD 16.0.
