ix init script duplication and CPIO creation issues

- Remove duplicate /sbin/init copying from initramfs_setup_zinit()
- Only /init should be config/init (initramfs setup script)
- No /sbin/init needed - config/init calls 'switch_root /mnt/root /sbin/zinit init'
- Remove unsupported cpio --owner option that broke CPIO creation
- Fix validation to not expect /sbin/init file
- Correct boot flow: /init → switch_root → /sbin/zinit init
- Remove strip and UPX compression from zinit binary copying
- UPX compression was corrupting the zinit binary causing segfaults after switch_root
- Keep zinit unmodified as it's
This commit is contained in:
2025-09-05 11:43:25 +02:00
parent 38dee2de74
commit 8c3868b242
102 changed files with 589 additions and 375 deletions

View File

@@ -10,6 +10,20 @@ KERNEL_VERSION="${KERNEL_VERSION:-6.12.44}"
KERNEL_SOURCE_URL="${KERNEL_SOURCE_URL:-https://cdn.kernel.org/pub/linux/kernel}"
KERNEL_CONFIG_SOURCE="${KERNEL_CONFIG_SOURCE:-${PROJECT_ROOT}/configs/kernel-config-generic}"
# Get actual kernel version including LOCALVERSION from kernel config
function kernel_get_full_version() {
local base_version="${1:-$KERNEL_VERSION}"
local config_file="${2:-${PROJECT_ROOT}/config/kernel.config}"
# Extract LOCALVERSION from kernel config
local localversion=""
if [[ -f "$config_file" ]] && grep -q "^CONFIG_LOCALVERSION=" "$config_file"; then
localversion=$(grep "^CONFIG_LOCALVERSION=" "$config_file" | cut -d'"' -f2)
fi
echo "${base_version}${localversion}"
}
# Download kernel source
function kernel_download_source() {
local kernel_dir="$1"
@@ -176,10 +190,6 @@ function kernel_build_with_initramfs() {
local source_dir="${kernel_dir}/current"
safe_execute cd "$source_dir"
# Clean previous build
log_info "Cleaning previous kernel build"
safe_execute make clean
# Determine number of cores for parallel build
local cores=$(nproc)
local jobs=$((cores > 1 ? cores - 1 : 1)) # Leave one core free
@@ -215,13 +225,13 @@ function kernel_build_with_initramfs() {
fi
}
# Build modules for initramfs
# Build and install modules in container for proper dependency resolution
function kernel_build_modules() {
local kernel_dir="$1"
local modules_install_dir="$2"
local version="${3:-$KERNEL_VERSION}"
local initramfs_dir="$2"
local base_version="${3:-$KERNEL_VERSION}"
section_header "Building Kernel Modules"
section_header "Building Kernel Modules in Container"
local source_dir="${kernel_dir}/current"
@@ -232,6 +242,11 @@ function kernel_build_modules() {
safe_execute cd "$source_dir"
# Get the full kernel version including LOCALVERSION
local full_version=$(kernel_get_full_version "$base_version" "${PROJECT_ROOT}/config/kernel.config")
log_info "Base kernel version: ${base_version}"
log_info "Full kernel version: ${full_version}"
# Build modules
local cores=$(nproc)
local jobs=$((cores > 1 ? cores - 1 : 1))
@@ -239,19 +254,30 @@ function kernel_build_modules() {
log_info "Building kernel modules with ${jobs} parallel jobs"
safe_execute make -j${jobs} modules
# Install modules to staging area
log_info "Installing modules to: ${modules_install_dir}"
safe_mkdir "$modules_install_dir"
safe_execute make modules_install INSTALL_MOD_PATH="$modules_install_dir"
# Install modules in container for proper modinfo/depmod access
local container_modules_dir="/lib/modules"
log_info "Installing modules in container: ${container_modules_dir}"
safe_execute make modules_install INSTALL_MOD_PATH=/
# Run depmod to create module dependencies
local modules_dir="${modules_install_dir}/lib/modules/${version}"
if [[ -d "$modules_dir" ]]; then
log_info "Running depmod for module dependencies"
safe_execute depmod -a -b "$modules_install_dir" "$version"
# Run depmod in container context for proper dependency resolution
log_info "Running depmod in container for ${full_version}"
safe_execute depmod -a "$full_version"
# Verify module installation in container
if [[ -d "/lib/modules/${full_version}" ]]; then
local module_count=$(find "/lib/modules/${full_version}" -name "*.ko*" | wc -l)
log_info "Container modules installed: ${module_count} modules in /lib/modules/${full_version}"
# Export the container modules path for dependency resolution
export CONTAINER_MODULES_PATH="/lib/modules/${full_version}"
export KERNEL_FULL_VERSION="$full_version"
log_info "Module dependency resolution will use: ${CONTAINER_MODULES_PATH}"
else
log_error "Module installation in container failed"
return 1
fi
log_info "Kernel modules build complete"
log_info "Kernel modules build and container installation complete"
}
# Clean kernel build artifacts
@@ -278,4 +304,4 @@ function kernel_cleanup() {
# Export functions
export -f kernel_download_source kernel_apply_config kernel_modify_config_for_initramfs
export -f kernel_build_with_initramfs kernel_build_modules kernel_cleanup
export -f kernel_build_with_initramfs kernel_build_modules kernel_cleanup kernel_get_full_version