Boot Options

Check support, pick a kernel and tune the boot.

import { checkSupport, createKernel } from "unkernel";

const support = await checkSupport(); // JSPI and the rest, before you boot
if (!support.ok) throw new Error(support.problems.join("\n"));

const vm = await createKernel({
  kernel: "./my-kernel.wasm", // a URL, bytes, a Response or a WebAssembly.Module
  initrd: "./initramfs.cpio.gz", // null: none
  cmdline: "console=hvc0 rdinit=/init",
  memoryMiB: 1024,
  jit: false, // interpreter only
  onProgress: (p) => console.log(p.stage),
});

createKernel() rejects with a BootError if the kernel cannot start.

Other options:

  • signal: an AbortSignal that cancels the downloads and, once the kernel has booted, stops it.
  • consoleSize: { cols, rows }: the console's size at boot; resize() changes it later.
  • log: where host diagnostics ([host] ..., [net] ...) go. Default console.error.
  • onDiskError(index, error): a disk built from a spec failed to save a flush (such as a full quota); the guest gets EIO for it.
  • memoryFallbackMiB: smaller sizes to try in order if memoryMiB cannot be allocated (browsers default to DEFAULT_MEMORY_FALLBACK_MIB).
  • profile: true: sample where guest user time goes; vm.profile() reads the report and formatProfile() prints it. Time samples need several CPUs and Node; elsewhere only instruction samples are taken.

vm.distro describes the distro image the guest booted, and vm.stats() has the counters of every device.

#Limits

On top of the kernel's own limits:

  • There is no guest agent beyond terminal sessions, so you drive the guest through a terminal or its console, or over vsock with your own program; guest programs reach you through host commands.
  • Devices beyond the console are off unless asked for: display, sound, soundIn, camera, shm, gpu, gl, vk, va, net, serial, bluetooth and usb (vsock is on unless vsock: false).
  • stop() doesn't shut the guest down cleanly, so prefer poweroff.
  • Only one kernel can run per thread.
  • Types ship as .d.mts and use the DOM's WebAssembly types, so a Node-only TypeScript project needs "lib": ["dom"] or skipLibCheck.