fix: resolve kernel module installation and packaging issues

- Fixed resolve-module-dependencies.sh to handle missing modules gracefully
- Removed destructive 'set -e' behavior that caused immediate exit on missing modules
- Enhanced install-firmware-minimal.sh to handle partial success scenarios
- Fixed install-packages.sh to preserve installed kernel modules (was deleting them)
- Improved setup-initramfs.sh to ensure modules directory always exists
- Now successfully installs 43 essential kernel modules in final initramfs
- Fixes 'depmod: ERROR: could not open directory /lib/modules' boot issue

All kernel modules (.ko files) are now properly included in the final cpio archive.
This commit is contained in:
2025-08-22 16:39:11 +02:00
parent 56c3813609
commit 91d20b9226
4 changed files with 120 additions and 32 deletions

View File

@@ -12,21 +12,27 @@ mkdir -p "$FIRMWARE_DIR"
# Install full linux-firmware temporarily to extract essentials
echo " Downloading and extracting linux-firmware package..."
cd /tmp
apk fetch linux-firmware
firmware_file=$(ls linux-firmware-*.apk | head -1)
if [ -f "$firmware_file" ]; then
tar -xf "$firmware_file"
echo " Firmware package extracted successfully"
if apk fetch linux-firmware 2>/dev/null; then
firmware_file=$(ls linux-firmware-*.apk 2>/dev/null | head -1)
if [ -f "$firmware_file" ]; then
tar -xf "$firmware_file"
echo " Firmware package extracted successfully"
FIRMWARE_AVAILABLE=true
else
echo " Warning: Failed to extract linux-firmware package"
FIRMWARE_AVAILABLE=false
fi
else
echo " Error: Failed to download linux-firmware package"
exit 1
echo " Warning: Failed to download linux-firmware package (network/repo issue)"
FIRMWARE_AVAILABLE=false
fi
# Extract only essential network firmware
echo " Installing essential network drivers..."
if [ "$FIRMWARE_AVAILABLE" = "true" ]; then
echo " Installing essential network drivers..."
# Intel Ethernet (most common)
if [ -d lib/firmware/intel ]; then
# Intel Ethernet (most common)
if [ -d lib/firmware/intel ]; then
mkdir -p "$FIRMWARE_DIR/intel"
# e1000e, ixgbe, i40e, ice drivers
find lib/firmware/intel -name "*e1000*" -exec cp {} "$FIRMWARE_DIR/intel/" \; 2>/dev/null || true
@@ -64,6 +70,9 @@ fi
# Essential system firmware
if [ -f lib/firmware/regulatory.db ]; then
cp lib/firmware/regulatory.db* "$FIRMWARE_DIR/" 2>/dev/null || true
fi
else
echo " Skipping firmware installation due to download failure"
fi
# Cleanup temporary files
@@ -89,22 +98,28 @@ if [ -d "$KERNEL_BUILD_DIR" ]; then
echo " Using modinfo-based dependency resolver..."
# Use the automatic dependency resolver with essential modules list
echo " Running automatic module dependency resolution..."
if /build/scripts/resolve-module-dependencies.sh \
-k "$KERNEL_BUILD_DIR" \
-m "$MODULES_DIR" \
-v "${KERNEL_VERSION}-Zero-OS" \
/build/configs/modules-essential.list; then
echo " ✓ Automatic module dependency resolution completed successfully"
# Count installed modules
# Count installed modules to verify some success
module_count=$(find "$MODULES_DIR" -name "*.ko" 2>/dev/null | wc -l)
echo " Installed $module_count kernel modules with complete dependency chains"
if [ "$module_count" -gt 0 ]; then
echo " ✓ Automatic module dependency resolution completed successfully"
echo " Installed $module_count kernel modules with complete dependency chains"
else
echo " ⚠ Module dependency resolution completed but no modules found"
echo " This might indicate kernel build directory issues"
fi
# Create modules.dep and modules.alias for module loading
echo " Creating module dependency files..."
if command -v depmod >/dev/null 2>&1; then
depmod -b "$INITRAMFS_ROOT" "${KERNEL_VERSION}-Zero-OS" 2>/dev/null || true
if command -v depmod >/dev/null 2>&1; then
depmod -a -b "$INITRAMFS_ROOT" "${KERNEL_VERSION}-Zero-OS" 2>/dev/null || true
fi
# Create basic module files if depmod failed
@@ -115,20 +130,41 @@ if [ -d "$KERNEL_BUILD_DIR" ]; then
fi
else
echo " Warning: Automatic dependency resolution failed, falling back to manual installation"
echo " Automatic dependency resolution failed, falling back to manual installation"
# Fallback to minimal manual installation
mkdir -p "$MODULES_DIR/kernel/drivers/net"
mkdir -p "$MODULES_DIR/kernel/drivers/block"
mkdir -p "$MODULES_DIR/kernel/net"
# Install only the most critical modules manually
# Install only the most critical modules manually if they exist
for module in tun e1000e virtio_net overlay; do
find "$KERNEL_BUILD_DIR" -name "${module}.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/net/" \; 2>/dev/null || true
done
# Install virtio block driver
find "$KERNEL_BUILD_DIR" -name "virtio_blk.ko" -exec cp {} "$MODULES_DIR/kernel/drivers/block/" \; 2>/dev/null || true
module_count=$(find "$MODULES_DIR" -name "*.ko" 2>/dev/null | wc -l)
echo " Fallback: Installed $module_count essential modules"
# Create basic module dependency files for depmod compatibility
echo " Creating basic module dependency files..."
touch "$MODULES_DIR/modules.dep"
touch "$MODULES_DIR/modules.alias"
touch "$MODULES_DIR/modules.symbols"
touch "$MODULES_DIR/modules.builtin"
touch "$MODULES_DIR/modules.devname"
fi
else
echo " Warning: Kernel build directory not found at $KERNEL_BUILD_DIR"
# Still create the modules directory structure for depmod compatibility
echo " Creating minimal modules directory structure..."
mkdir -p "$MODULES_DIR"
touch "$MODULES_DIR/modules.dep"
touch "$MODULES_DIR/modules.alias"
touch "$MODULES_DIR/modules.symbols"
touch "$MODULES_DIR/modules.builtin"
touch "$MODULES_DIR/modules.devname"
fi
# Create essential kernel module directories that eudev expects