How nanovms/nanos works
Purpose and Entry Points
Nanos is a single-application unikernel: it boots one application directly in a virtualized environment, rather than hosting multiple users/processes or SSH administration. The build root is Makefile, with kernel composition in kernel.mk and shared rules in rules.mk. Primary execution starts in platform boot code and architecture CRT/initialization paths, then reaches kernel initialization.
Boot, Platform, and CPU Boundary
Platform directories produce bootable images and provide machine-specific services for PC, ARM virtual, and RISC-V virtual targets: platform/pc/boot/stage1.s, platform/pc/boot/stage2.c, platform/virt/service.c. Architecture implementations establish CPU state, interrupts, paging, clocks, serial I/O, and UEFI/ELF support for x86-64, AArch64, and RISC-V: src/x86_64/crt0.s, src/aarch64/kernel_machine.c, src/riscv64/init.S.
Kernel Lifecycle and Resource Core
Kernel startup coordinates staged initialization, scheduling, physical/virtual memory, PCI discovery, storage, and logging: src/kernel/init.c, src/kernel/stage3.c, src/kernel/kernel.c. Heap and page-management layers underpin all higher-level allocations and mappings: src/kernel/page.c, src/kernel/pagecache.c, src/kernel/vmem_heap.c. This is the central boundary between hardware/platform abstractions and runtime, driver, and application services.
Runtime and Single-Process Unix ABI
The generic runtime supplies primitive containers, closures, timers, buffers, heaps, cryptography, and management abstractions used across kernel subsystems: src/runtime/runtime_init.c, src/runtime/heap/heap.h, src/runtime/closure.h. The Unix layer exposes the Linux-like application execution and syscall surface—ELF loading, threads, memory mappings, files, signals, sockets, polling, and async I/O—within the one-application model: src/unix/unix.c, src/unix/syscall.c, src/unix/exec.c. Application binaries enter through architecture-specific Unix-machine glue, e.g. src/x86_64/unix_machine.c.
Device Discovery, Virtualization, and I/O
Hardware discovery is based on ACPI/device tree and PCI, then routes devices to native or paravirtual drivers: src/drivers/acpi.c, src/devicetree/devicetree.c, src/kernel/pci.c. VirtIO is the primary portable virtual-device transport for networking, storage, sockets, 9P, SCSI, RNG, and ballooning: src/virtio/virtio.c, src/virtio/virtio_pci.c, src/virtio/virtqueue.c. Cloud/hypervisor-specific paths support AWS ENA, Hyper-V VMBus, VMware, and Xen: src/aws/ena/ena.c, src/hyperv/vmbus/vmbus.c, src/xen/xen.c.
Storage, Filesystems, and Networking
The storage path connects block transports to the filesystem layer and TFS, Nanos’s current filesystem: src/kernel/storage.c, src/fs/fs.c, src/fs/tfs.c. Optional filesystem-related services include 9P and tmpfs: src/fs/9p.c, klib/tmpfs.c. Networking uses lwIP integration, direct network plumbing, and Unix socket/syscall adapters: src/net/net.c, src/net/direct.c, src/unix/socket.c. Network devices are provided by VirtIO, cloud, Hyper-V, VMware, or native drivers.
Image Services, Cloud Integration, and Observability
Kernel libraries add boot-time/application-adjacent services such as cloud-init metadata, userdata, AWS/GCP/Azure integrations, TLS, NTP, firewalling, and S3-backed filesystem support: klib/cloud_init.c, klib/aws.c, klib/s3fs.c. These form external-service boundaries with cloud metadata/control APIs and network services. Observability and debug interfaces include tracing, syscall tracing, GDB remote support, telnet management, and log facilities: src/kernel/tracelog.c, src/gdb/gdbstub.c, src/kernel/management_telnet.c.
Runtime Environments and Delivery
Nanos targets virtualized x86-64, AArch64, and RISC-V environments, developed/run locally through QEMU with KVM (Linux) or HVF (macOS) acceleration. ops is the externally maintained, tightly coupled build/run/deployment tool; it can deploy images to AWS, GCP, Azure, and other cloud environments. Kernel artifacts include platform boot images and kernel images built through Makefile and platform-specific Makefiles such as platform/pc/Makefile.
Main entry points: init.c Kernel lifecycle · net.c Network stack · unix.c Single-process Unix ABI · acpi.c Hardware discovery
Components 19
Build & Delivery
- Build root · Composes the kernel and platform image build.
Makefile - PC image build
platform/pc/Makefile - Bootable kernel images · Platform boot and kernel images for virtualized targets.
- ops deployment · Builds, runs, and deploys images to local and cloud virtual environments.
Boot & Kernel Core
- Platform boot · Loads the kernel and supplies target machine services.
platform/pc/boot/stage1.s - CPU initialization · Establishes CPU state before kernel startup.
src/x86_64/crt0.s - Kernel lifecycle · Stages initialization, scheduling, PCI, storage, and logging.
src/kernel/init.c - Memory core · Provides physical, virtual, and heap allocation services.
src/kernel/page.c
Runtime & Unix ABI
- Generic runtime · Supplies buffers, timers, closures, heaps, and shared primitives.
src/runtime/runtime_init.c - Single-process Unix ABI · Provides syscalls, ELF execution, threads, mappings, files, signals, and async I/O.
src/unix/unix.c - Application entry glue · Transfers into the application under the one-application model.
src/x86_64/unix_machine.c
Devices, Storage & Network
- Hardware discovery · Discovers machine devices and routes driver binding.
src/drivers/acpi.c - VirtIO transport · Portable transport for network, block, socket, 9P, SCSI, RNG, and balloon devices.
src/virtio/virtio.c - Cloud hypervisor drivers · Supports AWS ENA, Hyper-V, VMware, Xen, and native devices.
src/aws/ena/ena.c - Storage stack · Connects block transports to filesystem services.
src/kernel/storage.c - Filesystem layer · Hosts TFS with optional 9P and tmpfs services.
src/fs/fs.c - Network stack · Provides direct networking and Unix socket adapters.
src/net/net.c
Cloud & Observability
- Cloud image services · Provides cloud-init, metadata, cloud APIs, TLS, and S3 filesystem support.
klib/cloud_init.c - Debug & management · Provides tracing, GDB remote support, telnet management, and logs.
src/kernel/tracelog.c
Connections 24
- Build root → PC image build: includes platform build
- PC image build → Bootable kernel images: produces
- Build root → Bootable kernel images: composes
- Bootable kernel images → Platform boot: boots through
- Platform boot → CPU initialization: enters
- CPU initialization → Kernel lifecycle: starts
- Kernel lifecycle → Memory core: initializes
- Kernel lifecycle → Generic runtime: initializes
- Memory core → Generic runtime: backs allocations
- Generic runtime → Single-process Unix ABI: supports
- Single-process Unix ABI → Application entry glue: hosts application entry
- Kernel lifecycle → Hardware discovery: enumerates devices
- Hardware discovery → VirtIO transport: binds virtual devices
- Hardware discovery → Cloud hypervisor drivers: binds platform drivers
- VirtIO transport → Storage stack: provides block transport
- Cloud hypervisor drivers → Storage stack: provides block devices
- Storage stack → Filesystem layer: backs
- VirtIO transport → Network stack: provides NICs
- Cloud hypervisor drivers → Network stack: provides NICs
- Network stack → Single-process Unix ABI: serves sockets
- Filesystem layer → Single-process Unix ABI: serves files
- Network stack → Cloud image services: reaches external APIs
- Kernel lifecycle → Debug & management: exposes diagnostics
- ops deployment → Bootable kernel images: runs and deploys