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: anAbortSignalthat 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. Defaultconsole.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 ifmemoryMiBcannot be allocated (browsers default toDEFAULT_MEMORY_FALLBACK_MIB).profile: true: sample where guest user time goes;vm.profile()reads the report andformatProfile()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,bluetoothandusb(vsock is on unlessvsock: false). stop()doesn't shut the guest down cleanly, so preferpoweroff.- Only one kernel can run per thread.
- Types ship as
.d.mtsand use the DOM'sWebAssemblytypes, so a Node-only TypeScript project needs"lib": ["dom"]orskipLibCheck.