Getting started

Quick start in Node

Boot Alpine Linux to a shell from the command line, then control the same machine from JavaScript.

Get a kernel

The quickest way to a shell is Alpine's netboot kernel and initramfs:

curl -LO https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/aarch64/netboot/vmlinuz-virt
curl -LO https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/aarch64/netboot/initramfs-virt

Boot it from the command line

warm-system-aarch64 -m 1G -cpu cortex-a76 -kernel vmlinuz-virt -initrd initramfs-virt -append console=ttyAMA0 -nographic

The kernel boots, and a ~ # prompt appears in your terminal. Try uname -a. Press Ctrl+A then c to switch to the monitor, where you can try info status and info cpus. Press Ctrl+A then x to quit.

If you've used qemu-system-aarch64, this is the same command line, and anything you'd add to it works the same way.

Boot it from JavaScript

You can run the same command line from code:

boot.mjs
import { WARM } from "@warm-virtual/warm64";
import { nodeWARMHost } from "@warm-virtual/warm64/warm-node";

const vm = await WARM.launch(
  "-m 1G -cpu cortex-a76 -S -display none -kernel vmlinuz-virt -initrd initramfs-virt -append console=ttyAMA0",
  nodeWARMHost(),
);

// print the console, and answer the shell's prompt once
let typed = false;
vm.serial[0].onData((bytes) => {
  process.stdout.write(bytes);
  if (!typed && new TextDecoder().decode(bytes).includes("~ # ")) {
    typed = true;
    vm.serial[0].write("uname -a; poweroff -f\n");
  }
});

await vm.qmp("cont");
const { code } = await vm.wait();
console.log(`\nexited with ${code}`);
node boot.mjs

What each part does:

  • -cpu cortex-a76 picks the CPU. QEMU's default for virt is the 32-bit cortex-a15, which can't run a 64-bit kernel, so always name an Arm64 model.
  • -S starts the machine paused, so your console listener is in place before the first byte of output. cont sets it running.
  • -display none, without -nographic, sends the console to vm.serial[0] instead of your terminal.
  • poweroff -f in the guest shuts the machine down, and wait() resolves with its exit code. The netboot initramfs ignores a plain poweroff, so -f powers off right away.

Control it

While it runs, you can do anything QEMU's QMP or monitor can do:

await vm.qmp("stop");
console.log(await vm.hmp("info registers"));
await vm.hmp("savevm booted");
await vm.qmp("cont");

Next steps