# nanovms/nanos architecture

> Architecture diagram of the GitHub repository nanovms/nanos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nanovms/nanos
- Repository: https://github.com/nanovms/nanos

## Overview

#### 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: [`src/kernel/init.c`](https://github.com/nanovms/nanos/blob/master/src/kernel/init.c) (Kernel lifecycle), [`src/net/net.c`](https://github.com/nanovms/nanos/blob/master/src/net/net.c) (Network stack), [`src/unix/unix.c`](https://github.com/nanovms/nanos/blob/master/src/unix/unix.c) (Single-process Unix ABI), [`src/drivers/acpi.c`](https://github.com/nanovms/nanos/blob/master/src/drivers/acpi.c) (Hardware discovery)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build &amp; Delivery"]
  node_make["Build root<br/>Make build"]
  node_pc_build["PC image build<br/>platform Make build"]
  node_images["Bootable kernel images<br/>artifact"]
  node_deployment{{"ops deployment<br/>external delivery tool"}}
end

subgraph group_boot["Boot &amp; Kernel Core"]
  node_platform_boot["Platform boot<br/>bootloader<br/>[stage1.s]"]
  node_cpu_init["CPU initialization<br/>architecture CRT<br/>[crt0.s]"]
  node_kernel_init["Kernel lifecycle<br/>kernel initialization<br/>[init.c]"]
  node_memory["Memory core<br/>page and heap management<br/>[page.c]"]
end

subgraph group_runtime["Runtime &amp; Unix ABI"]
  node_runtime_init["Generic runtime<br/>runtime foundation<br/>[runtime_init.c]"]
  node_unix_abi["Single-process Unix ABI<br/>Linux-like ABI<br/>[unix.c]"]
  node_app_glue["Application entry glue<br/>Unix machine layer<br/>[unix_machine.c]"]
end

subgraph group_io["Devices, Storage &amp; Network"]
  node_discovery["Hardware discovery<br/>ACPI, DT, PCI<br/>[acpi.c]"]
  node_virtio["VirtIO transport<br/>paravirtual I/O<br/>[virtio.c]"]
  node_hypervisor_drivers["Cloud hypervisor drivers<br/>native/paravirtual drivers<br/>[ena.c]"]
  node_storage["Storage stack<br/>block I/O<br/>[storage.c]"]
  node_filesystem["Filesystem layer<br/>TFS and file services<br/>[fs.c]"]
  node_network["Network stack<br/>lwIP integration<br/>[net.c]"]
end

subgraph group_services["Cloud &amp; Observability"]
  node_cloud_services["Cloud image services<br/>external-service integration<br/>[cloud_init.c]"]
  node_observability["Debug &amp; management<br/>observability interfaces<br/>[tracelog.c]"]
end

node_make -->|"includes platform build"| node_pc_build
node_pc_build -->|"produces"| node_images
node_make -->|"composes"| node_images
node_images -->|"boots through"| node_platform_boot
node_platform_boot -->|"enters"| node_cpu_init
node_cpu_init -->|"starts"| node_kernel_init
node_kernel_init -->|"initializes"| node_memory
node_kernel_init -->|"initializes"| node_runtime_init
node_memory -->|"backs allocations"| node_runtime_init
node_runtime_init -->|"supports"| node_unix_abi
node_unix_abi -->|"hosts application entry"| node_app_glue
node_kernel_init -->|"enumerates devices"| node_discovery
node_discovery -->|"binds virtual devices"| node_virtio
node_discovery -->|"binds platform drivers"| node_hypervisor_drivers
node_virtio -->|"provides block transport"| node_storage
node_hypervisor_drivers -->|"provides block devices"| node_storage
node_storage -->|"backs"| node_filesystem
node_virtio -->|"provides NICs"| node_network
node_hypervisor_drivers -->|"provides NICs"| node_network
node_network -->|"serves sockets"| node_unix_abi
node_filesystem -->|"serves files"| node_unix_abi
node_network -->|"reaches external APIs"| node_cloud_services
node_kernel_init -->|"exposes diagnostics"| node_observability
node_deployment -.->|"runs and deploys"| node_images

click node_make "https://github.com/nanovms/nanos/blob/master/Makefile"
click node_pc_build "https://github.com/nanovms/nanos/blob/master/platform/pc/Makefile"
click node_platform_boot "https://github.com/nanovms/nanos/blob/master/platform/pc/boot/stage1.s"
click node_cpu_init "https://github.com/nanovms/nanos/blob/master/src/x86_64/crt0.s"
click node_kernel_init "https://github.com/nanovms/nanos/blob/master/src/kernel/init.c"
click node_memory "https://github.com/nanovms/nanos/blob/master/src/kernel/page.c"
click node_runtime_init "https://github.com/nanovms/nanos/blob/master/src/runtime/runtime_init.c"
click node_unix_abi "https://github.com/nanovms/nanos/blob/master/src/unix/unix.c"
click node_app_glue "https://github.com/nanovms/nanos/blob/master/src/x86_64/unix_machine.c"
click node_discovery "https://github.com/nanovms/nanos/blob/master/src/drivers/acpi.c"
click node_virtio "https://github.com/nanovms/nanos/blob/master/src/virtio/virtio.c"
click node_hypervisor_drivers "https://github.com/nanovms/nanos/blob/master/src/aws/ena/ena.c"
click node_storage "https://github.com/nanovms/nanos/blob/master/src/kernel/storage.c"
click node_filesystem "https://github.com/nanovms/nanos/blob/master/src/fs/fs.c"
click node_network "https://github.com/nanovms/nanos/blob/master/src/net/net.c"
click node_cloud_services "https://github.com/nanovms/nanos/blob/master/klib/cloud_init.c"
click node_observability "https://github.com/nanovms/nanos/blob/master/src/kernel/tracelog.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_make,node_pc_build,node_images,node_deployment toneBlue
class node_platform_boot,node_cpu_init,node_kernel_init,node_memory toneAmber
class node_runtime_init,node_unix_abi,node_app_glue toneMint
class node_discovery,node_virtio,node_hypervisor_drivers,node_storage,node_filesystem,node_network toneRose
class node_cloud_services,node_observability toneIndigo
```

## Components

### Build & Delivery

- [Build root](https://github.com/nanovms/nanos/blob/master/Makefile): Make build · Composes the kernel and platform image build. · `Makefile`
- [PC image build](https://github.com/nanovms/nanos/blob/master/platform/pc/Makefile): platform Make build · `platform/pc/Makefile`
- **Bootable kernel images**: artifact · Platform boot and kernel images for virtualized targets.
- **ops deployment**: external delivery tool · Builds, runs, and deploys images to local and cloud virtual environments.

### Boot & Kernel Core

- [Platform boot](https://github.com/nanovms/nanos/blob/master/platform/pc/boot/stage1.s): bootloader · Loads the kernel and supplies target machine services. · `platform/pc/boot/stage1.s`
- [CPU initialization](https://github.com/nanovms/nanos/blob/master/src/x86_64/crt0.s): architecture CRT · Establishes CPU state before kernel startup. · `src/x86_64/crt0.s`
- [Kernel lifecycle](https://github.com/nanovms/nanos/blob/master/src/kernel/init.c): kernel initialization · Stages initialization, scheduling, PCI, storage, and logging. · `src/kernel/init.c`
- [Memory core](https://github.com/nanovms/nanos/blob/master/src/kernel/page.c): page and heap management · Provides physical, virtual, and heap allocation services. · `src/kernel/page.c`

### Runtime & Unix ABI

- [Generic runtime](https://github.com/nanovms/nanos/blob/master/src/runtime/runtime_init.c): runtime foundation · Supplies buffers, timers, closures, heaps, and shared primitives. · `src/runtime/runtime_init.c`
- [Single-process Unix ABI](https://github.com/nanovms/nanos/blob/master/src/unix/unix.c): Linux-like ABI · Provides syscalls, ELF execution, threads, mappings, files, signals, and async I/O. · `src/unix/unix.c`
- [Application entry glue](https://github.com/nanovms/nanos/blob/master/src/x86_64/unix_machine.c): Unix machine layer · Transfers into the application under the one-application model. · `src/x86_64/unix_machine.c`

### Devices, Storage & Network

- [Hardware discovery](https://github.com/nanovms/nanos/blob/master/src/drivers/acpi.c): ACPI, DT, PCI · Discovers machine devices and routes driver binding. · `src/drivers/acpi.c`
- [VirtIO transport](https://github.com/nanovms/nanos/blob/master/src/virtio/virtio.c): paravirtual I/O · Portable transport for network, block, socket, 9P, SCSI, RNG, and balloon devices. · `src/virtio/virtio.c`
- [Cloud hypervisor drivers](https://github.com/nanovms/nanos/blob/master/src/aws/ena/ena.c): native/paravirtual drivers · Supports AWS ENA, Hyper-V, VMware, Xen, and native devices. · `src/aws/ena/ena.c`
- [Storage stack](https://github.com/nanovms/nanos/blob/master/src/kernel/storage.c): block I/O · Connects block transports to filesystem services. · `src/kernel/storage.c`
- [Filesystem layer](https://github.com/nanovms/nanos/blob/master/src/fs/fs.c): TFS and file services · Hosts TFS with optional 9P and tmpfs services. · `src/fs/fs.c`
- [Network stack](https://github.com/nanovms/nanos/blob/master/src/net/net.c): lwIP integration · Provides direct networking and Unix socket adapters. · `src/net/net.c`

### Cloud & Observability

- [Cloud image services](https://github.com/nanovms/nanos/blob/master/klib/cloud_init.c): external-service integration · Provides cloud-init, metadata, cloud APIs, TLS, and S3 filesystem support. · `klib/cloud_init.c`
- [Debug & management](https://github.com/nanovms/nanos/blob/master/src/kernel/tracelog.c): observability interfaces · Provides tracing, GDB remote support, telnet management, and logs. · `src/kernel/tracelog.c`

## Connections

- 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
