Kload
- Kload provides fast kernel switching for FreeBSD on amd64 — the ability to boot into a new kernel without going through a BIOS reset cycle. It is analogous to Linux's kexec facility.
How It Works
- When a system administrator wants to switch to a new kernel, kload works in two phases:
Phase 1 — Preload (while the system is running normally): The kload(8) userspace command uses the FreeBSD userboot.so loader framework to parse and load a new kernel image into a reserved region of kernel virtual memory. The BIOS memory map is captured from the running system via a new buildsmap userboot callback so it can be handed to the incoming kernel without a BIOS query.
Phase 2 — Switch (at reboot time): Instead of resetting the hardware, the normal reboot path hands control to the kload execution engine. All application processors (APs) are halted via an IPI_KLOAD inter-processor interrupt. The BSP then sets up a fresh GDT and a minimal identity-mapped page table, atomically overwrites the running kernel with the preloaded image, and jumps to the new kernel's entry point. The APs are then restarted by the new kernel's SMP bring-up sequence.
Panic Safety
If the system panics after a kernel has been preloaded, the RB_ABORT_KLOAD flag is set automatically in kern_reboot() to prevent the switch from happening — the system will fall through to a normal reboot or dump instead.
Architecture
- Kload is currently amd64-only. Key components:
usr.sbin/kload/ — userspace loader command (based on bhyveload(8))
sys/kern/kern_kload.c — syscall interface; manages the preloaded image in kernel memory
sys/amd64/amd64/kload.c — builds the GDT and identity-mapped page table for the switch
sys/amd64/amd64/kload_exec.S — assembly trampoline: halts APs, copies image, jumps to new entry
stand/userboot/ — extended with buildsmap callback (USERBOOT_VERSION_6)
Building
Add options KLOAD to your kernel config (see sys/amd64/conf/GENERIC). The userspace tool builds as part of the normal world build.
Timeline
2011 — Initial development begun by Russell Cattelan (Digital Elves LLC)
2012 — Co-developed with EMC Corp / Isilon Systems Division
May 2012 — Presented at BSDCan 2012: "Fast reboots with kload"
November 2012 — Posted to freebsd-current mailing list
2017 — Last active development (branch kload-20170103)
2026 — Branch rebased onto current FreeBSD main; updated to USERBOOT_VERSION_6, IPI slot and reboot flag conflicts resolved
Resources
Todo
- Build and boot test on current FreeBSD
Verify buildsmap callback used conditionally (version >= USERBOOT_VERSION_6)
- Clean up squash commits before upstream submission
- i386 / arm64 support (currently amd64 only)
- Driver testing
Contact
- Email: cattelan at digitalelves dot com