No description
Find a file
Jan De Landtsheer 287f8031f2 Increase font sizes in web UI for better readability
- Bump form labels from 10px to 12px
- Enlarge left sidebar headline and navigation pills
- Keep collapsible card layout intact
2025-12-12 15:04:05 +01:00
.forgejo/workflows Use curl API calls instead of Node.js action for releases 2025-12-09 23:08:27 +01:00
docs Implement ADR-0003 code review findings 2025-12-05 08:27:19 +01:00
internal Increase font sizes in web UI for better readability 2025-12-12 15:04:05 +01:00
scripts feat: add kernel caching, debug mode, and hybrid boot improvements 2025-11-05 18:12:15 +01:00
.gitignore Rename binary to mosbootstrap and simplify project structure 2025-12-09 12:56:12 +01:00
ARCHITECTURE.md Rename binary to mosbootstrap and simplify project structure 2025-12-09 12:56:12 +01:00
boot.ipxe Rebrand from Threefold/ZOS to Geomind/MyceliumOS 2025-12-04 13:10:48 +01:00
claude.md Rebrand from Threefold/ZOS to Geomind/MyceliumOS 2025-12-04 13:10:48 +01:00
config.example.toml Rebrand from Threefold/ZOS to Geomind/MyceliumOS 2025-12-04 13:10:48 +01:00
CONFIG.md docs: add configuration example and documentation 2025-10-23 11:06:39 +02:00
DEVGUIDE.md Rebrand from Threefold/ZOS to Geomind/MyceliumOS 2025-12-04 13:10:48 +01:00
go.mod Implement ADR-0003 code review findings 2025-12-05 08:27:19 +01:00
go.sum Implement ADR-0003 code review findings 2025-12-05 08:27:19 +01:00
main.go Redesign web UI with Geomind branding and fix iPXE build 2025-12-11 23:54:53 +01:00
Makefile Rename binary to mosbootstrap and simplify project structure 2025-12-09 12:56:12 +01:00
README.md Fix repo name: mosbootstrap -> mos_bootstrap 2025-12-04 13:42:00 +01:00

MOS Bootstrap Web Generator

A self-contained Go-based iPXE bootblock generation service for Geomind MyceliumOS. This 2MB single ipxe image or a 70MB full MyceliumOS creates customized boot artifacts (iPXE scripts, UEFI binaries, ISO images, USB images, LKRN kernels) with configurable parameters including farm ID, kernel URLs, run modes, console targets, and kernel flags.

Features

  • Fully Self-Contained: Single 20MB binary with all assets embedded - zero external dependencies
  • Auto-Extraction: Automatically extracts documentation, configuration, and build tools on first run
  • Smart Caching: Reuses build artifacts with per-target locking for 10x faster subsequent builds
  • Web UI: Interactive Alpine.js-powered two-tab interface for artifact generation
  • Customizable Kernel URLs: Configure custom kernel download servers and filenames
  • Multiple Formats: UEFI binaries, ISO images, USB images, LKRN kernels, iPXE scripts, Full MyceliumOS images
  • Full MyceliumOS: Hybrid BIOS+EFI bootable USB images with embedded kernel for offline boot (use when iPXE doesn't work with recent NICs or UEFI signing issues)
  • HTTPS Boot: Automatically includes Let's Encrypt certificates for secure boot
  • Always Documented: README and config template auto-extract with binary

Quick Start

One-Line Deployment

# Download, run, and access web UI
wget https://git.ourworld.tf/geomind_code/mos_bootstrap/releases/latest/mosbootstrap
chmod +x mosbootstrap
./mosbootstrap &
open http://localhost:8080

That's it! The binary automatically extracts all required files on first run.

What Happens on First Run

./mosbootstrap

Auto-Extraction (happens once):

✓ README.md → Documentation (you're reading it!)
✓ config.example.toml → Configuration template
✓ boot.ipxe → Customizable boot script template
✓ build/ipxe/ → Complete iPXE source tree (923 files, ~50MB)

Result:


Architecture

Self-Contained Design

mosbootstrap (20MB)
├── Embedded Assets
│   ├── boot.ipxe → Auto-extracts to project root
│   ├── README.md → Auto-extracts to project root
│   ├── config.example.toml → Auto-extracts to project root
│   ├── HTML templates → Loaded in memory
│   ├── Static CSS/JS → Served from memory
│   └── iPXE source tree (4.8MB compressed) → Extracts to build/ipxe/
│
└── Self-Extracting Runtime
    ├── Checks for missing files
    ├── Extracts only what's needed
    ├── Preserves existing customizations
    └── Starts web server

Directory Structure (After First Run)

project/
├── mosbootstrap           # 20MB self-contained binary
├── README.md               # This file (auto-extracted)
├── config.example.toml     # Configuration template (auto-extracted)
├── boot.ipxe              # Boot script template (auto-extracted, customizable)
└── build/
    └── ipxe/              # iPXE source tree (auto-extracted, ~50MB)
        └── src/
            ├── Makefile   # Build system
            ├── config/    # iPXE configuration
            └── ...        # 923 source files

Installation

# Download latest release
wget https://git.ourworld.tf/geomind_code/mos_bootstrap/releases/latest/mosbootstrap

# Make executable
chmod +x mosbootstrap

# Run (auto-extracts everything)
./mosbootstrap

# Access web UI
open http://localhost:8080

Option 2: Build from Source

# Clone repository
git clone https://git.ourworld.tf/geomind_code/mos_bootstrap.git
cd mosbootstrap

# Generate iPXE tarball (only if build/ipxe updated)
go generate ./internal/assets/embed

# Build binary
go build -o mosbootstrap ./cmd/mosbootstrap

# Run
./mosbootstrap

Usage

Web Interface

  1. Open http://localhost:8080
  2. Choose tab:
    • iPXE Image: Network-based boot (requires internet at boot time)
      • Artifacts are designed for iPXE servers but can also be written to USB sticks
    • Full MyceliumOS: Self-contained offline-bootable image with embedded kernel
      • Use when iPXE doesn't work with recent NICs or UEFI signing issues occur
  3. Select artifact type:
    • iPXE Tab: UEFI, iPXE Script, ISO, USB, LKRN
    • Full MyceliumOS Tab: Hybrid BIOS+EFI USB image
  4. Configure parameters:
    • Farm ID (required): Your Geomind farm identifier
    • Version: prod/test/dev (default: prod)
    • Kernel URL: Base URL for kernel downloads (default: https://mos.grid.tf)
    • Advanced Settings (click to expand):
      • Kernel Path (default: kernel)
      • Kernel Filename (default: mos-latest.efi)
    • Console: Serial/video console target
    • Kernel Parameters: Additional boot parameters
  5. Click Generate
  6. Download artifact or copy iPXE script

Command Line

# Basic usage
./mosbootstrap

# Custom port
./mosbootstrap --port 3000

# With configuration file
./mosbootstrap --config config.toml

# Override iPXE source location
./mosbootstrap --ipxe-template /custom/ipxe

# Show all options
./mosbootstrap --help

API Usage

See complete API documentation: docs/API.md

Quick Example:

# Generate UEFI binary
curl -X POST http://localhost:8080/generate/uefi \
  -H "Content-Type: application/json" \
  -d '{"farmId":"12345"}' \
  -o boot-12345.efi

# Generate with custom kernel URL
curl -X POST http://localhost:8080/generate/uefi \
  -H "Content-Type: application/json" \
  -d '{
    "farmId":"12345",
    "kernelUrl":"https://custom-mirror.com",
    "kernelFilename":"mos-v3.5.0.efi"
  }' \
  -o boot-12345.efi

Configuration

Environment Variables

# HTTP server port
export PORT=8080

# Generator workspace directory
export GENERATOR_WORK_DIR=/tmp/bootstrap-work

# Override make environment
export GENERATOR_MAKE_ENV="CC=gcc,CFLAGS=-O2"

Configuration File

Create config.toml from the auto-extracted template:

cp config.example.toml config.toml
vim config.toml
[server]
port = "8080"

[generator]
ipxe_template_dir = "build/ipxe"
work_dir = "/tmp/bootstrap-work"
make_env = []

Customizing the Boot Script

The boot script is auto-extracted to boot.ipxe:

# Edit boot script
vim boot.ipxe

# Changes take effect immediately (no rebuild needed)
systemctl restart mosbootstrap

API Reference

POST /generate/{kind}

Generate a boot artifact with custom parameters.

Parameters:

Field Type Required Default Description
farmId string Yes - Geomind farm ID
version string No "prod" MyceliumOS version
kernelUrl string No "https://mos.grid.tf" Kernel server base URL
kernelFilename string No "mos-latest.efi" Kernel filename
console string No "" Console device
nomodeset boolean No false Disable KMS
extra string No "" Extra kernel params

Examples: See docs/api-examples.http for complete request templates.

Full Documentation: docs/API.md


Kernel URL Configuration

Default Configuration

  • Base URL: https://mos.grid.tf
  • Filename: mos-latest.efi
  • Full Path: https://mos.grid.tf/kernel/mos-latest.efi

Custom Kernel Server

{
  "farmId": "12345",
  "kernelUrl": "https://mirror.example.com",
  "kernelFilename": "custom-kernel.efi"
}

Downloads from: https://mirror.example.com/kernel/custom-kernel.efi

Specific Kernel Version

{
  "farmId": "12345",
  "kernelFilename": "mos-v3.5.0-rc2.efi"
}

Downloads from: https://mos.grid.tf/kernel/mos-v3.5.0-rc2.efi


Asset Management

Embedded Assets

All assets are embedded in the 20MB binary:

Asset Size Auto-Extract Purpose
boot.ipxe ~3KB Yes → root Boot script template
README.md ~12KB Yes → root Documentation
config.example.toml ~2.4KB Yes → root Config template
HTML templates ~17KB No (memory) Web UI rendering
Static CSS/JS ~1KB No (memory) Web UI styling
iPXE source 4.8MB Yes → build/ipxe/ Binary builds

Auto-Extraction Behavior

First Run (files missing):

./mosbootstrap
# Extracts: boot.ipxe, README.md, config.example.toml, build/ipxe/
# Logs: "extracted successfully"

Subsequent Runs (files exist):

./mosbootstrap
# Uses existing files
# Logs: "found at <path>"
# Starts instantly

Customization Preserved:

# Your edits are NEVER overwritten
vim boot.ipxe  # Make custom changes
./mosbootstrap  # Uses your custom boot.ipxe

Development

Building

# Regular build
go build -o mosbootstrap ./cmd/mosbootstrap

# With updated iPXE source
go generate ./internal/assets/embed
go build -o mosbootstrap ./cmd/mosbootstrap

# Run tests
go test ./...

# Static analysis
go vet ./...

Updating Embedded Assets

Update Boot Template:

vim internal/assets/embed/boot.ipxe
go build -o mosbootstrap ./cmd/mosbootstrap

Update HTML Templates:

vim internal/assets/embed/templates/landing.tmpl
go build -o mosbootstrap ./cmd/mosbootstrap

Update iPXE Source:

cd build/ipxe
git pull  # or manual updates
cd ../..
go generate ./internal/assets/embed
go build -o mosbootstrap ./cmd/mosbootstrap

Project Structure

mosbootstrap/
├── cmd/mosbootstrap/          # Main application
├── internal/
│   ├── assets/
│   │   ├── embed/              # All embeddable assets
│   │   │   ├── boot.ipxe       # Boot template
│   │   │   ├── README.md       # This file
│   │   │   ├── config.example.toml
│   │   │   ├── templates/      # HTML templates
│   │   │   ├── static/         # CSS/JS
│   │   │   ├── ipxe_src.tgz    # Compressed iPXE (4.8MB)
│   │   │   ├── assets.go       # Embed directives
│   │   │   └── generate.go     # Tarball generation
│   │   └── provider.go         # Auto-extraction logic
│   ├── generator/              # Build orchestration
│   │   ├── generator.go
│   │   ├── types.go
│   │   └── extra.go
│   └── handlers/               # HTTP handlers
│       └── landing.go
├── docs/
│   ├── API.md                  # Complete API documentation
│   ├── api-examples.http       # REST client templates
│   └── adr/                    # Architecture decision records
├── build/
│   └── ipxe/                   # iPXE source (auto-extracted)
├── README.md                   # This file (auto-extracted)
└── config.example.toml         # Config template (auto-extracted)

Deployment

Systemd Service

[Unit]
Description=MyceliumOS Bootstrap Service
After=network.target

[Service]
Type=simple
User=bootstrap
WorkingDirectory=/opt/mosbootstrap
ExecStart=/opt/mosbootstrap/mosbootstrap
Restart=always
RestartSec=10

# Environment variables (optional)
Environment="PORT=8080"
Environment="GENERATOR_WORK_DIR=/var/cache/mosbootstrap"

[Install]
WantedBy=multi-user.target

Docker

FROM alpine:latest

# Install iPXE build dependencies
RUN apk add --no-cache build-base make gcc musl-dev xz-dev xorriso syslinux

# Copy binary
COPY mosbootstrap /app/mosbootstrap
WORKDIR /app

# Expose port
EXPOSE 8080

# Run binary (auto-extracts on first run)
CMD ["./mosbootstrap"]

Kubernetes

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mosbootstrap
spec:
  replicas: 3
  selector:
    matchLabels:
      app: mosbootstrap
  template:
    metadata:
      labels:
        app: mosbootstrap
    spec:
      containers:
        - name: mosbootstrap
          image: mosbootstrap:latest
          ports:
            - containerPort: 8080
          env:
            - name: PORT
              value: "8080"
            - name: GENERATOR_WORK_DIR
              value: "/tmp/bootstrap-work"
          resources:
            requests:
              memory: "256Mi"
              cpu: "500m"
            limits:
              memory: "2Gi"
              cpu: "2000m"

Troubleshooting

Build Issues

Problem: First build is slow (30-90 seconds)

✓ Expected behavior - initial make compiles all iPXE objects
✓ Subsequent builds reuse cache (5-10 seconds)

Problem: "iPXE source tree not found"

# Source auto-extracts on first run
# If extraction failed, check permissions:
ls -la build/ipxe/src/Makefile

# Force re-extraction:
rm -rf build/ipxe
./mosbootstrap

Problem: Certificate download errors

# Generator auto-downloads Let's Encrypt certs
# If blocked, manually place in build/ipxe/src/:
# - isrgrootx1.pem
# - lets-encrypt-r3-cross-signed.pem
# - lets-encrypt-r3.pem

Runtime Issues

Problem: Port already in use

# Use different port
./mosbootstrap --port 8081

# Or set environment
export PORT=8081
./mosbootstrap

Problem: "failed to extract tarball"

# Check write permissions
chmod 755 .
mkdir -p build

# Check disk space
df -h .

Problem: Slow generation requests

# First request per artifact type is slower (compiles iPXE)
# Subsequent requests are fast (reuse workspace)

# Check logs for actual build time:
tail -f /var/log/mosbootstrap.log

Boot Issues

Problem: iPXE not working on recent hardware

# Recent NICs or UEFI firmware may have issues with iPXE
# Solution: Use the "Full MyceliumOS" tab to generate a bootable image with embedded kernel

# The Full MyceliumOS option provides:
# - Offline boot capability (no network required)
# - Better compatibility with recent NICs
# - Works around UEFI signing issues with iPXE binaries

Problem: Need to boot without network connectivity

# iPXE artifacts require network at boot time
# Solution: Use "Full MyceliumOS" tab for offline-bootable USB images
# This embeds the kernel directly in the bootable image

Customization Issues

Problem: Custom boot.ipxe not being used

# Verify file exists and location is correct
ls -la boot.ipxe  # Should be in working directory

# Check logs for which file is loaded
./mosbootstrap 2>&1 | grep "boot template"

Problem: Changes to boot.ipxe not taking effect

# Restart the service
systemctl restart mosbootstrap

# Or if running in foreground
# Stop (Ctrl+C) and restart
./mosbootstrap

API Documentation

Complete Reference

See docs/API.md for comprehensive API documentation including:

  • Full endpoint reference
  • Request/response schemas
  • Error codes and handling
  • Integration examples (Python, JavaScript, Go, Bash)
  • OpenAPI 3.0 specification
  • Security considerations

Quick API Examples

Generate UEFI Binary:

curl -X POST http://localhost:8080/generate/uefi \
  -H "Content-Type: application/json" \
  -d '{"farmId":"12345"}' \
  -o boot-12345.efi

Custom Kernel URL:

curl -X POST http://localhost:8080/generate/uefi \
  -H "Content-Type: application/json" \
  -d '{
    "farmId":"12345",
    "kernelUrl":"https://mirror.example.com",
    "kernelFilename":"mos-v3.5.0.efi"
  }' \
  -o boot-12345.efi

More Examples: See docs/api-examples.http for ready-to-use REST client templates


Performance

Binary Size

  • Total: 20MB
  • Code: ~15MB
  • Embedded Assets: ~5MB (4.8MB iPXE + 35KB other)

Startup Time

  • First run: ~3 seconds (includes file extraction)
  • Subsequent: <100ms (no extraction)

Build Performance

Artifact First Build Cached Build
iPXE script <1 second <1 second
UEFI binary 30-90 seconds 5-10 seconds
ISO image 30-90 seconds 5-10 seconds
USB image 30-90 seconds 5-10 seconds
LKRN kernel 30-90 seconds 5-10 seconds

Concurrent Builds

  • Safe: Per-target workspace locking
  • Efficient: Different targets build in parallel
  • Cached: Reuses compiled objects across requests

Customization

Boot Script Template

Edit the auto-extracted boot.ipxe:

vim boot.ipxe

Available Template Variables:

  • {{release}} - MyceliumOS release name
  • {{farmerid}} - Farm ID from request
  • {{parameters}} - All kernel parameters
  • {{kernel}} - Full kernel download URL
  • {{cmdline}} - Kernel command line

Example Customization:

#!ipxe
echo Custom boot screen
echo Farm: {{farmerid}}
echo Release: {{release}}

imgfetch {{kernel}} {{cmdline}}
imgexec

Kernel URL Configuration

Web UI: Enter custom URL in "Kernel URL Base" field

API: Include in request:

{
  "farmId": "12345",
  "kernelUrl": "https://your-mirror.com",
  "kernelFilename": "custom-kernel.efi"
}

Result: Downloads from https://your-mirror.com/kernel/custom-kernel.efi


File Naming Convention

All artifacts follow consistent naming:

Type Format Example
UEFI boot-{farmid}.efi boot-12345.efi
ISO boot-{farmid}.iso boot-12345.iso
USB boot-{farmid}.img boot-12345.img
LKRN boot-{farmid}.lkrn boot-12345.lkrn
iPXE bootstrap-{version}.ipxe bootstrap-prod.ipxe
Full OS boot-{farmid}-full.img boot-12345-full.img

Prerequisites

For Running (Production)

  • iPXE Images: None! Binary is completely self-contained
  • Full MyceliumOS Images: GRUB tools and partition utilities required:
    • parted - Partition management
    • grub-pc-bin - GRUB for BIOS boot
    • grub-efi-amd64-bin - GRUB for EFI boot
    • dosfstools - FAT32 formatting
    • mtools - FAT filesystem operations

For Building (Development)

  • Go 1.22+
  • iPXE build dependencies: build-essential, make, gcc, liblzma-dev, xorriso, isolinux

Installing Runtime Dependencies

Ubuntu/Debian (for Full MyceliumOS generation):

sudo apt-get update
sudo apt-get install -y parted grub-pc-bin grub-efi-amd64-bin dosfstools mtools

Alpine Linux (for Full MyceliumOS generation):

apk add --no-cache parted grub grub-efi dosfstools mtools

Installing Build Dependencies

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install -y build-essential make gcc liblzma-dev xorriso isolinux

Alpine Linux:

apk add --no-cache build-base make gcc musl-dev xz-dev xorriso syslinux

Red Hat/CentOS:

sudo yum groupinstall "Development Tools"
sudo yum install syslinux genisoimage

macOS:

brew install make gcc

Security Considerations

Production Deployment

Recommended:

  1. Rate Limiting: Limit requests per IP
  2. Input Validation: Strictly validate all parameters
  3. URL Whitelist: Whitelist allowed kernel URLs
  4. HTTPS: Use HTTPS with valid certificates
  5. Authentication: Add API key or OAuth
  6. Logging: Log all generation requests
  7. Monitoring: Monitor for abuse patterns

Example NGINX Reverse Proxy:

upstream mosbootstrap {
    server localhost:8080;
}

server {
    listen 443 ssl http2;
    server_name bootstrap.example.com;

    ssl_certificate /etc/ssl/certs/bootstrap.crt;
    ssl_certificate_key /etc/ssl/private/bootstrap.key;

    location / {
        proxy_pass http://mosbootstrap;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;

        # Rate limiting
        limit_req zone=api burst=10 nodelay;
    }
}

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (go test ./...)
  5. Run static analysis (go vet ./...)
  6. Commit changes (git commit -m 'feat: add amazing feature')
  7. Push to branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Development Workflow

# Make code changes
vim internal/generator/generator.go

# Test changes
go test ./internal/generator

# Build
go build -o mosbootstrap ./cmd/mosbootstrap

# Test locally
./mosbootstrap

Support & Resources


License

Apache 2.0 - Same as the original Geomind bootstrap tooling.


Changelog

v1.1.0 (Latest)

  • Self-contained binary with full asset embedding
  • Automatic extraction of documentation and configuration
  • Customizable kernel URL and filename
  • Complete API documentation
  • Consistent file naming (boot-{farmid}.ext)
  • Updated default kernel URL (mos.grid.tf)

v1.0.0

  • Initial release
  • Web UI for artifact generation
  • Support for UEFI, ISO, USB, LKRN, iPXE artifacts
  • Basic kernel parameter configuration