Files
kubesolo-os/init/init.sh
Adolfo Delorenzo e372df578b feat: initial Phase 1 PoC scaffolding for KubeSolo OS
Complete Phase 1 implementation of KubeSolo OS — an immutable, bootable
Linux distribution built on Tiny Core Linux for running KubeSolo
single-node Kubernetes.

Build system:
- Makefile with fetch, rootfs, initramfs, iso, disk-image targets
- Dockerfile.builder for reproducible builds
- Scripts to download Tiny Core, extract rootfs, inject KubeSolo,
  pack initramfs, and create bootable ISO/disk images

Init system (10 POSIX sh stages):
- Early mount (proc/sys/dev/cgroup2), cmdline parsing, persistent
  mount with bind-mounts, kernel module loading, sysctl, DHCP
  networking, hostname, clock sync, containerd prep, KubeSolo exec

Shared libraries:
- functions.sh (device wait, IP lookup, config helpers)
- network.sh (static IP, config persistence, interface detection)
- health.sh (containerd, API server, node readiness checks)
- Emergency shell for boot failure debugging

Testing:
- QEMU boot test with serial log marker detection
- K8s readiness test with kubectl verification
- Persistence test (reboot + verify state survives)
- Workload deployment test (nginx pod)
- Local storage test (PVC + local-path provisioner)
- Network policy test
- Reusable run-vm.sh launcher

Developer tools:
- dev-vm.sh (interactive QEMU with port forwarding)
- rebuild-initramfs.sh (fast iteration)
- inject-ssh.sh (dropbear SSH for debugging)
- extract-kernel-config.sh + kernel-audit.sh

Documentation:
- Full design document with architecture research
- Boot flow documentation covering all 10 init stages
- Cloud-init examples (DHCP, static IP, Portainer Edge, air-gapped)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 10:18:42 -06:00

88 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
# /sbin/init — KubeSolo OS init system
# POSIX sh compatible (BusyBox ash)
#
# Boot stages are sourced from /usr/lib/kubesolo-os/init.d/ in numeric order.
# Each stage file must be a valid POSIX sh script.
# If any mandatory stage fails, the system drops to an emergency shell.
#
# Boot parameters (from kernel command line):
# kubesolo.data=<device> Persistent data partition (required)
# kubesolo.debug Enable verbose logging
# kubesolo.shell Drop to emergency shell immediately
# kubesolo.nopersist Run without persistent storage (RAM only)
# kubesolo.cloudinit=<path> Path to cloud-init config
# kubesolo.flags=<flags> Extra flags for KubeSolo binary
set -e
# --- Constants ---
INIT_LIB="/usr/lib/kubesolo-os"
INIT_STAGES="/usr/lib/kubesolo-os/init.d"
LOG_PREFIX="[kubesolo-init]"
DATA_MOUNT="/mnt/data"
# --- Parsed boot parameters (populated by 10-parse-cmdline.sh) ---
export KUBESOLO_DATA_DEV=""
export KUBESOLO_DEBUG=""
export KUBESOLO_SHELL=""
export KUBESOLO_NOPERSIST=""
export KUBESOLO_CLOUDINIT=""
export KUBESOLO_EXTRA_FLAGS=""
# --- Logging ---
log() {
echo "$LOG_PREFIX $*" >&2
}
log_ok() {
echo "$LOG_PREFIX [OK] $*" >&2
}
log_err() {
echo "$LOG_PREFIX [ERROR] $*" >&2
}
log_warn() {
echo "$LOG_PREFIX [WARN] $*" >&2
}
# --- Emergency shell ---
emergency_shell() {
log_err "Boot failed: $*"
log_err "Dropping to emergency shell. Type 'exit' to retry boot."
exec /bin/sh
}
# --- Main boot sequence ---
log "KubeSolo OS v$(cat /etc/kubesolo-os-version 2>/dev/null || echo 'dev') starting..."
# Source shared functions
if [ -f "$INIT_LIB/functions.sh" ]; then
. "$INIT_LIB/functions.sh"
fi
# Run init stages in order
for stage in "$INIT_STAGES"/*.sh; do
[ -f "$stage" ] || continue
stage_name="$(basename "$stage")"
log "Running stage: $stage_name"
if ! . "$stage"; then
emergency_shell "Stage $stage_name failed"
fi
# Check for early shell request (parsed in 10-parse-cmdline.sh)
if [ "$KUBESOLO_SHELL" = "1" ] && [ "$stage_name" = "10-parse-cmdline.sh" ]; then
log "Emergency shell requested via boot parameter"
exec /bin/sh
fi
log_ok "Stage $stage_name complete"
done
# If we get here, all stages ran but KubeSolo should have exec'd.
# This means 90-kubesolo.sh didn't exec (shouldn't happen).
emergency_shell "Init completed without exec'ing KubeSolo — this is a bug"