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-virtBoot it from the command line
warm-system-aarch64 -m 1G -cpu cortex-a76 -kernel vmlinuz-virt -initrd initramfs-virt -append console=ttyAMA0 -nographicThe 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.mjsWhat each part does:
-cpu cortex-a76picks the CPU. QEMU's default forvirtis the 32-bitcortex-a15, which can't run a 64-bit kernel, so always name an Arm64 model.-Sstarts the machine paused, so your console listener is in place before the first byte of output.contsets it running.-display none, without-nographic, sends the console tovm.serial[0]instead of your terminal.poweroff -fin the guest shuts the machine down, andwait()resolves with its exit code. The netboot initramfs ignores a plainpoweroff, so-fpowers 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
- Booting Linux with a root disk, Debian or Arch
- Networking: the guest has a network card by default, as in QEMU
- WARM reference