- Fixed build system to clone source repositories instead of downloading binaries - Enhanced scripts/fetch-github.sh with proper git repo cloning and branch handling - Updated scripts/compile-components.sh for RFS compilation with build-binary feature - Added minimal firmware installation for essential network drivers (73 modules) - Created comprehensive zinit configuration set (15 config files including getty) - Added util-linux package for getty/agetty console support - Optimized package selection for minimal 27MB initramfs footprint - Successfully builds bootable vmlinuz.efi with embedded initramfs - Confirmed working: VM boot, console login, network drivers, zinit init system Components: - initramfs.cpio.xz: 27MB compressed minimal Zero-OS image - vmlinuz.efi: 35MB bootable kernel with embedded initramfs - Complete Zero-OS toolchain: zinit, rfs, mycelium compiled from source
147 lines
5.7 KiB
Markdown
147 lines
5.7 KiB
Markdown
# 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
|
|
```bash
|
|
# Build everything
|
|
./build.sh
|
|
|
|
# Or with Docker Compose
|
|
cd build/
|
|
docker-compose up
|
|
```
|
|
|
|
### Development Build
|
|
```bash
|
|
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)
|
|
```bash
|
|
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
|
|
```bash
|
|
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
|
|
```bash
|
|
# 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:
|
|
```bash
|
|
# 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
|
|
``` |