Initial commit: Alpine Zero-OS initramfs build system with cleaned Docker configuration
This commit is contained in:
179
scripts/build-boot.sh
Executable file
179
scripts/build-boot.sh
Executable file
@@ -0,0 +1,179 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
BOOT_ROOT="/build/boot"
|
||||
OUTPUT_DIR="/build/output"
|
||||
CONFIG_DIR="/build/configs"
|
||||
|
||||
echo "[+] Building minimal boot initramfs..."
|
||||
echo " Target: ~10-20MB embedded in kernel"
|
||||
echo " Purpose: Boot + network + mount Alpine runtime"
|
||||
|
||||
# Clean and create boot root
|
||||
rm -rf "$BOOT_ROOT"
|
||||
mkdir -p "$BOOT_ROOT"
|
||||
|
||||
echo "[+] Installing minimal boot packages..."
|
||||
|
||||
# Set up APK for boot root
|
||||
mkdir -p "$BOOT_ROOT/etc/apk"
|
||||
cp /etc/apk/repositories "$BOOT_ROOT/etc/apk/"
|
||||
|
||||
# Copy APK keys
|
||||
if [ -d /etc/apk/keys ]; then
|
||||
mkdir -p "$BOOT_ROOT/etc/apk/keys"
|
||||
cp /etc/apk/keys/* "$BOOT_ROOT/etc/apk/keys/"
|
||||
fi
|
||||
|
||||
# Create APK database
|
||||
mkdir -p "$BOOT_ROOT/lib/apk/db"
|
||||
mkdir -p "$BOOT_ROOT/var/cache/apk"
|
||||
|
||||
# Install absolute minimal packages
|
||||
echo " Installing boot packages from packages-boot.txt..."
|
||||
apk --root "$BOOT_ROOT" --clean-protected --update-cache --initdb add alpine-baselayout busybox apk-tools musl
|
||||
|
||||
# Install additional boot packages
|
||||
while read -r package; do
|
||||
# Skip comments and empty lines
|
||||
case "$package" in
|
||||
\#*|"") continue ;;
|
||||
esac
|
||||
|
||||
echo " Installing: $package"
|
||||
if apk --root "$BOOT_ROOT" add --no-cache "$package"; then
|
||||
echo " Success: $package"
|
||||
else
|
||||
echo " Warning: Failed to install $package"
|
||||
fi
|
||||
done < "$CONFIG_DIR/packages-boot.txt"
|
||||
|
||||
echo "[+] Installing minimal ethernet drivers..."
|
||||
# Install essential ethernet firmware and drivers using our minimal script
|
||||
INITRAMFS_ROOT="$BOOT_ROOT" /build/scripts/install-firmware-minimal.sh
|
||||
|
||||
echo "[+] Setting up boot filesystem structure..."
|
||||
|
||||
# Create essential directories
|
||||
mkdir -p "$BOOT_ROOT"/{dev,proc,sys,mnt,tmp,var/run,var/log}
|
||||
mkdir -p "$BOOT_ROOT"/{root,home,opt}
|
||||
mkdir -p "$BOOT_ROOT"/mnt/{alpine,debug}
|
||||
|
||||
# Create device nodes
|
||||
echo " Creating device nodes..."
|
||||
[ ! -e "$BOOT_ROOT/dev/console" ] && mknod "$BOOT_ROOT/dev/console" c 5 1
|
||||
[ ! -e "$BOOT_ROOT/dev/null" ] && mknod "$BOOT_ROOT/dev/null" c 1 3
|
||||
[ ! -e "$BOOT_ROOT/dev/zero" ] && mknod "$BOOT_ROOT/dev/zero" c 1 5
|
||||
|
||||
# Set proper permissions
|
||||
chmod 666 "$BOOT_ROOT/dev/null" "$BOOT_ROOT/dev/zero"
|
||||
chmod 600 "$BOOT_ROOT/dev/console"
|
||||
|
||||
echo "[+] Creating boot init script..."
|
||||
# Create minimal init script for mounting Alpine runtime
|
||||
cat > "$BOOT_ROOT/init" << 'EOF'
|
||||
#!/bin/sh
|
||||
# Minimal boot init - establish network and mount Alpine runtime
|
||||
|
||||
echo "[BOOT] Zero-OS minimal boot starting..."
|
||||
|
||||
# Mount essential filesystems
|
||||
mount -t proc proc /proc
|
||||
mount -t sysfs sysfs /sys
|
||||
mount -t devtmpfs devtmpfs /dev
|
||||
|
||||
# Load essential modules
|
||||
echo "[BOOT] Loading ethernet drivers..."
|
||||
modprobe -a e1000 e1000e igb ixgbe r8169 8139too bnx2 tg3 2>/dev/null || true
|
||||
|
||||
# Start eudev for hardware detection
|
||||
echo "[BOOT] Starting hardware detection..."
|
||||
/sbin/udevd --daemon
|
||||
udevadm trigger
|
||||
udevadm settle
|
||||
|
||||
# Network configuration
|
||||
echo "[BOOT] Configuring network..."
|
||||
for iface in $(ls /sys/class/net/ | grep -v lo); do
|
||||
echo " Bringing up interface: $iface"
|
||||
ip link set "$iface" up
|
||||
# Try DHCP with timeout
|
||||
timeout 30 dhcpcd "$iface" && break
|
||||
done
|
||||
|
||||
# Mount Alpine runtime system
|
||||
echo "[BOOT] Mounting Alpine runtime system..."
|
||||
|
||||
# Check for VirtioFS mount (development)
|
||||
if [ -d /sys/fs/virtio_fs ]; then
|
||||
echo " Attempting VirtioFS mount..."
|
||||
mount -t virtiofs alpine-root /mnt/alpine && ALPINE_MOUNTED=true
|
||||
fi
|
||||
|
||||
# If VirtioFS failed, try network mount (production)
|
||||
if [ "$ALPINE_MOUNTED" != "true" ]; then
|
||||
echo " VirtioFS not available, attempting network mount..."
|
||||
# Add network mounting logic here (NFS, HTTP, etc.)
|
||||
echo " Network mount not implemented yet"
|
||||
fi
|
||||
|
||||
# Switch to Alpine runtime if mounted
|
||||
if [ "$ALPINE_MOUNTED" = "true" ]; then
|
||||
echo "[BOOT] Switching to Alpine runtime system..."
|
||||
|
||||
# Move boot mounts to Alpine
|
||||
mount --move /proc /mnt/alpine/proc
|
||||
mount --move /sys /mnt/alpine/sys
|
||||
mount --move /dev /mnt/alpine/dev
|
||||
|
||||
# Switch root to Alpine
|
||||
exec switch_root /mnt/alpine /sbin/zinit
|
||||
else
|
||||
echo "[BOOT] Failed to mount Alpine runtime - dropping to shell"
|
||||
exec /bin/sh
|
||||
fi
|
||||
EOF
|
||||
|
||||
chmod +x "$BOOT_ROOT/init"
|
||||
|
||||
echo "[+] Setting up symlinks..."
|
||||
cd "$BOOT_ROOT"
|
||||
|
||||
# Standard symlinks
|
||||
ln -sf usr/lib lib || true
|
||||
ln -sf usr/lib lib64 || true
|
||||
|
||||
# Fixed run symlink (not circular)
|
||||
mkdir -p run
|
||||
cd var
|
||||
ln -sf ../run run || true
|
||||
cd ..
|
||||
|
||||
echo "[+] Cleaning up boot initramfs..."
|
||||
# Remove unnecessary files
|
||||
rm -rf var/cache/apk/*
|
||||
rm -rf usr/share/doc usr/share/man usr/share/info 2>/dev/null || true
|
||||
|
||||
# Aggressive cleanup for embedded
|
||||
find . -name "*.a" -delete 2>/dev/null || true
|
||||
find . -name "*.la" -delete 2>/dev/null || true
|
||||
|
||||
echo "[+] Creating boot initramfs archive..."
|
||||
cd "$BOOT_ROOT"
|
||||
|
||||
# Create cpio archive
|
||||
find . | cpio -H newc -o > "$OUTPUT_DIR/boot-initramfs.cpio"
|
||||
|
||||
if [ -f "$OUTPUT_DIR/boot-initramfs.cpio" ]; then
|
||||
size=$(stat -c%s "$OUTPUT_DIR/boot-initramfs.cpio")
|
||||
size_mb=$((size / 1024 / 1024))
|
||||
echo "[+] Boot initramfs created: $OUTPUT_DIR/boot-initramfs.cpio (${size_mb}MB)"
|
||||
else
|
||||
echo "[-] Error: Failed to create boot initramfs"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[+] Minimal boot initramfs build complete"
|
||||
echo " Size: ${size_mb}MB (target: ~10-20MB)"
|
||||
echo " Contains: Boot + network + minimal drivers"
|
||||
echo " Purpose: Mount and switch to Alpine runtime"
|
||||
74
scripts/build-initramfs.sh
Executable file
74
scripts/build-initramfs.sh
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "====================================="
|
||||
echo "= Alpine Zero-OS Initramfs Build ="
|
||||
echo "====================================="
|
||||
echo ""
|
||||
|
||||
# DIAGNOSTIC: Check critical dependencies before starting
|
||||
echo "[DEBUG] Checking critical dependencies..."
|
||||
echo "[DEBUG] Current directory: $(pwd)"
|
||||
echo "[DEBUG] Available disk space: $(df -h /build | tail -1)"
|
||||
echo "[DEBUG] Available memory: $(free -h)"
|
||||
echo "[DEBUG] Network connectivity: $(ping -c 1 8.8.8.8 >/dev/null 2>&1 && echo 'OK' || echo 'FAILED')"
|
||||
echo "[DEBUG] GitHub API access: $(curl -s https://api.github.com/repos/threefoldtech/zinit/releases/latest >/dev/null 2>&1 && echo 'OK' || echo 'FAILED')"
|
||||
echo "[DEBUG] Zinit config mount check: $(ls -la /mnt/zinit 2>/dev/null | wc -l) files"
|
||||
echo "[DEBUG] APK repositories: $(apk update >/dev/null 2>&1 && echo 'OK' || echo 'FAILED')"
|
||||
echo ""
|
||||
|
||||
# Source configuration
|
||||
if [ -f /build/build.conf ]; then
|
||||
. /build/build.conf
|
||||
else
|
||||
echo "Error: build.conf not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[+] Build mode: $BUILDMODE"
|
||||
echo "[+] Target arch: $TARGETARCH"
|
||||
echo "[+] Output directory: $OUTPUT_DIR"
|
||||
echo ""
|
||||
|
||||
# Ensure output directory exists
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
# Phase 1: Install Alpine packages to initramfs
|
||||
echo "[+] Installing Alpine packages..."
|
||||
/build/scripts/install-packages.sh
|
||||
|
||||
# Phase 2: Compile Zero-OS components from source (replaces problematic fetch-github)
|
||||
echo "[+] Compiling Zero-OS components..."
|
||||
if [ -f /build/scripts/build-smart.sh ]; then
|
||||
# Use smart build if available (with caching)
|
||||
/build/scripts/build-smart.sh
|
||||
exit $?
|
||||
else
|
||||
# Fallback to direct component compilation
|
||||
/build/scripts/compile-components.sh
|
||||
fi
|
||||
|
||||
# Phase 3: Setup initramfs structure
|
||||
echo "[+] Setting up initramfs structure..."
|
||||
/build/scripts/setup-initramfs.sh
|
||||
|
||||
# Phase 4: Build kernel with embedded initramfs
|
||||
echo "[+] Building kernel..."
|
||||
/build/scripts/build-kernel.sh
|
||||
|
||||
echo ""
|
||||
echo "[+] Build completed successfully!"
|
||||
echo "[+] Output files:"
|
||||
ls -la "$OUTPUT_DIR/"
|
||||
|
||||
# Verify output
|
||||
if [ -f "$OUTPUT_DIR/vmlinuz.efi" ]; then
|
||||
size=$(stat -c%s "$OUTPUT_DIR/vmlinuz.efi")
|
||||
echo "[+] Kernel size: $size bytes"
|
||||
else
|
||||
echo "[-] Error: vmlinuz.efi not found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "[+] Alpine Zero-OS initramfs build complete!"
|
||||
259
scripts/build-kernel.sh
Executable file
259
scripts/build-kernel.sh
Executable file
@@ -0,0 +1,259 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
KERNEL_DIR="/build/kernel"
|
||||
OUTPUT_DIR="/build/output"
|
||||
CONFIG_DIR="/build/configs"
|
||||
|
||||
# Parse command line arguments
|
||||
KERNEL_ONLY=false
|
||||
EMBED_ONLY=false
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--kernel-only)
|
||||
KERNEL_ONLY=true
|
||||
shift
|
||||
;;
|
||||
--embed-only)
|
||||
EMBED_ONLY=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "[+] Building custom Zero-OS kernel..."
|
||||
echo " Mode: $([ "$KERNEL_ONLY" = "true" ] && echo "kernel-only" || [ "$EMBED_ONLY" = "true" ] && echo "embed-only" || echo "full-build")"
|
||||
|
||||
# DIAGNOSTIC: Check prerequisites
|
||||
echo "[DEBUG] Checking kernel build prerequisites..."
|
||||
echo "[DEBUG] Initramfs file exists: $([ -f "$OUTPUT_DIR/initramfs.cpio.xz" ] && echo 'YES' || echo 'NO')"
|
||||
echo "[DEBUG] Kernel config exists: $([ -f "$CONFIG_DIR/kernel-config-generic" ] && echo 'YES' || echo 'NO')"
|
||||
|
||||
# Only check for initramfs if we're doing embedding
|
||||
if [ "$KERNEL_ONLY" != "true" ] && [ ! -f "$OUTPUT_DIR/initramfs.cpio.xz" ]; then
|
||||
echo "[DEBUG] ERROR: Initramfs not found - kernel build will fail"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$CONFIG_DIR/kernel-config-generic" ]; then
|
||||
echo "[DEBUG] ERROR: Kernel config not found - kernel build will fail"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[DEBUG] Initramfs size: $(stat -c%s "$OUTPUT_DIR/initramfs.cpio.xz") bytes"
|
||||
|
||||
# Read kernel version from config
|
||||
if [ -f "$CONFIG_DIR/kernel-version" ]; then
|
||||
KERNEL_VERSION=$(cat "$CONFIG_DIR/kernel-version" | tr -d '\n')
|
||||
echo " Using kernel version from config: $KERNEL_VERSION"
|
||||
else
|
||||
echo " Error: kernel-version config file not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
KERNEL_MAJOR=$(echo $KERNEL_VERSION | cut -d. -f1)
|
||||
KERNEL_URL="https://cdn.kernel.org/pub/linux/kernel/v${KERNEL_MAJOR}.x/linux-${KERNEL_VERSION}.tar.xz"
|
||||
|
||||
echo " Kernel version: $KERNEL_VERSION"
|
||||
echo " Download URL: $KERNEL_URL"
|
||||
|
||||
# Create kernel build directory
|
||||
echo " Setting up kernel build environment..."
|
||||
mkdir -p "$KERNEL_DIR"
|
||||
cd "$KERNEL_DIR"
|
||||
|
||||
# Install kernel build dependencies
|
||||
echo " Installing kernel build dependencies..."
|
||||
apk add --no-cache build-base bc bison flex openssl-dev elfutils-dev \
|
||||
perl linux-headers cpio xz wget
|
||||
|
||||
# Download kernel source if not already present
|
||||
if [ ! -f "linux-${KERNEL_VERSION}.tar.xz" ]; then
|
||||
echo " Downloading Linux kernel ${KERNEL_VERSION}..."
|
||||
wget -q --show-progress "$KERNEL_URL"
|
||||
fi
|
||||
|
||||
# Extract kernel source if not already extracted
|
||||
if [ ! -d "linux-${KERNEL_VERSION}" ]; then
|
||||
echo " Extracting kernel source..."
|
||||
tar -xf "linux-${KERNEL_VERSION}.tar.xz"
|
||||
fi
|
||||
|
||||
cd "linux-${KERNEL_VERSION}"
|
||||
|
||||
# Copy kernel config
|
||||
echo " Setting up kernel configuration..."
|
||||
cp "$CONFIG_DIR/kernel-config-generic" .config
|
||||
|
||||
# Handle different build modes
|
||||
if [ "$KERNEL_ONLY" = "true" ]; then
|
||||
echo " Building kernel only (no initramfs embedding)..."
|
||||
|
||||
# Disable initramfs in config for kernel-only build
|
||||
sed -i 's/CONFIG_INITRAMFS_SOURCE="..\/..\/root"/CONFIG_INITRAMFS_SOURCE=""/' .config
|
||||
|
||||
# Update config and build kernel
|
||||
make olddefconfig
|
||||
make -j$(nproc) bzImage
|
||||
make -j$(nproc) modules
|
||||
|
||||
echo " Kernel built successfully (cached for later embedding)"
|
||||
exit 0
|
||||
|
||||
elif [ "$EMBED_ONLY" = "true" ]; then
|
||||
echo " Embedding initramfs into existing kernel..."
|
||||
|
||||
# The kernel config expects initramfs at "../../root" relative to kernel build directory
|
||||
echo " Extracting initramfs for embedding..."
|
||||
mkdir -p ../../root
|
||||
cd ../../root
|
||||
rm -rf ./*
|
||||
xz -dc "$OUTPUT_DIR/initramfs.cpio.xz" | cpio -id
|
||||
cd "$KERNEL_DIR/linux-${KERNEL_VERSION}"
|
||||
|
||||
# Restore initramfs path in config
|
||||
sed -i 's/CONFIG_INITRAMFS_SOURCE=""/CONFIG_INITRAMFS_SOURCE="..\/..\/root"/' .config
|
||||
|
||||
# Rebuild with embedded initramfs
|
||||
make olddefconfig
|
||||
make -j$(nproc) bzImage
|
||||
|
||||
# Copy final kernel
|
||||
echo " Copying embedded kernel..."
|
||||
cp arch/x86/boot/bzImage "$OUTPUT_DIR/vmlinuz.efi"
|
||||
|
||||
kernel_size=$(stat -c%s "$OUTPUT_DIR/vmlinuz.efi")
|
||||
echo " Embedded kernel created: $(echo "$kernel_size / 1024 / 1024" | bc)MB"
|
||||
exit 0
|
||||
|
||||
else
|
||||
# Full build mode (original behavior)
|
||||
echo " Full build: kernel + embedded initramfs..."
|
||||
|
||||
# The kernel config expects initramfs at "../../root" relative to kernel build directory
|
||||
echo " Setting up initramfs for kernel embedding..."
|
||||
mkdir -p ../../root
|
||||
cd ../../root
|
||||
|
||||
# Extract our initramfs to the location expected by kernel config
|
||||
echo " Extracting initramfs to expected location..."
|
||||
# Remove any existing contents first
|
||||
rm -rf ./*
|
||||
# Extract the initramfs cpio archive
|
||||
xz -dc "$OUTPUT_DIR/initramfs.cpio.xz" | cpio -id
|
||||
|
||||
echo " Initramfs extracted to: $(pwd)"
|
||||
echo " Initramfs contents:"
|
||||
find . -maxdepth 2 -type f -o -type d | head -20
|
||||
|
||||
# Return to kernel source directory
|
||||
cd "$KERNEL_DIR/linux-${KERNEL_VERSION}"
|
||||
|
||||
# Verify kernel config is properly set up
|
||||
echo " Verifying kernel configuration..."
|
||||
if grep -q 'CONFIG_INITRAMFS_SOURCE="../../root"' .config; then
|
||||
echo " ✓ Initramfs source path configured correctly"
|
||||
else
|
||||
echo " ✗ Warning: Initramfs source path not found in config"
|
||||
fi
|
||||
|
||||
if grep -q 'CONFIG_INITRAMFS_COMPRESSION_XZ=y' .config; then
|
||||
echo " ✓ XZ compression enabled"
|
||||
else
|
||||
echo " ✗ Warning: XZ compression not enabled"
|
||||
fi
|
||||
|
||||
# Update config to handle any new options
|
||||
echo " Updating kernel configuration..."
|
||||
make olddefconfig
|
||||
|
||||
# Build the kernel
|
||||
echo " Building kernel with embedded initramfs..."
|
||||
echo " This may take several minutes..."
|
||||
make -j$(nproc) bzImage
|
||||
fi
|
||||
|
||||
# Verify kernel was built
|
||||
if [ ! -f "arch/x86/boot/bzImage" ]; then
|
||||
echo " Error: Kernel build failed - bzImage not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Copy built kernel to output location
|
||||
echo " Installing built kernel..."
|
||||
cp arch/x86/boot/bzImage "$OUTPUT_DIR/vmlinuz.efi"
|
||||
|
||||
# Get kernel size info
|
||||
kernel_size=$(stat -c%s "$OUTPUT_DIR/vmlinuz.efi")
|
||||
initramfs_size=$(stat -c%s "$OUTPUT_DIR/initramfs.cpio.xz")
|
||||
|
||||
echo "[DEBUG] Built kernel size: $kernel_size bytes"
|
||||
echo "[DEBUG] Original initramfs size: $initramfs_size bytes"
|
||||
|
||||
# Create version info file
|
||||
echo " Creating version information..."
|
||||
cat > "$OUTPUT_DIR/version.txt" << EOF
|
||||
Zero-OS Custom Kernel (Linux $KERNEL_VERSION)
|
||||
Built: $(date)
|
||||
Source: $KERNEL_URL
|
||||
Config: kernel-config-generic
|
||||
Initramfs: Embedded during compilation
|
||||
Final size: $kernel_size bytes
|
||||
Original initramfs: $initramfs_size bytes
|
||||
|
||||
Boot Options:
|
||||
Method: Custom kernel with embedded initramfs
|
||||
Usage: Boot vmlinuz.efi directly
|
||||
GRUB: linux vmlinuz.efi
|
||||
No separate initramfs needed
|
||||
|
||||
Build Environment:
|
||||
Alpine Linux $(cat /etc/alpine-release 2>/dev/null || echo 'unknown')
|
||||
GCC: $(gcc --version | head -1)
|
||||
Make: $(make --version | head -1)
|
||||
EOF
|
||||
|
||||
# Build kernel modules
|
||||
echo " Building kernel modules..."
|
||||
make -j$(nproc) modules
|
||||
|
||||
# Install modules to output directory
|
||||
echo " Installing kernel modules..."
|
||||
mkdir -p "$OUTPUT_DIR/modules"
|
||||
make INSTALL_MOD_PATH="$OUTPUT_DIR/modules" modules_install
|
||||
|
||||
# Find the installed module directory
|
||||
MODULE_DIR=$(find "$OUTPUT_DIR/modules/lib/modules" -maxdepth 1 -type d -name "*" | head -1)
|
||||
if [ -n "$MODULE_DIR" ]; then
|
||||
echo " Modules installed to: $MODULE_DIR"
|
||||
echo "Modules: $MODULE_DIR" >> "$OUTPUT_DIR/version.txt"
|
||||
else
|
||||
echo " Warning: No modules installed"
|
||||
fi
|
||||
|
||||
# Clean up intermediate files
|
||||
echo " Cleaning up build artifacts..."
|
||||
cd "$KERNEL_DIR"
|
||||
rm -rf "linux-${KERNEL_VERSION}"
|
||||
rm -f "linux-${KERNEL_VERSION}.tar.xz"
|
||||
|
||||
echo "[+] Custom kernel build completed successfully"
|
||||
echo " Kernel: $OUTPUT_DIR/vmlinuz.efi ($(du -h $OUTPUT_DIR/vmlinuz.efi | cut -f1))"
|
||||
echo " Version: Linux $KERNEL_VERSION Zero-OS"
|
||||
if [ -d "$OUTPUT_DIR/modules" ]; then
|
||||
echo " Modules: $OUTPUT_DIR/modules/ ($(du -sh $OUTPUT_DIR/modules | cut -f1))"
|
||||
fi
|
||||
echo " Method: Custom compilation with embedded initramfs"
|
||||
|
||||
# Final verification
|
||||
if [ ! -f "$OUTPUT_DIR/vmlinuz.efi" ] || [ "$(stat -c%s "$OUTPUT_DIR/vmlinuz.efi")" -eq 0 ]; then
|
||||
echo " Error: Final kernel verification failed" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " ✓ Kernel ready for deployment"
|
||||
106
scripts/build-smart.sh
Executable file
106
scripts/build-smart.sh
Executable file
@@ -0,0 +1,106 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
CACHE_DIR="/build/cache"
|
||||
KERNEL_VERSION=$(cat /build/configs/kernel-version)
|
||||
|
||||
echo "[+] Smart build with Docker layer caching..."
|
||||
|
||||
# Function to check if we need to rebuild a stage
|
||||
needs_rebuild() {
|
||||
local stage="$1"
|
||||
local trigger_files="$2"
|
||||
local cache_marker="$CACHE_DIR/${stage}-marker"
|
||||
|
||||
# If cache marker doesn't exist, rebuild
|
||||
if [ ! -f "$cache_marker" ]; then
|
||||
echo " $stage: No cache marker found, rebuild needed"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Check if any trigger files are newer than cache marker
|
||||
for file in $trigger_files; do
|
||||
if [ -f "$file" ] && [ "$file" -nt "$cache_marker" ]; then
|
||||
echo " $stage: $file changed, rebuild needed"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
echo " $stage: Cache valid, skipping"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Function to mark stage as completed
|
||||
mark_completed() {
|
||||
local stage="$1"
|
||||
mkdir -p "$CACHE_DIR"
|
||||
touch "$CACHE_DIR/${stage}-marker"
|
||||
}
|
||||
|
||||
echo " Checking cache status..."
|
||||
|
||||
# Check each build stage
|
||||
REBUILD_COMPONENTS=false
|
||||
REBUILD_KERNEL=false
|
||||
REBUILD_INITRAMFS=false
|
||||
|
||||
# Components need rebuild if:
|
||||
# - Component source repos have updates (we'll assume weekly refresh)
|
||||
# - compile-components.sh script changed
|
||||
if needs_rebuild "components" "/build/scripts/compile-components.sh"; then
|
||||
REBUILD_COMPONENTS=true
|
||||
fi
|
||||
|
||||
# Kernel needs rebuild if:
|
||||
# - Kernel version changed
|
||||
# - Kernel config changed
|
||||
# - build-kernel.sh script changed
|
||||
if needs_rebuild "kernel" "/build/configs/kernel-version /build/configs/kernel-config-generic /build/scripts/build-kernel.sh"; then
|
||||
REBUILD_KERNEL=true
|
||||
fi
|
||||
|
||||
# Initramfs always rebuilds (it's fast and contains user scripts)
|
||||
REBUILD_INITRAMFS=true
|
||||
|
||||
echo ""
|
||||
echo " Build plan:"
|
||||
echo " Components: $([ "$REBUILD_COMPONENTS" = "true" ] && echo "REBUILD" || echo "CACHED")"
|
||||
echo " Kernel: $([ "$REBUILD_KERNEL" = "true" ] && echo "REBUILD" || echo "CACHED")"
|
||||
echo " Initramfs: REBUILD (always)"
|
||||
echo ""
|
||||
|
||||
# Phase 1: Components (if needed)
|
||||
if [ "$REBUILD_COMPONENTS" = "true" ]; then
|
||||
echo "[+] Building Zero-OS components from source..."
|
||||
/build/scripts/compile-components.sh
|
||||
mark_completed "components"
|
||||
else
|
||||
echo "[+] Using cached Zero-OS components"
|
||||
fi
|
||||
|
||||
# Phase 2: Kernel (if needed)
|
||||
if [ "$REBUILD_KERNEL" = "true" ]; then
|
||||
echo "[+] Building kernel ${KERNEL_VERSION}..."
|
||||
# Only download and build kernel, not embed initramfs yet
|
||||
/build/scripts/build-kernel.sh --kernel-only
|
||||
mark_completed "kernel"
|
||||
else
|
||||
echo "[+] Using cached kernel ${KERNEL_VERSION}"
|
||||
fi
|
||||
|
||||
# Phase 3: Initramfs (always - fast)
|
||||
echo "[+] Installing Alpine packages..."
|
||||
/build/scripts/install-packages.sh
|
||||
|
||||
echo "[+] Setting up initramfs structure..."
|
||||
/build/scripts/setup-initramfs.sh
|
||||
|
||||
# Phase 4: Final kernel assembly (embed initramfs)
|
||||
echo "[+] Embedding initramfs into kernel..."
|
||||
/build/scripts/build-kernel.sh --embed-only
|
||||
|
||||
echo ""
|
||||
echo "[+] Smart build completed!"
|
||||
echo " Components: $([ "$REBUILD_COMPONENTS" = "true" ] && echo "rebuilt" || echo "cached")"
|
||||
echo " Kernel: $([ "$REBUILD_KERNEL" = "true" ] && echo "rebuilt" || echo "cached")"
|
||||
echo " Total time saved by caching: significant!"
|
||||
196
scripts/compile-components.sh
Executable file
196
scripts/compile-components.sh
Executable file
@@ -0,0 +1,196 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
ALPINE_ROOT="/build/alpine"
|
||||
COMPONENTS_DIR="/build/components"
|
||||
CACHE_DIR="/build/cache/source"
|
||||
|
||||
echo "[+] Compiling Zero-OS components from git submodules..."
|
||||
|
||||
# Create build directories
|
||||
mkdir -p "$CACHE_DIR"
|
||||
|
||||
# Check if submodules are available
|
||||
if [ ! -d "$COMPONENTS_DIR" ]; then
|
||||
echo "Error: Components directory not found. Run setup-submodules.sh first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to prepare component for building
|
||||
prepare_component() {
|
||||
local component_name="$1"
|
||||
local component_dir="$COMPONENTS_DIR/$component_name"
|
||||
|
||||
if [ ! -d "$component_dir" ]; then
|
||||
echo " Warning: $component_name submodule not found at $component_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo " Preparing $component_name..."
|
||||
cd "$component_dir"
|
||||
|
||||
# Update submodule if needed
|
||||
if [ -d ".git" ]; then
|
||||
git pull origin main 2>/dev/null || git pull origin master 2>/dev/null || echo " Using existing checkout"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Function to build Rust project from submodule
|
||||
build_rust_component() {
|
||||
local component_name="$1"
|
||||
local binary_name="$2"
|
||||
local install_path="$3"
|
||||
|
||||
echo " Building Rust component: $component_name"
|
||||
|
||||
if ! prepare_component "$component_name"; then
|
||||
echo " Skipping $component_name (not available)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Build the project
|
||||
echo " Compiling with cargo..."
|
||||
if command -v cargo >/dev/null; then
|
||||
cargo build --release
|
||||
|
||||
# Install binary to Alpine root
|
||||
mkdir -p "$ALPINE_ROOT$install_path"
|
||||
cp "target/release/$binary_name" "$ALPINE_ROOT$install_path/"
|
||||
chmod +x "$ALPINE_ROOT$install_path/$binary_name"
|
||||
|
||||
echo " Success: $install_path/$binary_name installed to Alpine root"
|
||||
return 0
|
||||
else
|
||||
echo " Error: cargo not found - installing Rust..."
|
||||
apk add --no-cache rust cargo
|
||||
cargo build --release
|
||||
|
||||
mkdir -p "$ALPINE_ROOT$install_path"
|
||||
cp "target/release/$binary_name" "$ALPINE_ROOT$install_path/"
|
||||
chmod +x "$ALPINE_ROOT$install_path/$binary_name"
|
||||
|
||||
echo " Success: $install_path/$binary_name installed to Alpine root"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to build Go project from submodule
|
||||
build_go_component() {
|
||||
local component_name="$1"
|
||||
local binary_name="$2"
|
||||
local install_path="$3"
|
||||
local build_cmd="$4"
|
||||
|
||||
echo " Building Go component: $component_name"
|
||||
|
||||
if ! prepare_component "$component_name"; then
|
||||
echo " Skipping $component_name (not available)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Build the project
|
||||
echo " Compiling with go..."
|
||||
if command -v go >/dev/null; then
|
||||
if [ -n "$build_cmd" ]; then
|
||||
eval "$build_cmd"
|
||||
else
|
||||
go build -o "$binary_name"
|
||||
fi
|
||||
|
||||
# Install binary to Alpine root
|
||||
mkdir -p "$ALPINE_ROOT$install_path"
|
||||
cp "$binary_name" "$ALPINE_ROOT$install_path/"
|
||||
chmod +x "$ALPINE_ROOT$install_path/$binary_name"
|
||||
|
||||
echo " Success: $install_path/$binary_name installed to Alpine root"
|
||||
return 0
|
||||
else
|
||||
echo " Error: go not found - installing Go..."
|
||||
apk add --no-cache go
|
||||
if [ -n "$build_cmd" ]; then
|
||||
eval "$build_cmd"
|
||||
else
|
||||
go build -o "$binary_name"
|
||||
fi
|
||||
|
||||
mkdir -p "$ALPINE_ROOT$install_path"
|
||||
cp "$binary_name" "$ALPINE_ROOT$install_path/"
|
||||
chmod +x "$ALPINE_ROOT$install_path/$binary_name"
|
||||
|
||||
echo " Success: $install_path/$binary_name installed to Alpine root"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Install build dependencies if needed
|
||||
echo " Checking build dependencies..."
|
||||
if ! command -v git >/dev/null; then
|
||||
echo " Installing git..."
|
||||
apk add --no-cache git
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Ensure Alpine root directory exists
|
||||
if [ ! -d "$ALPINE_ROOT" ]; then
|
||||
echo "Error: Alpine root not found at $ALPINE_ROOT"
|
||||
echo "Make sure Alpine system is built first"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build each Zero-OS component from submodules
|
||||
echo "Building Zero-OS components from submodules:"
|
||||
|
||||
# 1. Zinit - Init system (Go)
|
||||
if build_go_component "zinit" "zinit" "/sbin" "go build -o zinit"; then
|
||||
echo " Zinit built successfully"
|
||||
else
|
||||
echo " Warning: Failed to build zinit"
|
||||
fi
|
||||
|
||||
# 2. RFS - Rust filesystem (Rust)
|
||||
if build_rust_component "rfs" "rfs" "/usr/bin"; then
|
||||
echo " RFS built successfully"
|
||||
else
|
||||
echo " Warning: Failed to build rfs"
|
||||
fi
|
||||
|
||||
# 3. Seektime - Disk detection (Go)
|
||||
if build_go_component "seektime" "seektime" "/usr/bin" "go build -o seektime"; then
|
||||
echo " Seektime built successfully"
|
||||
else
|
||||
echo " Warning: Failed to build seektime"
|
||||
fi
|
||||
|
||||
# 4. Core-X - Container control (Go)
|
||||
if build_go_component "core-x" "core-x" "/usr/bin" "go build -o core-x"; then
|
||||
echo " Core-X built successfully"
|
||||
else
|
||||
echo " Warning: Failed to build core-x"
|
||||
fi
|
||||
|
||||
# 5. Mycelium - Networking layer (Rust)
|
||||
if build_rust_component "mycelium" "mycelium" "/usr/bin"; then
|
||||
echo " Mycelium built successfully"
|
||||
else
|
||||
echo " Warning: Failed to build mycelium"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "[+] Zero-OS component compilation completed"
|
||||
|
||||
# Show installed binaries info
|
||||
echo ""
|
||||
echo "[+] Compiled Zero-OS components in Alpine root:"
|
||||
for binary in "/sbin/zinit" "/usr/bin/rfs" "/usr/bin/seektime" "/usr/bin/core-x" "/usr/bin/mycelium"; do
|
||||
if [ -x "$ALPINE_ROOT$binary" ]; then
|
||||
size=$(stat -c%s "$ALPINE_ROOT$binary" 2>/dev/null || echo "unknown")
|
||||
echo " $binary (${size} bytes)"
|
||||
else
|
||||
echo " $binary (NOT BUILT)"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "[+] Zero-OS binaries installed to Alpine root filesystem"
|
||||
215
scripts/fetch-github.sh
Executable file
215
scripts/fetch-github.sh
Executable file
@@ -0,0 +1,215 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
GITHUB_DIR="/build/github"
|
||||
INITRAMFS_ROOT="/build/initramfs"
|
||||
CACHE_TIMEOUT=3600 # 1 hour cache
|
||||
|
||||
echo "[+] Fetching GitHub components..."
|
||||
|
||||
# DIAGNOSTIC: Check GitHub connectivity and cache
|
||||
echo "[DEBUG] Checking GitHub connectivity..."
|
||||
echo "[DEBUG] Cache directory: $GITHUB_DIR"
|
||||
echo "[DEBUG] Existing cache files: $(ls -la $GITHUB_DIR 2>/dev/null | wc -l)"
|
||||
echo "[DEBUG] GitHub API rate limit check..."
|
||||
github_status=$(curl -s -I https://api.github.com/repos/threefoldtech/zinit/releases/latest | head -1 | awk '{print $2}')
|
||||
echo "[DEBUG] GitHub API response code: $github_status"
|
||||
if [ "$github_status" != "200" ]; then
|
||||
echo "[DEBUG] WARNING: GitHub API may be inaccessible - code: $github_status"
|
||||
fi
|
||||
echo "[DEBUG] Available tools: curl=$(command -v curl >/dev/null && echo 'YES' || echo 'NO'), wget=$(command -v wget >/dev/null && echo 'YES' || echo 'NO')"
|
||||
|
||||
# Create cache directory
|
||||
mkdir -p "$GITHUB_DIR"
|
||||
|
||||
# Function to get latest release info
|
||||
get_latest_release() {
|
||||
local repo="$1"
|
||||
local cache_file="$GITHUB_DIR/${repo//\//_}_release.json"
|
||||
|
||||
# Check cache first
|
||||
if [ -f "$cache_file" ] && [ $(($(date +%s) - $(stat -c %Y "$cache_file"))) -lt $CACHE_TIMEOUT ]; then
|
||||
cat "$cache_file"
|
||||
return
|
||||
fi
|
||||
|
||||
# Fetch latest release info
|
||||
local api_url="https://api.github.com/repos/$repo/releases/latest"
|
||||
echo " Fetching release info for $repo..." >&2
|
||||
|
||||
if command -v curl >/dev/null; then
|
||||
curl -s "$api_url" | tee "$cache_file"
|
||||
else
|
||||
wget -qO- "$api_url" | tee "$cache_file"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to extract download URL from release JSON
|
||||
get_download_url() {
|
||||
local release_json="$1"
|
||||
local pattern="$2"
|
||||
|
||||
echo "$release_json" | grep -o '"browser_download_url": *"[^"]*"' | \
|
||||
grep "$pattern" | head -1 | cut -d '"' -f 4
|
||||
}
|
||||
|
||||
# Function to download with retry
|
||||
download_with_retry() {
|
||||
local url="$1"
|
||||
local output="$2"
|
||||
local max_attempts=3
|
||||
local attempt=1
|
||||
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
echo " Attempt $attempt/$max_attempts..."
|
||||
|
||||
if command -v curl >/dev/null; then
|
||||
if curl -L --fail -o "$output" "$url"; then
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
if wget -O "$output" "$url"; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
attempt=$((attempt + 1))
|
||||
if [ $attempt -le $max_attempts ]; then
|
||||
echo " Retrying in 5 seconds..."
|
||||
sleep 5
|
||||
fi
|
||||
done
|
||||
|
||||
echo " Error: Failed to download after $max_attempts attempts" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
# Function to download and install binary
|
||||
install_github_binary() {
|
||||
local repo="$1"
|
||||
local binary_name="$2"
|
||||
local install_path="$3"
|
||||
local download_pattern="$4"
|
||||
|
||||
echo " Installing: $repo -> $install_path/$binary_name"
|
||||
|
||||
# Get release information
|
||||
local release_json=$(get_latest_release "$repo")
|
||||
if [ -z "$release_json" ]; then
|
||||
echo " Error: Failed to get release info for $repo" >&2
|
||||
echo "[DEBUG] GitHub API call failed for $repo - check network/rate limits"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if this is a "Not Found" response
|
||||
if echo "$release_json" | grep -q '"message": *"Not Found"'; then
|
||||
echo " Error: Repository $repo not found or has no releases" >&2
|
||||
echo "[DEBUG] Repository $repo does not exist or has no releases"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "[DEBUG] Successfully fetched release info for $repo"
|
||||
|
||||
# Extract version for logging
|
||||
local version=$(echo "$release_json" | grep '"tag_name"' | cut -d '"' -f 4)
|
||||
echo " Version: $version"
|
||||
|
||||
# Get download URL
|
||||
local download_url=$(get_download_url "$release_json" "$download_pattern")
|
||||
if [ -z "$download_url" ]; then
|
||||
echo " Error: No matching release found for pattern: $download_pattern" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo " Downloading: $(basename "$download_url")"
|
||||
local filename=$(basename "$download_url")
|
||||
local download_path="$GITHUB_DIR/$filename"
|
||||
|
||||
# Download if not cached
|
||||
if [ ! -f "$download_path" ]; then
|
||||
download_with_retry "$download_url" "$download_path"
|
||||
else
|
||||
echo " Using cached file"
|
||||
fi
|
||||
|
||||
# Create install directory
|
||||
mkdir -p "$INITRAMFS_ROOT$install_path"
|
||||
|
||||
# Extract and install based on file type
|
||||
case "$filename" in
|
||||
*.tar.gz|*.tgz)
|
||||
echo " Extracting tar.gz..."
|
||||
tar -xzf "$download_path" -C "$GITHUB_DIR"
|
||||
# Find the binary in extracted files
|
||||
local extracted_binary=$(find "$GITHUB_DIR" -name "$binary_name" -type f -executable | head -1)
|
||||
if [ -n "$extracted_binary" ]; then
|
||||
cp "$extracted_binary" "$INITRAMFS_ROOT$install_path/$binary_name"
|
||||
else
|
||||
echo " Error: Binary '$binary_name' not found in archive" >&2
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
*.zip)
|
||||
echo " Extracting zip..."
|
||||
unzip -q "$download_path" -d "$GITHUB_DIR"
|
||||
local extracted_binary=$(find "$GITHUB_DIR" -name "$binary_name" -type f -executable | head -1)
|
||||
if [ -n "$extracted_binary" ]; then
|
||||
cp "$extracted_binary" "$INITRAMFS_ROOT$install_path/$binary_name"
|
||||
else
|
||||
echo " Error: Binary '$binary_name' not found in archive" >&2
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
# Assume it's a direct binary
|
||||
echo " Installing direct binary..."
|
||||
cp "$download_path" "$INITRAMFS_ROOT$install_path/$binary_name"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Make executable
|
||||
chmod +x "$INITRAMFS_ROOT$install_path/$binary_name"
|
||||
|
||||
# Verify installation
|
||||
if [ -x "$INITRAMFS_ROOT$install_path/$binary_name" ]; then
|
||||
echo " Success: $install_path/$binary_name installed"
|
||||
else
|
||||
echo " Error: Failed to install $binary_name" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Install each component
|
||||
echo ""
|
||||
|
||||
# Zinit - Init system
|
||||
install_github_binary "threefoldtech/zinit" "zinit" "/sbin" "linux-x86_64"
|
||||
|
||||
# Core-X - Container control (skip if repo doesn't exist)
|
||||
echo " Checking: threefoldtech/core-x"
|
||||
if install_github_binary "threefoldtech/core-x" "core-x" "/usr/bin" "linux.*amd64"; then
|
||||
echo " Core-X installed successfully"
|
||||
else
|
||||
echo " Warning: Core-X repository not found or no releases available - continuing without it"
|
||||
fi
|
||||
|
||||
# Seektime - Disk detection
|
||||
install_github_binary "threefoldtech/seektime" "seektime" "/usr/bin" "linux-amd64"
|
||||
|
||||
# RFS - Rust filesystem (direct binary, no architecture in name)
|
||||
install_github_binary "threefoldtech/rfs" "rfs" "/usr/bin" "rfs"
|
||||
|
||||
echo ""
|
||||
echo "[+] GitHub components installed successfully"
|
||||
|
||||
# Show installed binaries info
|
||||
echo ""
|
||||
echo "[+] Installed components:"
|
||||
for binary in "/sbin/zinit" "/usr/bin/core-x" "/usr/bin/seektime" "/usr/bin/rfs"; do
|
||||
if [ -x "$INITRAMFS_ROOT$binary" ]; then
|
||||
size=$(stat -c%s "$INITRAMFS_ROOT$binary" 2>/dev/null || echo "unknown")
|
||||
echo " $binary (${size} bytes)"
|
||||
else
|
||||
echo " $binary (MISSING)"
|
||||
fi
|
||||
done
|
||||
115
scripts/install-firmware-minimal.sh
Executable file
115
scripts/install-firmware-minimal.sh
Executable file
@@ -0,0 +1,115 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
INITRAMFS_ROOT="/build/initramfs"
|
||||
FIRMWARE_DIR="$INITRAMFS_ROOT/lib/firmware"
|
||||
|
||||
echo "[+] Installing minimal network firmware (not full 600MB package)..."
|
||||
|
||||
# Create firmware directory
|
||||
mkdir -p "$FIRMWARE_DIR"
|
||||
|
||||
# Install full linux-firmware temporarily to extract essentials
|
||||
echo " Downloading linux-firmware package..."
|
||||
cd /tmp
|
||||
apk fetch linux-firmware
|
||||
tar -xf linux-firmware-*.apk
|
||||
|
||||
# Extract only essential network firmware
|
||||
echo " Extracting essential network drivers..."
|
||||
|
||||
# Intel Ethernet (most common)
|
||||
if [ -d lib/firmware/intel ]; then
|
||||
mkdir -p "$FIRMWARE_DIR/intel"
|
||||
# e1000e, ixgbe, i40e, ice drivers
|
||||
cp -r lib/firmware/intel/*e1000* "$FIRMWARE_DIR/intel/" 2>/dev/null || true
|
||||
cp -r lib/firmware/intel/*ixgbe* "$FIRMWARE_DIR/intel/" 2>/dev/null || true
|
||||
cp -r lib/firmware/intel/*i40e* "$FIRMWARE_DIR/intel/" 2>/dev/null || true
|
||||
cp -r lib/firmware/intel/*ice* "$FIRMWARE_DIR/intel/" 2>/dev/null || true
|
||||
echo " Intel ethernet firmware: $(du -sh $FIRMWARE_DIR/intel 2>/dev/null | cut -f1)"
|
||||
fi
|
||||
|
||||
# Realtek Ethernet
|
||||
if [ -d lib/firmware/rtl_nic ]; then
|
||||
mkdir -p "$FIRMWARE_DIR/rtl_nic"
|
||||
# r8169 driver
|
||||
cp -r lib/firmware/rtl_nic/* "$FIRMWARE_DIR/rtl_nic/" 2>/dev/null || true
|
||||
echo " Realtek ethernet firmware: $(du -sh $FIRMWARE_DIR/rtl_nic 2>/dev/null | cut -f1)"
|
||||
fi
|
||||
|
||||
# Broadcom Ethernet
|
||||
if [ -d lib/firmware/bnx2 ]; then
|
||||
mkdir -p "$FIRMWARE_DIR/bnx2"
|
||||
cp -r lib/firmware/bnx2/* "$FIRMWARE_DIR/bnx2/" 2>/dev/null || true
|
||||
fi
|
||||
if [ -d lib/firmware/tigon ]; then
|
||||
mkdir -p "$FIRMWARE_DIR/tigon"
|
||||
cp -r lib/firmware/tigon/* "$FIRMWARE_DIR/tigon/" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Essential system firmware
|
||||
if [ -d lib/firmware/regulatory.db ]; then
|
||||
cp lib/firmware/regulatory.db* "$FIRMWARE_DIR/" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Cleanup temporary files
|
||||
cd /build
|
||||
rm -rf /tmp/lib /tmp/linux-firmware-*
|
||||
|
||||
# Show firmware size
|
||||
if [ -d "$FIRMWARE_DIR" ]; then
|
||||
total_size=$(du -sh "$FIRMWARE_DIR" 2>/dev/null | cut -f1)
|
||||
echo "[+] Essential firmware installed: $total_size (vs 600MB full package)"
|
||||
else
|
||||
echo "[-] Warning: No firmware installed"
|
||||
fi
|
||||
|
||||
# Install essential ethernet kernel modules
|
||||
echo " Installing essential ethernet kernel modules..."
|
||||
KERNEL_VERSION=$(cat /build/configs/kernel-version)
|
||||
MODULES_DIR="$INITRAMFS_ROOT/lib/modules/${KERNEL_VERSION}-Zero-OS"
|
||||
mkdir -p "$MODULES_DIR/kernel/drivers/net/ethernet"
|
||||
|
||||
# Copy essential ethernet driver modules from the built kernel
|
||||
KERNEL_BUILD_DIR="/build/kernel/linux-${KERNEL_VERSION}"
|
||||
if [ -d "$KERNEL_BUILD_DIR" ]; then
|
||||
echo " Copying ethernet drivers from kernel build..."
|
||||
|
||||
# Intel drivers (e1000, e1000e, igb, ixgbe, i40e, ice)
|
||||
find "$KERNEL_BUILD_DIR" -name "e1000.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/ethernet/" \; 2>/dev/null || true
|
||||
find "$KERNEL_BUILD_DIR" -name "e1000e.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/ethernet/" \; 2>/dev/null || true
|
||||
find "$KERNEL_BUILD_DIR" -name "igb.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/ethernet/" \; 2>/dev/null || true
|
||||
find "$KERNEL_BUILD_DIR" -name "ixgbe.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/ethernet/" \; 2>/dev/null || true
|
||||
find "$KERNEL_BUILD_DIR" -name "i40e.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/ethernet/" \; 2>/dev/null || true
|
||||
find "$KERNEL_BUILD_DIR" -name "ice.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/ethernet/" \; 2>/dev/null || true
|
||||
|
||||
# Realtek drivers (r8169, 8139too)
|
||||
find "$KERNEL_BUILD_DIR" -name "r8169.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/ethernet/" \; 2>/dev/null || true
|
||||
find "$KERNEL_BUILD_DIR" -name "8139too.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/ethernet/" \; 2>/dev/null || true
|
||||
|
||||
# Broadcom drivers (bnx2, tg3, b44)
|
||||
find "$KERNEL_BUILD_DIR" -name "bnx2.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/ethernet/" \; 2>/dev/null || true
|
||||
find "$KERNEL_BUILD_DIR" -name "tg3.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/ethernet/" \; 2>/dev/null || true
|
||||
find "$KERNEL_BUILD_DIR" -name "b44.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/ethernet/" \; 2>/dev/null || true
|
||||
|
||||
# Common dependencies (mii, mdio)
|
||||
find "$KERNEL_BUILD_DIR" -name "mii.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/" \; 2>/dev/null || true
|
||||
find "$KERNEL_BUILD_DIR" -name "mdio.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/" \; 2>/dev/null || true
|
||||
|
||||
# Create modules.dep for module loading
|
||||
if command -v depmod >/dev/null 2>&1; then
|
||||
depmod -b "$INITRAMFS_ROOT" "${KERNEL_VERSION}-Zero-OS" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
module_count=$(find "$MODULES_DIR" -name "*.ko" | wc -l)
|
||||
echo " Installed $module_count ethernet driver modules"
|
||||
else
|
||||
echo " Warning: Kernel build directory not found, modules may not be available"
|
||||
fi
|
||||
|
||||
# Create essential kernel module directories that eudev expects
|
||||
mkdir -p "$INITRAMFS_ROOT/lib/modules"
|
||||
mkdir -p "$INITRAMFS_ROOT/sys/module"
|
||||
mkdir -p "$INITRAMFS_ROOT/dev"
|
||||
|
||||
echo "[+] Minimal firmware and driver installation complete"
|
||||
200
scripts/install-packages.sh
Executable file
200
scripts/install-packages.sh
Executable file
@@ -0,0 +1,200 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
INITRAMFS_ROOT="/build/initramfs"
|
||||
|
||||
# Determine which package list to use
|
||||
if [ "$1" = "minimal" ] || [ "$MINIMAL_MODE" = "true" ] || [ -f "/build/configs/packages-minimal.txt" -a ! -f "/build/configs/packages.txt" ]; then
|
||||
PACKAGES_FILE="/build/configs/packages-minimal.txt"
|
||||
MINIMAL_MODE=true
|
||||
echo "[+] Creating MINIMAL initramfs root directory (embedded cpio)..."
|
||||
else
|
||||
PACKAGES_FILE="/build/configs/packages.txt"
|
||||
MINIMAL_MODE=false
|
||||
echo "[+] Creating FULL initramfs root directory..."
|
||||
fi
|
||||
rm -rf "$INITRAMFS_ROOT"
|
||||
mkdir -p "$INITRAMFS_ROOT"
|
||||
|
||||
echo "[+] Setting up Alpine repositories..."
|
||||
echo "[DEBUG] Checking APK setup..."
|
||||
echo "[DEBUG] Host repositories: $(cat /etc/apk/repositories | grep -v '^#' | wc -l) active repos"
|
||||
echo "[DEBUG] Host APK keys: $(ls -la /etc/apk/keys 2>/dev/null | wc -l) keys"
|
||||
echo "[DEBUG] Network connectivity to Alpine repos..."
|
||||
apk_test=$(apk update --quiet 2>&1 && echo 'OK' || echo 'FAILED')
|
||||
echo "[DEBUG] APK repository access: $apk_test"
|
||||
|
||||
# Create the repository configuration and copy APK keys
|
||||
mkdir -p "$INITRAMFS_ROOT/etc/apk"
|
||||
cp /etc/apk/repositories "$INITRAMFS_ROOT/etc/apk/"
|
||||
|
||||
# Copy APK keys to avoid UNTRUSTED signature warnings
|
||||
if [ -d /etc/apk/keys ]; then
|
||||
mkdir -p "$INITRAMFS_ROOT/etc/apk/keys"
|
||||
cp /etc/apk/keys/* "$INITRAMFS_ROOT/etc/apk/keys/"
|
||||
fi
|
||||
|
||||
echo "[+] Installing Alpine base system..."
|
||||
# Create APK database directory and initialize
|
||||
mkdir -p "$INITRAMFS_ROOT/lib/apk/db"
|
||||
mkdir -p "$INITRAMFS_ROOT/var/cache/apk"
|
||||
|
||||
# Initialize the database first with --clean-protected for new root
|
||||
apk --root "$INITRAMFS_ROOT" --clean-protected --update-cache --initdb add alpine-baselayout busybox apk-tools musl
|
||||
|
||||
echo "[+] Installing Zero-OS packages..."
|
||||
while read -r package; do
|
||||
# Skip comments and empty lines
|
||||
case "$package" in
|
||||
\#*|"") continue ;;
|
||||
esac
|
||||
|
||||
echo " Installing: $package"
|
||||
if apk --root "$INITRAMFS_ROOT" add --no-cache "$package"; then
|
||||
echo "[DEBUG] Successfully installed: $package"
|
||||
else
|
||||
echo " Warning: Failed to install $package (continuing)"
|
||||
echo "[DEBUG] Package installation failed: $package - check if package exists in repos"
|
||||
fi
|
||||
done < "$PACKAGES_FILE"
|
||||
|
||||
# For minimal mode, install selective firmware instead of full linux-firmware package
|
||||
if [ "$MINIMAL_MODE" = "true" ]; then
|
||||
echo "[+] Installing minimal firmware (essential network drivers only)..."
|
||||
/build/scripts/install-firmware-minimal.sh
|
||||
else
|
||||
echo "[+] Full mode: linux-firmware package already installed"
|
||||
fi
|
||||
|
||||
echo "[+] Setting up initramfs filesystem structure..."
|
||||
|
||||
# Create essential directories
|
||||
mkdir -p "$INITRAMFS_ROOT"/{dev,proc,sys,mnt,tmp,var/run,var/log,var/lock}
|
||||
mkdir -p "$INITRAMFS_ROOT"/{root,home,opt}
|
||||
mkdir -p "$INITRAMFS_ROOT"/mnt/root
|
||||
mkdir -p "$INITRAMFS_ROOT"/var/cache/containers
|
||||
|
||||
# Create device nodes (minimal set) - check if they exist first
|
||||
echo " Creating device nodes..."
|
||||
[ ! -e "$INITRAMFS_ROOT/dev/console" ] && mknod "$INITRAMFS_ROOT/dev/console" c 5 1
|
||||
[ ! -e "$INITRAMFS_ROOT/dev/null" ] && mknod "$INITRAMFS_ROOT/dev/null" c 1 3
|
||||
[ ! -e "$INITRAMFS_ROOT/dev/zero" ] && mknod "$INITRAMFS_ROOT/dev/zero" c 1 5
|
||||
[ ! -e "$INITRAMFS_ROOT/dev/random" ] && mknod "$INITRAMFS_ROOT/dev/random" c 1 8
|
||||
[ ! -e "$INITRAMFS_ROOT/dev/urandom" ] && mknod "$INITRAMFS_ROOT/dev/urandom" c 1 9
|
||||
|
||||
# Set proper permissions
|
||||
chmod 666 "$INITRAMFS_ROOT/dev/null" "$INITRAMFS_ROOT/dev/zero"
|
||||
chmod 600 "$INITRAMFS_ROOT/dev/console"
|
||||
chmod 644 "$INITRAMFS_ROOT/dev/random" "$INITRAMFS_ROOT/dev/urandom"
|
||||
|
||||
# Create symlinks (similar to current system)
|
||||
echo " Creating symlinks..."
|
||||
cd "$INITRAMFS_ROOT"
|
||||
ln -sf usr/lib lib || true
|
||||
ln -sf usr/lib lib64 || true
|
||||
ln -sf var/run run || true
|
||||
|
||||
# Ensure minimal login logs
|
||||
touch "$INITRAMFS_ROOT"/var/log/lastlog
|
||||
touch "$INITRAMFS_ROOT"/var/log/wtmp
|
||||
|
||||
# Legacy mtab symlink
|
||||
cd "$INITRAMFS_ROOT/etc"
|
||||
ln -sf /proc/mounts mtab || true
|
||||
|
||||
echo "[+] Cleaning up unnecessary files..."
|
||||
cd "$INITRAMFS_ROOT"
|
||||
|
||||
# Remove package cache and docs
|
||||
rm -rf var/cache/apk/*
|
||||
rm -rf usr/share/doc
|
||||
rm -rf usr/share/man
|
||||
rm -rf usr/share/info
|
||||
rm -rf usr/share/locale
|
||||
rm -rf usr/include
|
||||
rm -rf usr/lib/pkgconfig
|
||||
|
||||
# Remove development files
|
||||
rm -rf lib/*.a usr/lib/*.a
|
||||
rm -rf lib/*.la usr/lib/*.la
|
||||
|
||||
# Aggressive cleanup for minimal mode
|
||||
if [ "$MINIMAL_MODE" = "true" ]; then
|
||||
echo " Applying aggressive size optimizations for embedded cpio..."
|
||||
|
||||
# Remove ALL documentation and help files
|
||||
rm -rf usr/share/doc usr/share/man usr/share/info
|
||||
rm -rf usr/share/help usr/share/gtk-doc usr/share/licenses
|
||||
rm -rf usr/share/LICENSES usr/share/COPYING*
|
||||
|
||||
# Remove ALL locale and internationalization
|
||||
rm -rf usr/share/locale usr/share/i18n
|
||||
rm -rf usr/lib/locale usr/lib/gconv
|
||||
|
||||
# Remove timezone data (embedded systems often use UTC)
|
||||
rm -rf usr/share/zoneinfo/* 2>/dev/null || true
|
||||
|
||||
# Remove terminfo except bare essentials (vt100, linux, xterm)
|
||||
rm -rf usr/share/terminfo/[b-df-km-uw-z]* 2>/dev/null || true
|
||||
rm -rf usr/share/terminfo/[A-Z]* 2>/dev/null || true
|
||||
rm -rf usr/share/terminfo/1 usr/share/terminfo/2 usr/share/terminfo/3 2>/dev/null || true
|
||||
|
||||
# Remove graphics/desktop files (embedded has no GUI)
|
||||
rm -rf usr/share/pixmaps usr/share/icons usr/share/applications
|
||||
rm -rf usr/share/mime usr/share/desktop-directories
|
||||
|
||||
# Remove development headers and static libraries
|
||||
rm -rf usr/include usr/lib/pkgconfig usr/share/pkgconfig
|
||||
rm -rf lib/*.a usr/lib/*.a lib/*.la usr/lib/*.la
|
||||
|
||||
# Remove Python cache and compiled modules
|
||||
rm -rf usr/lib/python*/site-packages/__pycache__
|
||||
rm -rf usr/lib/python*/__pycache__ usr/lib/python*/test
|
||||
rm -rf usr/lib/python*/tkinter usr/lib/python*/turtle*
|
||||
find usr/lib/python* -name "*.pyc" -delete 2>/dev/null || true
|
||||
find usr/lib/python* -name "*.pyo" -delete 2>/dev/null || true
|
||||
|
||||
# Remove unnecessary logs, cache, and temporary files
|
||||
rm -rf var/log/* var/cache/* tmp/* var/tmp/*
|
||||
rm -rf var/lib/apk/db/installed var/lib/apk/db/lock
|
||||
rm -rf etc/apk/cache/* 2>/dev/null || true
|
||||
|
||||
# Remove unneeded kernel modules (we only need firmware)
|
||||
rm -rf lib/modules/* 2>/dev/null || true
|
||||
|
||||
# Strip binaries aggressively to reduce size
|
||||
echo " Stripping binaries..."
|
||||
find . -type f -perm -111 -exec strip --strip-unneeded {} \; 2>/dev/null || true
|
||||
find . -name "*.so*" -exec strip --strip-unneeded {} \; 2>/dev/null || true
|
||||
|
||||
# Remove backup files and editor artifacts
|
||||
find . -name "*~" -delete 2>/dev/null || true
|
||||
find . -name "*.orig" -delete 2>/dev/null || true
|
||||
find . -name "*.rej" -delete 2>/dev/null || true
|
||||
|
||||
# Show final firmware size
|
||||
echo " Minimal firmware size: $(du -sh lib/firmware 2>/dev/null | cut -f1 || echo 'N/A')"
|
||||
echo " Total size after aggressive cleanup: $(du -sh . | cut -f1)"
|
||||
fi
|
||||
|
||||
echo "[+] Setting up Alpine-specific configurations..."
|
||||
|
||||
# Ensure terminfo is available (needed for various tools)
|
||||
if [ -d /usr/share/terminfo ]; then
|
||||
cp -r /usr/share/terminfo "$INITRAMFS_ROOT/usr/share/" || true
|
||||
fi
|
||||
|
||||
# Copy timezone data
|
||||
if [ -d /usr/share/zoneinfo ]; then
|
||||
mkdir -p "$INITRAMFS_ROOT/usr/share"
|
||||
cp -r /usr/share/zoneinfo "$INITRAMFS_ROOT/usr/share/" || true
|
||||
fi
|
||||
|
||||
echo "[+] Alpine packages installed successfully"
|
||||
echo " Initramfs root: $INITRAMFS_ROOT"
|
||||
|
||||
# Show size
|
||||
if command -v du >/dev/null; then
|
||||
size=$(du -sh "$INITRAMFS_ROOT" | cut -f1)
|
||||
echo " Size: $size"
|
||||
fi
|
||||
172
scripts/setup-initramfs.sh
Executable file
172
scripts/setup-initramfs.sh
Executable file
@@ -0,0 +1,172 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
INITRAMFS_ROOT="/build/initramfs"
|
||||
CONFIG_DIR="/build/configs"
|
||||
OUTPUT_DIR="/build/output"
|
||||
|
||||
echo "[+] Setting up initramfs structure..."
|
||||
|
||||
# Copy init script
|
||||
echo " Installing init script..."
|
||||
cp "$CONFIG_DIR/init" "$INITRAMFS_ROOT/init"
|
||||
chmod +x "$INITRAMFS_ROOT/init"
|
||||
|
||||
# Copy zinit configuration (mounted from existing config)
|
||||
echo " Installing zinit configuration..."
|
||||
echo "[DEBUG] Checking zinit config sources..."
|
||||
echo "[DEBUG] /mnt/zinit exists: $([ -d "/mnt/zinit" ] && echo 'YES' || echo 'NO')"
|
||||
echo "[DEBUG] /mnt/zinit contents: $(ls -la /mnt/zinit 2>/dev/null | wc -l) files"
|
||||
echo "[DEBUG] $CONFIG_DIR/zinit exists: $([ -d "$CONFIG_DIR/zinit" ] && echo 'YES' || echo 'NO')"
|
||||
echo "[DEBUG] $CONFIG_DIR/zinit contents: $(ls -la $CONFIG_DIR/zinit 2>/dev/null | wc -l) files"
|
||||
|
||||
mkdir -p "$INITRAMFS_ROOT/etc/zinit"
|
||||
if [ -d "/mnt/zinit" ]; then
|
||||
cp -r "/mnt/zinit/"* "$INITRAMFS_ROOT/etc/zinit/"
|
||||
echo " Copied zinit configs from /mnt/zinit"
|
||||
echo "[DEBUG] Copied $(ls -la $INITRAMFS_ROOT/etc/zinit 2>/dev/null | wc -l) zinit config files"
|
||||
elif [ -d "$CONFIG_DIR/zinit" ]; then
|
||||
cp -r "$CONFIG_DIR/zinit/"* "$INITRAMFS_ROOT/etc/zinit/"
|
||||
echo " Copied zinit configs from $CONFIG_DIR/zinit"
|
||||
echo "[DEBUG] Copied $(ls -la $INITRAMFS_ROOT/etc/zinit 2>/dev/null | wc -l) zinit config files"
|
||||
else
|
||||
echo " Warning: zinit config directory not found"
|
||||
echo "[DEBUG] ERROR: No zinit config source available - this will likely cause runtime failures"
|
||||
fi
|
||||
|
||||
# Create debug script for compatibility
|
||||
echo " Creating debug script..."
|
||||
cat > "$INITRAMFS_ROOT/init-debug" << 'EOF'
|
||||
#!/bin/sh
|
||||
# Debug file injection script (Alpine version)
|
||||
echo "[+] debug mode enabled"
|
||||
|
||||
# Check for debug device (same as original)
|
||||
if [ -b /dev/sda1 ]; then
|
||||
echo " debug device found: /dev/sda1"
|
||||
|
||||
# Create temporary mount point
|
||||
mkdir -p /mnt/debug
|
||||
|
||||
# Try to mount as vfat (same as original)
|
||||
if mount -t vfat -o ro /dev/sda1 /mnt/debug 2>/dev/null; then
|
||||
echo " mounted debug device"
|
||||
|
||||
# Check for debug marker file
|
||||
if [ -f /mnt/debug/.zero-os-debug ]; then
|
||||
echo " debug marker found, copying files..."
|
||||
|
||||
# Copy all files from debug device to tmpfs root
|
||||
target="/mnt/root"
|
||||
if [ -d "$target" ]; then
|
||||
cp -rv /mnt/debug/* "$target/" 2>/dev/null || true
|
||||
echo " debug files copied to tmpfs"
|
||||
else
|
||||
echo " warning: tmpfs root not ready yet"
|
||||
fi
|
||||
else
|
||||
echo " no debug marker (.zero-os-debug) found"
|
||||
fi
|
||||
|
||||
# Unmount debug device
|
||||
umount /mnt/debug 2>/dev/null || true
|
||||
else
|
||||
echo " failed to mount debug device"
|
||||
fi
|
||||
|
||||
# Cleanup
|
||||
rmdir /mnt/debug 2>/dev/null || true
|
||||
else
|
||||
echo " no debug device found"
|
||||
fi
|
||||
|
||||
echo "[+] debug initialization complete"
|
||||
EOF
|
||||
|
||||
chmod +x "$INITRAMFS_ROOT/init-debug"
|
||||
|
||||
# Copy other system configurations
|
||||
echo " Setting up system configuration..."
|
||||
|
||||
# Ensure proper hostname
|
||||
echo "zero-os" > "$INITRAMFS_ROOT/etc/hostname"
|
||||
|
||||
# Basic hosts file
|
||||
cat > "$INITRAMFS_ROOT/etc/hosts" << EOF
|
||||
127.0.0.1 localhost zero-os
|
||||
::1 localhost zero-os
|
||||
EOF
|
||||
|
||||
# Minimal passwd file (compatible with existing)
|
||||
if [ ! -f "$INITRAMFS_ROOT/etc/passwd" ]; then
|
||||
cat > "$INITRAMFS_ROOT/etc/passwd" << EOF
|
||||
root:x:0:0:root:/root:/bin/sh
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Minimal group file
|
||||
if [ ! -f "$INITRAMFS_ROOT/etc/group" ]; then
|
||||
cat > "$INITRAMFS_ROOT/etc/group" << EOF
|
||||
root:x:0:
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Set up profile for environment
|
||||
cat > "$INITRAMFS_ROOT/etc/profile" << EOF
|
||||
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
||||
export HOME=/root
|
||||
export TERM=linux
|
||||
EOF
|
||||
|
||||
# Ensure SSH directory exists
|
||||
mkdir -p "$INITRAMFS_ROOT/etc/ssh"
|
||||
mkdir -p "$INITRAMFS_ROOT/root/.ssh"
|
||||
|
||||
# Set proper permissions
|
||||
chmod 700 "$INITRAMFS_ROOT/root"
|
||||
chmod 700 "$INITRAMFS_ROOT/root/.ssh" 2>/dev/null || true
|
||||
|
||||
# Create necessary run directories
|
||||
mkdir -p "$INITRAMFS_ROOT/run"
|
||||
mkdir -p "$INITRAMFS_ROOT/var"
|
||||
|
||||
# Ensure terminfo is available for better terminal support
|
||||
if [ -d "$INITRAMFS_ROOT/usr/share/terminfo" ]; then
|
||||
echo " terminfo available"
|
||||
else
|
||||
echo " warning: terminfo not found"
|
||||
fi
|
||||
|
||||
# Set up symlinks (similar to current system)
|
||||
echo " Setting up symlinks..."
|
||||
cd "$INITRAMFS_ROOT"
|
||||
|
||||
# Ensure lib symlinks
|
||||
ln -sf usr/lib lib || true
|
||||
ln -sf usr/lib lib64 || true
|
||||
|
||||
# Ensure var/run symlink (standard Linux practice: /var/run -> /run)
|
||||
cd "$INITRAMFS_ROOT/var"
|
||||
rm -rf run
|
||||
ln -sf ../run run || true
|
||||
cd "$INITRAMFS_ROOT"
|
||||
|
||||
# Create initramfs archive
|
||||
echo "[+] Creating initramfs archive..."
|
||||
cd "$INITRAMFS_ROOT"
|
||||
|
||||
# Create the cpio archive
|
||||
find . | cpio -H newc -o | xz --check=crc32 --x86 --lzma2=dict=1MiB > "$OUTPUT_DIR/initramfs.cpio.xz"
|
||||
|
||||
if [ -f "$OUTPUT_DIR/initramfs.cpio.xz" ]; then
|
||||
size=$(stat -c%s "$OUTPUT_DIR/initramfs.cpio.xz")
|
||||
echo "[+] Initramfs created: $OUTPUT_DIR/initramfs.cpio.xz ($size bytes)"
|
||||
else
|
||||
echo "[-] Error: Failed to create initramfs archive"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Also create uncompressed version for debugging
|
||||
find . | cpio -H newc -o > "$OUTPUT_DIR/initramfs.cpio"
|
||||
|
||||
echo "[+] Initramfs setup completed successfully"
|
||||
7
scripts/setup-permissions.sh
Executable file
7
scripts/setup-permissions.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Ensure all scripts are executable
|
||||
|
||||
chmod +x /build/scripts/*.sh
|
||||
|
||||
echo "Script permissions updated:"
|
||||
ls -la /build/scripts/*.sh | grep -E '\.(sh)$'
|
||||
62
scripts/setup-submodules.sh
Executable file
62
scripts/setup-submodules.sh
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "[+] Setting up Zero-OS component submodules..."
|
||||
|
||||
# Check if we're in git repository
|
||||
if [ ! -d ".git" ]; then
|
||||
echo "Error: Not in a git repository. Please run 'git init' first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create components directory
|
||||
mkdir -p components
|
||||
|
||||
# Add Zero-OS components as git submodules
|
||||
echo " Adding zinit (init system)..."
|
||||
if [ ! -d "components/zinit" ]; then
|
||||
git submodule add https://github.com/threefoldtech/zinit.git components/zinit
|
||||
else
|
||||
echo " zinit submodule already exists"
|
||||
fi
|
||||
|
||||
echo " Adding seektime (disk detection)..."
|
||||
if [ ! -d "components/seektime" ]; then
|
||||
git submodule add https://github.com/threefoldtech/seektime.git components/seektime
|
||||
else
|
||||
echo " seektime submodule already exists"
|
||||
fi
|
||||
|
||||
echo " Adding core-x (container control)..."
|
||||
if [ ! -d "components/core-x" ]; then
|
||||
git submodule add https://github.com/threefoldtech/core-x.git components/core-x
|
||||
else
|
||||
echo " core-x submodule already exists"
|
||||
fi
|
||||
|
||||
echo " Adding mycelium (networking layer)..."
|
||||
if [ ! -d "components/mycelium" ]; then
|
||||
git submodule add https://github.com/threefoldtech/mycelium.git components/mycelium
|
||||
else
|
||||
echo " mycelium submodule already exists"
|
||||
fi
|
||||
|
||||
echo " Adding rfs (rust filesystem)..."
|
||||
if [ ! -d "components/rfs" ]; then
|
||||
git submodule add https://github.com/threefoldtech/rfs.git components/rfs
|
||||
else
|
||||
echo " rfs submodule already exists"
|
||||
fi
|
||||
|
||||
# Initialize and update submodules
|
||||
echo " Initializing submodules..."
|
||||
git submodule init
|
||||
git submodule update
|
||||
|
||||
echo "[+] Zero-OS component submodules setup complete"
|
||||
echo ""
|
||||
echo "Submodules added:"
|
||||
ls -la components/
|
||||
echo ""
|
||||
echo "To update submodules later, run:"
|
||||
echo " git submodule update --remote"
|
||||
Reference in New Issue
Block a user