Files
kubesolo-os/build/scripts/extract-core.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

84 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# extract-core.sh — Extract Tiny Core Linux rootfs from ISO
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
CACHE_DIR="${CACHE_DIR:-$PROJECT_ROOT/build/cache}"
ROOTFS_DIR="${ROOTFS_DIR:-$PROJECT_ROOT/build/rootfs-work}"
# shellcheck source=../config/versions.env
. "$SCRIPT_DIR/../config/versions.env"
TC_ISO="$CACHE_DIR/$TINYCORE_ISO"
ISO_MNT="$ROOTFS_DIR/iso-mount"
if [ ! -f "$TC_ISO" ]; then
echo "ERROR: Tiny Core ISO not found: $TC_ISO"
echo "Run 'make fetch' first."
exit 1
fi
# Clean previous rootfs
rm -rf "$ROOTFS_DIR"
mkdir -p "$ROOTFS_DIR" "$ISO_MNT"
# --- Mount ISO and extract kernel + initramfs ---
echo "==> Mounting ISO: $TC_ISO"
mount -o loop,ro "$TC_ISO" "$ISO_MNT" 2>/dev/null || {
# Fallback for non-root: use 7z or bsdtar
echo " mount failed (need root?), trying bsdtar..."
mkdir -p "$ISO_MNT"
bsdtar xf "$TC_ISO" -C "$ISO_MNT" 2>/dev/null || {
echo " bsdtar failed, trying 7z..."
7z x -o"$ISO_MNT" "$TC_ISO" >/dev/null 2>&1
}
}
# Find vmlinuz and core.gz (path varies by Tiny Core version/arch)
VMLINUZ=""
COREGZ=""
for f in "$ISO_MNT"/boot/vmlinuz64 "$ISO_MNT"/boot/vmlinuz; do
[ -f "$f" ] && VMLINUZ="$f" && break
done
for f in "$ISO_MNT"/boot/corepure64.gz "$ISO_MNT"/boot/core.gz; do
[ -f "$f" ] && COREGZ="$f" && break
done
if [ -z "$VMLINUZ" ] || [ -z "$COREGZ" ]; then
echo "ERROR: Could not find vmlinuz/core.gz in ISO"
echo "ISO contents:"
find "$ISO_MNT" -type f
umount "$ISO_MNT" 2>/dev/null || true
exit 1
fi
echo "==> Found kernel: $VMLINUZ"
echo "==> Found initramfs: $COREGZ"
# Copy kernel
cp "$VMLINUZ" "$ROOTFS_DIR/vmlinuz"
# --- Extract initramfs (core.gz → rootfs) ---
echo "==> Extracting initramfs..."
mkdir -p "$ROOTFS_DIR/rootfs"
cd "$ROOTFS_DIR/rootfs"
zcat "$COREGZ" | cpio -idm 2>/dev/null
# Unmount ISO
cd "$PROJECT_ROOT"
umount "$ISO_MNT" 2>/dev/null || true
rm -rf "$ISO_MNT"
echo "==> Rootfs extracted: $ROOTFS_DIR/rootfs"
echo " Size: $(du -sh "$ROOTFS_DIR/rootfs" | cut -f1)"
echo " Kernel: $ROOTFS_DIR/vmlinuz ($(du -h "$ROOTFS_DIR/vmlinuz" | cut -f1))"
# --- Audit kernel config if available ---
if [ -f "$ROOTFS_DIR/rootfs/proc/config.gz" ]; then
echo "==> Kernel config found in rootfs, auditing..."
"$SCRIPT_DIR/../config/kernel-audit.sh" <(zcat "$ROOTFS_DIR/rootfs/proc/config.gz") || true
fi
echo "==> Extract complete."