fix: major build system improvements and container output issues

- Fix container output visibility with proper TTY handling and debug mode
- Fix build order: kernel modules built before initramfs creation
- Implement two-stage kernel build to resolve chicken-and-egg dependency
- Fix sed command issues in kernel configuration with direct execution
- Add diffutils package to container for proper kernel build support
- Enhance NIC module/firmware correlation with intelligent selection
- Fix module staging logic: all NICs loaded in stage1 before network up
- Add smart firmware installation based on module requirements
- Create comprehensive function documentation (scripts/functionlist.md)
- Add debug container script for troubleshooting

Major fixes:
* Container builds now show real-time output
* Kernel builds work with proper GNU diff support
* Module/firmware selection optimized for common hardware
* Build process handles dependencies correctly
* Documentation provides complete function reference
This commit is contained in:
2025-09-03 14:06:44 +02:00
parent 6d44575860
commit b9f94105cf
23 changed files with 1072 additions and 4310 deletions

View File

@@ -287,9 +287,9 @@ function alpine_aggressive_cleanup() {
find "${initramfs_dir}/usr/share/zoneinfo" -type f ! -name "UTC" ! -path "*/posix/*" -delete 2>/dev/null || true
fi
# Remove empty directories
log_info "Removing empty directories"
find "${initramfs_dir}" -type d -empty -delete 2>/dev/null || true
# Remove empty directories (but preserve essential system directories)
log_info "Removing empty directories (preserving essential system dirs)"
find "${initramfs_dir}" -type d -empty -not -path "*/dev" -not -path "*/proc" -not -path "*/sys" -not -path "*/tmp" -not -path "*/run" -not -path "*/mnt" -not -path "*/home" -not -path "*/root" -not -path "*/opt" -not -path "*/srv" -not -path "*/media*" -delete 2>/dev/null || true
# Calculate size after cleanup
local total_size=$(du -sh "${initramfs_dir}" 2>/dev/null | cut -f1 || echo "unknown")
@@ -322,6 +322,19 @@ function alpine_configure_system() {
section_header "Configuring Alpine System Settings"
# Ensure all essential Linux directories exist
log_info "Creating essential Linux filesystem directories"
local essential_dirs=(
"dev" "proc" "sys" "tmp" "run"
"mnt" "home" "root" "opt" "srv" "media"
"media/cdrom" "media/floppy" "media/usb"
"mnt/cdrom" "mnt/floppy" "mnt/usb"
)
for dir in "${essential_dirs[@]}"; do
safe_mkdir "${initramfs_dir}/${dir}"
done
# Set hostname
echo "zero-os" > "${initramfs_dir}/etc/hostname"
@@ -356,50 +369,74 @@ EOF
log_info "Alpine system configuration complete"
}
# Install firmware packages for hardware support
# Install firmware packages for hardware support (intelligent selection)
function alpine_install_firmware() {
local initramfs_dir="$1"
local firmware_conf="$2"
section_header "Installing Alpine Firmware Packages"
section_header "Installing Required Firmware Packages"
if [[ ! -f "$firmware_conf" ]]; then
log_warn "Firmware configuration not found: ${firmware_conf}"
log_info "Skipping firmware installation"
# Use smart firmware selection from module analysis if available
local firmware_packages=()
if [[ -n "${REQUIRED_FIRMWARE_PACKAGES:-}" ]]; then
log_info "Using intelligent firmware selection based on required modules"
read -ra firmware_packages <<< "$REQUIRED_FIRMWARE_PACKAGES"
for package in "${firmware_packages[@]}"; do
log_info " Required by modules: ${package}"
done
else
log_info "Falling back to firmware configuration file"
if [[ ! -f "$firmware_conf" ]]; then
log_warn "No firmware configuration found and no module requirements"
log_info "Skipping firmware installation"
return 0
fi
# Read firmware packages from config (excluding comments and empty lines)
while IFS=: read -r package description; do
# Skip comments and empty lines
if [[ "$package" =~ ^[[:space:]]*# ]] || [[ -z "${package// }" ]]; then
continue
fi
# Trim whitespace
package=$(echo "$package" | xargs)
description=$(echo "$description" | xargs)
if [[ -n "$package" ]]; then
firmware_packages+=("$package")
log_info " - ${package}: ${description}"
fi
done < "$firmware_conf"
fi
if [[ ${#firmware_packages[@]} -eq 0 ]]; then
log_warn "No firmware packages to install"
return 0
fi
# Setup chroot environment
alpine_setup_chroot "$initramfs_dir"
# Read firmware packages from config (excluding comments and empty lines)
local firmware_packages=()
while IFS=: read -r package description; do
# Skip comments and empty lines
if [[ "$package" =~ ^[[:space:]]*# ]] || [[ -z "${package// }" ]]; then
continue
fi
# Trim whitespace
package=$(echo "$package" | xargs)
description=$(echo "$description" | xargs)
if [[ -n "$package" ]]; then
firmware_packages+=("$package")
log_info " - ${package}: ${description}"
fi
done < "$firmware_conf"
if [[ ${#firmware_packages[@]} -eq 0 ]]; then
log_warn "No firmware packages found in ${firmware_conf}"
alpine_cleanup_chroot "$initramfs_dir"
return 0
fi
log_info "Installing ${#firmware_packages[@]} firmware packages"
# Install firmware packages
safe_execute chroot "$initramfs_dir" apk add --no-cache "${firmware_packages[@]}"
# Install firmware packages (allow failures for missing packages)
local failed_packages=()
for package in "${firmware_packages[@]}"; do
if chroot "$initramfs_dir" apk add --no-cache "$package" 2>/dev/null; then
log_info "✓ Installed firmware: $package"
else
log_warn "✗ Failed to install firmware: $package (may not be available)"
failed_packages+=("$package")
fi
done
# Report installation results
local installed_count=$((${#firmware_packages[@]} - ${#failed_packages[@]}))
log_info "Firmware installation: ${installed_count} installed, ${#failed_packages[@]} failed"
# List installed firmware files
log_info "Checking installed firmware files:"
@@ -409,17 +446,19 @@ function alpine_install_firmware() {
local firmware_size=$(du -sh "${initramfs_dir}/lib/firmware" 2>/dev/null | cut -f1 || echo "0B")
log_info " Firmware files: ${firmware_count} (${firmware_size})"
# Log some example firmware files for verification
# Log some example firmware files for verification (avoid SIGPIPE)
log_debug "Sample firmware files:"
find "${initramfs_dir}/lib/firmware" -type f | head -10 | while read -r fw; do
log_debug " $(basename "$fw")"
done
if [[ $firmware_count -gt 0 ]]; then
find "${initramfs_dir}/lib/firmware" -type f -print0 | head -z -n 10 | while IFS= read -r -d '' fw; do
log_debug " $(basename "$fw")"
done 2>/dev/null || true
fi
else
log_warn "No firmware directory found after installation"
fi
alpine_cleanup_chroot "$initramfs_dir"
log_info "Firmware installation complete: ${firmware_count} files"
log_info "Smart firmware installation complete: ${firmware_count} files"
}
# Export functions