Alpine-based Zero-OS Initramfs

Modern Alpine Linux based approach to building Zero-OS initramfs with source compilation for Zero-OS components and Alpine packages for system tools.

Architecture Overview

This system uses:

  • Alpine Linux 3.22 as base system with latest packages
  • Individual Rust workspaces with git subtrees for Zero-OS components (zinit, mycelium, rfs)
  • Component-based compilation - each component built in its own workspace
  • Alpine packages for system tools (busybox, openssh, btrfs-progs, etc.)
  • Smart caching with Docker layers and volumes
  • Same init flow as original Zero-OS

Directory Structure

alpine-initramfs/
├── build/                     # Build orchestration
│   ├── Dockerfile.alpine      # Alpine build environment
│   ├── Dockerfile.cached      # Multi-stage cached build
│   └── docker-compose.yml     # Build orchestration with caching
├── components/                # Git subtrees (individual workspaces)
│   ├── zinit/                 # Init system (Rust subtree with workspace)
│   ├── mycelium/              # Networking layer (Rust subtree with workspace)
│   └── rfs/                   # Filesystem (Rust subtree with workspace)
├── configs/                   # Configuration files
│   ├── packages-alpine.txt    # Alpine packages to install
│   ├── kernel-version         # Kernel version to build
│   ├── kernel-config-generic  # Kernel configuration
│   ├── init                   # Init script (Alpine → zinit)
│   └── zinit/                 # Zinit service configurations
├── scripts/                   # Build scripts
│   ├── build-initramfs.sh     # Main build orchestrator
│   ├── compile-components.sh  # Compile Rust workspace
│   ├── fetch-github.sh        # Download CoreX binary
│   ├── install-packages.sh    # Install Alpine packages
│   ├── setup-initramfs.sh     # Create initramfs structure
│   ├── build-kernel.sh        # Build kernel with embedded initramfs
│   ├── build-smart.sh         # Smart build with caching
│   └── cleanup.sh             # Clean build artifacts
├── target/                    # Rust workspace build artifacts
├── output/                    # Final build outputs
│   ├── vmlinuz.efi            # Final bootable kernel
│   ├── initramfs.cpio.xz      # Generated initramfs
│   └── version.txt            # Build information
└── docs/                      # Documentation
    ├── BUILD.md               # Build process guide
    ├── OVERVIEW.md            # Architecture overview
    └── *.md                   # Additional documentation

Build Flow

  1. Environment Setup: Alpine Docker container with Rust and build tools
  2. Component Compilation: Individual cargo builds for each Rust component
  3. Binary Downloads: Download CoreX (Go binary) from GitHub releases
  4. Package Installation: Install Alpine packages to initramfs root
  5. Initramfs Assembly: Create filesystem structure with compiled binaries
  6. Kernel Build: Compile kernel with embedded initramfs
  7. Output: Generate bootable vmlinuz.efi

Quick Start

Full Build

# Build everything
./build.sh

# Or with Docker Compose
cd build/
docker-compose up

Development Build

cd build/
# Interactive development shell
docker-compose run dev-shell

# Build all components (automated)
../scripts/compile-components.sh

# Build individual components manually:
cd ../components/zinit && cargo build --release --target x86_64-unknown-linux-musl
cd ../components/mycelium && cargo build --release --target x86_64-unknown-linux-musl
cd ../components/rfs && cargo build --release --target x86_64-unknown-linux-musl

Smart Build (with caching)

cd build/
docker-compose run builder  # Uses build-smart.sh automatically

Key Features

  • Component workspaces - Each component maintains its own workspace
  • Git subtrees - Source code included, no submodule complexity
  • Automated build - scripts/compile-components.sh builds all components
  • Shared target directory - Efficient build artifact sharing
  • Smart caching - Docker layer and volume caching for fast rebuilds
  • Alpine packages - System tools from Alpine repositories
  • Development mode - Full IDE support and integrated tooling
  • Same functionality - 100% compatible with original Zero-OS

Development

Building Individual Components

cd build/
docker-compose run dev-shell

# Inside container - build all components:
../scripts/compile-components.sh

# Or build specific components manually:
cd ../components/zinit && cargo build --release --target x86_64-unknown-linux-musl
cd ../components/mycelium/myceliumd && cargo build --release --target x86_64-unknown-linux-musl
cd ../components/rfs && cargo build --release --target x86_64-unknown-linux-musl

Cleanup

# Clean all build artifacts
./scripts/cleanup.sh

Cache Management

Smart build uses Docker volumes for caching:

  • build-cache: Build state markers
  • source-cache: Downloaded sources
  • kernel-cache: Kernel builds
  • target-cache: Rust workspace build artifacts

Updating Components

Update git subtree components:

# Update zinit to latest
git subtree pull --prefix=components/zinit https://github.com/threefoldtech/zinit.git master --squash

# Update mycelium to latest
git subtree pull --prefix=components/mycelium https://github.com/threefoldtech/mycelium.git master --squash

# Update rfs to latest
git subtree pull --prefix=components/rfs https://github.com/threefoldtech/rfs.git master --squash
Description
dockerized/podman-ized build system for zos, based on Alpine pakaging system, zinit and zos-specific binaries
Readme 147 MiB
Languages
Shell 99.5%
Dockerfile 0.5%