Fix module dependency resolution issues

- Fix dependency resolution to use built modules from /lib/modules/6.12.44-Zero-OS instead of fresh container
- Fix stage1/stage2 configuration mismatch (only using stage1 modules as intended)
- Fix firmware parsing to ignore comments in modules.conf
- Fix variable binding issues for incremental builds (FULL_KERNEL_VERSION, KERNEL_OUTPUT)
- Module resolution now properly expands 31 → 48 modules with dependencies
- Firmware requirements reduced from 157 bogus → 3 correct packages
- All 48/48 resolved modules validated as available .ko files
This commit is contained in:
2025-09-03 17:06:57 +02:00
parent b9f94105cf
commit f7c67ee5dd
3 changed files with 368 additions and 115 deletions

View File

@@ -9,6 +9,7 @@ PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
# Source all libraries
source "${SCRIPT_DIR}/lib/common.sh"
source "${SCRIPT_DIR}/lib/stages.sh"
source "${SCRIPT_DIR}/lib/docker.sh"
source "${SCRIPT_DIR}/lib/alpine.sh"
source "${SCRIPT_DIR}/lib/components.sh"
@@ -47,7 +48,7 @@ KEEP_ARTIFACTS="${KEEP_ARTIFACTS:-false}"
# Display usage information
function show_usage() {
cat << EOF
Zero OS Alpine Initramfs Builder
Zero OS Alpine Initramfs Builder (Incremental)
Usage: $0 [OPTIONS]
@@ -55,20 +56,31 @@ Options:
--clean Clean build (remove all artifacts first)
--skip-tests Skip boot tests
--keep-artifacts Keep build artifacts after completion
--force-rebuild Force rebuild all stages (ignore completion markers)
--rebuild-from=STAGE Force rebuild from specific stage onward
--show-stages Show stage completion status
--help Show this help message
Environment Variables:
ALPINE_VERSION Alpine Linux version (default: 3.22)
KERNEL_VERSION Linux kernel version (default: 6.8.8)
KERNEL_VERSION Linux kernel version (default: 6.12.44)
RUST_TARGET Rust compilation target (default: x86_64-unknown-linux-musl)
OPTIMIZATION_LEVEL Optimization level: max|size|speed (default: max)
DEBUG Enable debug output (default: 0)
FORCE_REBUILD Force rebuild all stages (default: false)
Examples:
$0 # Basic build
$0 --clean # Clean build
$0 --container # Force container build
DEBUG=1 $0 # Build with debug output
$0 # Incremental build (skip completed stages)
$0 --clean # Clean build (remove artifacts + stage markers)
$0 --force-rebuild # Force rebuild all stages
$0 --rebuild-from=zinit_setup # Rebuild from zinit setup onward
$0 --show-stages # Show which stages are completed
DEBUG=1 $0 # Build with debug output
Development Workflow:
./scripts/dev-container.sh start # Start persistent container
./scripts/dev-container.sh shell # Enter container for debugging
DEBUG=1 ./scripts/build.sh # Run incremental build inside container
EOF
}
@@ -88,6 +100,22 @@ function parse_arguments() {
KEEP_ARTIFACTS="true"
shift
;;
--force-rebuild)
export FORCE_REBUILD="true"
shift
;;
--rebuild-from=*)
export REBUILD_FROM_STAGE="${1#*=}"
export FORCE_REBUILD="true"
shift
;;
--show-stages)
# Initialize stage tracking and show status
source "${SCRIPT_DIR}/lib/stages.sh"
stages_init
stages_status
exit 0
;;
--help|-h)
show_usage
exit 0
@@ -174,82 +202,140 @@ function verify_configuration_files() {
log_info "All configuration files verified"
}
# Main build process
# Incremental build process with stage tracking
function main_build_process() {
section_header "Starting Zero OS Alpine Initramfs Build"
section_header "Starting Zero OS Alpine Initramfs Build (Incremental)"
local start_time=$(date +%s)
# Phase 1: Extract Alpine miniroot
alpine_extract_miniroot "$INSTALL_DIR" "$ALPINE_VERSION"
# Initialize stage tracking
stages_init
# Phase 2: Configure Alpine system
alpine_configure_repos "$INSTALL_DIR" "$ALPINE_VERSION"
alpine_configure_system "$INSTALL_DIR"
# Define stage wrapper functions
function stage_alpine_extract() {
alpine_extract_miniroot "$INSTALL_DIR" "$ALPINE_VERSION"
}
# Phase 3: Install Alpine packages (NO OpenRC)
alpine_install_packages "$INSTALL_DIR" "$PACKAGES_LIST"
function stage_alpine_configure() {
alpine_configure_repos "$INSTALL_DIR" "$ALPINE_VERSION"
alpine_configure_system "$INSTALL_DIR"
}
# Phase 3.5: Install firmware packages for hardware support
alpine_install_firmware "$INSTALL_DIR" "$FIRMWARE_CONF"
function stage_alpine_packages() {
alpine_install_packages "$INSTALL_DIR" "$PACKAGES_LIST"
}
# Phase 4: Build and install ThreeFold components
components_parse_sources_conf "$SOURCES_CONF" "$COMPONENTS_DIR" "$INSTALL_DIR"
function stage_alpine_firmware() {
alpine_install_firmware "$INSTALL_DIR" "$FIRMWARE_CONF"
}
# Phase 5: Verify component installation
components_verify_installation
function stage_components_build() {
components_parse_sources_conf "$SOURCES_CONF" "$COMPONENTS_DIR" "$INSTALL_DIR"
}
# Phase 6: Create placeholder initramfs for kernel build (chicken-egg problem)
local initramfs_archive="${DIST_DIR}/initramfs.cpio.xz"
safe_mkdir "$DIST_DIR"
log_info "Creating placeholder initramfs for initial kernel build"
safe_execute touch "$initramfs_archive"
function stage_components_verify() {
components_verify_installation
}
# Phase 7: Prepare kernel source and build modules (with placeholder initramfs)
log_info "Downloading and configuring kernel source for module build"
kernel_download_source "$KERNEL_DIR" "$KERNEL_VERSION"
kernel_apply_config "$KERNEL_DIR" "$initramfs_archive" "$KERNEL_CONFIG"
function stage_kernel_modules() {
# Create placeholder for kernel build
local initramfs_archive="${DIST_DIR}/initramfs.cpio.xz"
safe_mkdir "$DIST_DIR"
safe_execute touch "$initramfs_archive"
# Download and build kernel modules
kernel_download_source "$KERNEL_DIR" "$KERNEL_VERSION"
kernel_apply_config "$KERNEL_DIR" "$initramfs_archive" "$KERNEL_CONFIG"
kernel_build_modules "$KERNEL_DIR" "$INSTALL_DIR" "$KERNEL_VERSION"
# Set full kernel version for later stages
FULL_KERNEL_VERSION=$(kernel_get_full_version "$KERNEL_VERSION" "$KERNEL_CONFIG")
export FULL_KERNEL_VERSION
log_info "Full kernel version: ${FULL_KERNEL_VERSION}"
}
log_info "Building kernel modules for initramfs inclusion"
kernel_build_modules "$KERNEL_DIR" "$INSTALL_DIR" "$KERNEL_VERSION"
function stage_zinit_setup() {
initramfs_setup_zinit "$INSTALL_DIR" "$ZINIT_CONFIG_DIR"
}
# Phase 8: Setup zinit as init system
initramfs_setup_zinit "$INSTALL_DIR" "$ZINIT_CONFIG_DIR"
function stage_init_script() {
initramfs_install_init_script "$INSTALL_DIR" "${CONFIG_DIR}/init"
}
# Phase 9: Install critical /init script for initramfs boot
initramfs_install_init_script "$INSTALL_DIR" "${CONFIG_DIR}/init"
function stage_modules_setup() {
# Calculate full kernel version (needed for incremental builds when kernel_modules stage is skipped)
local full_kernel_version=$(kernel_get_full_version "$KERNEL_VERSION" "$KERNEL_CONFIG")
export FULL_KERNEL_VERSION="$full_kernel_version"
log_info "Using full kernel version: ${full_kernel_version}"
initramfs_setup_modules "$INSTALL_DIR" "$MODULES_CONF" "$full_kernel_version"
}
# Phase 10: Setup 2-stage module loading
initramfs_setup_modules "$INSTALL_DIR" "$MODULES_CONF" "$KERNEL_VERSION"
function stage_modules_copy() {
# Ensure FULL_KERNEL_VERSION is set (for incremental builds)
if [[ -z "${FULL_KERNEL_VERSION:-}" ]]; then
FULL_KERNEL_VERSION=$(kernel_get_full_version "$KERNEL_VERSION" "$KERNEL_CONFIG")
export FULL_KERNEL_VERSION
fi
log_info "About to copy modules - FULL_KERNEL_VERSION: ${FULL_KERNEL_VERSION}"
log_info "CONTAINER_MODULES_PATH: ${CONTAINER_MODULES_PATH:-not-set}"
initramfs_copy_resolved_modules "$INSTALL_DIR" "$FULL_KERNEL_VERSION"
}
# Phase 11: Aggressive cleanup for size optimization
alpine_aggressive_cleanup "$INSTALL_DIR"
function stage_cleanup() {
alpine_aggressive_cleanup "$INSTALL_DIR"
}
# Phase 12: Strip and UPX all binaries (temporarily skipped to reach kernel phase)
log_info "Skipping strip/UPX optimization to proceed to kernel compilation"
# initramfs_strip_and_upx "$INSTALL_DIR"
function stage_validation() {
initramfs_validate "$INSTALL_DIR"
}
# Phase 13: Validate initramfs
initramfs_validate "$INSTALL_DIR"
function stage_initramfs_create() {
local initramfs_archive="${DIST_DIR}/initramfs.cpio.xz"
initramfs_create_cpio "$INSTALL_DIR" "$initramfs_archive"
export INITRAMFS_ARCHIVE="$initramfs_archive"
}
# Phase 14: Create real initramfs archive (now with modules)
log_info "Creating real initramfs archive with all components and modules"
initramfs_create_cpio "$INSTALL_DIR" "$initramfs_archive"
function stage_initramfs_test() {
initramfs_test_archive "$INITRAMFS_ARCHIVE"
}
# Phase 15: Test archive integrity
initramfs_test_archive "$initramfs_archive"
function stage_kernel_build() {
local kernel_output="${DIST_DIR}/vmlinuz.efi"
kernel_build_with_initramfs "$KERNEL_CONFIG" "$INITRAMFS_ARCHIVE" "$kernel_output"
export KERNEL_OUTPUT="$kernel_output"
}
# Phase 16: Second kernel build with real embedded initramfs
local kernel_output="${DIST_DIR}/vmlinuz.efi"
log_info "Final kernel build: embedding complete initramfs"
kernel_build_with_initramfs "$KERNEL_CONFIG" "$initramfs_archive" "$kernel_output"
function stage_boot_tests() {
if [[ "$SKIP_TESTS" != "true" ]]; then
# Ensure KERNEL_OUTPUT is set (for incremental builds)
if [[ -z "${KERNEL_OUTPUT:-}" ]]; then
KERNEL_OUTPUT="${DIST_DIR}/vmlinuz.efi"
export KERNEL_OUTPUT
fi
testing_run_all "$KERNEL_OUTPUT"
fi
}
# Phase 17: Run boot tests (unless skipped)
if [[ "$SKIP_TESTS" != "true" ]]; then
testing_run_all "$kernel_output"
else
log_info "Skipping boot tests as requested"
fi
# Run all stages with incremental tracking
stage_run "alpine_extract" stage_alpine_extract
stage_run "alpine_configure" stage_alpine_configure
stage_run "alpine_packages" stage_alpine_packages
stage_run "alpine_firmware" stage_alpine_firmware
stage_run "components_build" stage_components_build
stage_run "components_verify" stage_components_verify
stage_run "kernel_modules" stage_kernel_modules
stage_run "zinit_setup" stage_zinit_setup
stage_run "init_script" stage_init_script
stage_run "modules_setup" stage_modules_setup
stage_run "modules_copy" stage_modules_copy
stage_run "cleanup" stage_cleanup
stage_run "validation" stage_validation
stage_run "initramfs_create" stage_initramfs_create
stage_run "initramfs_test" stage_initramfs_test
stage_run "kernel_build" stage_kernel_build
stage_run "boot_tests" stage_boot_tests
# Calculate build time
local end_time=$(date +%s)
@@ -260,8 +346,8 @@ function main_build_process() {
section_header "Build Complete"
log_info "Build time: ${build_minutes}m ${build_seconds}s"
log_info "Output files:"
log_info " Kernel: ${kernel_output} ($(get_file_size "$kernel_output"))"
log_info " Initramfs: ${initramfs_archive} ($(get_file_size "$initramfs_archive"))"
log_info " Kernel: ${KERNEL_OUTPUT} ($(get_file_size "$KERNEL_OUTPUT"))"
log_info " Initramfs: ${INITRAMFS_ARCHIVE} ($(get_file_size "$INITRAMFS_ARCHIVE"))"
}
# Cleanup build artifacts