kexec

package
v0.0.0-...-b25b90c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package kexec wraps the kexec_file_load(2) syscall and the reboot(2) trigger.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Boot

func Boot() error

Boot triggers the staged kernel. Does not return on success.

func Load

func Load(kernelPath, initrdPath, cmdline string) error

Load stages the given kernel + optional initrd + cmdline for kexec.

EFI zboot kernels (e.g. Alpine's vmlinuz-virt) are transparently unwrapped first — arm64's kexec_file_load only accepts a raw Image (it probes for ARM64_IMAGE_MAGIC at offset 56) and would reject the PE wrapper with EINVAL. See zboot_linux.go for the format details.

func MaybeUnwrapZBoot

func MaybeUnwrapZBoot(kernelPath string) (string, error)

MaybeUnwrapZBoot detects an EFI zboot wrapper at kernelPath and, if present, extracts the inner Linux kernel image to a sibling tempfile and returns its path. If the file is not a zboot, the original path is returned unchanged.

EFI zboot (drivers/firmware/efi/libstub/zboot-header.S) layout:

offset 0  : "MZ\0\0"
offset 4  : "zimg"
offset 8  : u32 payload_offset   (start of compressed payload)
offset 12 : u32 payload_size     (compressed bytes)
offset 16 : u32 reserved[2]
offset 24 : char compression_type[32]   "gzip" | "zstd" | "xz" | …

arm64's kexec_file_load doesn't understand zboot — its image_probe() looks for ARM64_IMAGE_MAGIC at offset 56 of a raw Image header and rejects the zboot wrapper outright (EINVAL). By decompressing in the init userspace we can reuse stock netboot kernels (Alpine, RHEL, …) that ship exclusively as zboot today.

Supported compressions — the only two mainline's Makefile.zboot can emit since ~6.7:

gzip   — default choice (Alpine, Debian, most distros)
zstd   — selected by CONFIG_KERNEL_ZSTD (Fedora, recent Ubuntu, RHEL)

xz / lzma / lzo / lz4 are intentionally not implemented: mainline dropped them as zboot choices, no current distro ships them in zboot form, and the savings vs zstd are nil (xz/lzma are slightly smaller but much slower to decompress; lz4/lzo are faster but compress significantly worse — neither matters for a one-shot kernel decode). If a real zboot image with one of these ever shows up the error message names the type so we can add support in 5 minutes.

Note: xz / lzma / lzo / lz4 also exist as separate `Image.<ext>` build targets for U-Boot and friends. Those are *raw* compressed Image files, not PE-wrapped zboot, and bypass this function entirely (no `zimg` magic at offset 4 → pass-through).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL