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>
This commit is contained in:
75
init/lib/functions.sh
Executable file
75
init/lib/functions.sh
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/bin/sh
|
||||
# functions.sh — Shared utility functions for KubeSolo OS init
|
||||
# Sourced by /sbin/init before running stages
|
||||
# POSIX sh only — must work with BusyBox ash
|
||||
|
||||
# Wait for a block device to appear
|
||||
wait_for_device() {
|
||||
dev="$1"
|
||||
timeout="${2:-30}"
|
||||
i=0
|
||||
while [ "$i" -lt "$timeout" ]; do
|
||||
[ -b "$dev" ] && return 0
|
||||
sleep 1
|
||||
i=$((i + 1))
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Wait for a file to appear
|
||||
wait_for_file() {
|
||||
path="$1"
|
||||
timeout="${2:-30}"
|
||||
i=0
|
||||
while [ "$i" -lt "$timeout" ]; do
|
||||
[ -f "$path" ] && return 0
|
||||
sleep 1
|
||||
i=$((i + 1))
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Get IP address of an interface (POSIX-safe, no grep -P)
|
||||
get_iface_ip() {
|
||||
iface="$1"
|
||||
ip -4 addr show "$iface" 2>/dev/null | \
|
||||
sed -n 's/.*inet \([0-9.]*\).*/\1/p' | head -1
|
||||
}
|
||||
|
||||
# Check if running in a VM (useful for adjusting timeouts)
|
||||
is_virtual() {
|
||||
[ -d /sys/class/dmi/id ] && \
|
||||
grep -qi -e 'qemu' -e 'kvm' -e 'vmware' -e 'virtualbox' -e 'xen' -e 'hyperv' \
|
||||
/sys/class/dmi/id/sys_vendor 2>/dev/null
|
||||
}
|
||||
|
||||
# Resolve a LABEL= or UUID= device spec to a block device path
|
||||
resolve_device() {
|
||||
spec="$1"
|
||||
case "$spec" in
|
||||
LABEL=*) blkid -L "${spec#LABEL=}" 2>/dev/null ;;
|
||||
UUID=*) blkid -U "${spec#UUID=}" 2>/dev/null ;;
|
||||
*) echo "$spec" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Write a key=value pair to a simple config file
|
||||
config_set() {
|
||||
file="$1" key="$2" value="$3"
|
||||
if grep -q "^${key}=" "$file" 2>/dev/null; then
|
||||
sed -i "s|^${key}=.*|${key}=${value}|" "$file"
|
||||
else
|
||||
echo "${key}=${value}" >> "$file"
|
||||
fi
|
||||
}
|
||||
|
||||
# Read a value from a simple key=value config file
|
||||
config_get() {
|
||||
file="$1" key="$2" default="${3:-}"
|
||||
if [ -f "$file" ]; then
|
||||
value=$(sed -n "s/^${key}=//p" "$file" | tail -1)
|
||||
echo "${value:-$default}"
|
||||
else
|
||||
echo "$default"
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user