initramfs+modules: robust copy aliasing, curated stage1 + PHYs, firmware policy via firmware.conf, runtime readiness, build ID; docs sync

Summary of changes (with references):\n\nModules + PHY coverage\n- Curated and normalized stage1 list in [config.modules.conf](config/modules.conf:1):\n  - Boot-critical storage, core virtio, common NICs (Intel/Realtek/Broadcom), overlay/fuse, USB HCD/HID.\n  - Added PHY drivers required by NIC MACs:\n    * realtek (for r8169, etc.)\n    * broadcom families: broadcom, bcm7xxx, bcm87xx, bcm_phy_lib, bcm_phy_ptp\n- Robust underscore↔hyphen aliasing during copy so e.g. xhci_pci → xhci-pci.ko, hid_generic → hid-generic.ko:\n  - [bash.initramfs_copy_resolved_modules()](scripts/lib/initramfs.sh:990)\n\nFirmware policy and coverage\n- Firmware selection now authoritative via [config/firmware.conf](config/firmware.conf:1); ignore modules.conf firmware hints:\n  - [bash.initramfs_setup_modules()](scripts/lib/initramfs.sh:229)\n  - Count from firmware.conf for reporting; remove stale required-firmware.list.\n- Expanded NIC firmware set (bnx2, bnx2x, tigon, intel, realtek, rtl_nic, qlogic, e100) in [config.firmware.conf](config/firmware.conf:1).\n- Installer enforces firmware.conf source-of-truth in [bash.alpine_install_firmware()](scripts/lib/alpine.sh:392).\n\nEarly input & build freshness\n- Write a runtime build stamp to /etc/zero-os-build-id for embedded initramfs verification:\n  - [bash.initramfs_finalize_customization()](scripts/lib/initramfs.sh:568)\n- Minor init refinements in [config.init](config/init:1) (ensures /home, consistent depmod path).\n\nRebuild helper improvements\n- [scripts/rebuild-after-zinit.sh](scripts/rebuild-after-zinit.sh:1):\n  - Added --verify-only; container-aware execution; selective marker clears only.\n  - Prints stage status before/after; avoids --rebuild-from; resolves full kernel version for diagnostics.\n\nRemote flist readiness + zinit\n- Init scripts now probe BASE_URL readiness and accept FLISTS_BASE_URL/FLIST_BASE_URL; firmware target is /lib/firmware:\n  - [sh.firmware.sh](config/zinit/init/firmware.sh:1)\n  - [sh.modules.sh](config/zinit/init/modules.sh:1)\n\nContainer, docs, and utilities\n- Stream container build logs by calling runtime build directly in [bash.docker_build_container()](scripts/lib/docker.sh:56).\n- Docs updated to reflect firmware policy, runtime readiness, rebuild helper, early input, and GRUB USB:\n  - [docs.NOTES.md](docs/NOTES.md)\n  - [docs.PROMPT.md](docs/PROMPT.md)\n  - [docs.review-rfs-integration.md](docs/review-rfs-integration.md)\n- Added GRUB USB creator (referenced in docs): [scripts/make-grub-usb.sh](scripts/make-grub-usb.sh)\n\nCleanup\n- Removed legacy/duplicated config trees under configs/ and config/zinit.old/.\n- Minor newline and ignore fixes: [.gitignore](.gitignore:1)\n\nNet effect\n- Runtime now has correct USB HCDs/HID-generic and NIC+PHY coverage (Realtek/Broadcom), with matching firmware installed in initramfs.\n- Rebuild workflow is minimal and host/container-aware; docs are aligned with implemented behavior.\n
This commit is contained in:
2025-09-23 14:03:01 +02:00
parent 2fba2bd4cd
commit ad0a06e267
87 changed files with 833 additions and 17307 deletions

View File

@@ -5,6 +5,7 @@
# scripts/rebuild-after-zinit.sh --run-tests # include boot tests (still no kernel rebuild by default)
# scripts/rebuild-after-zinit.sh --with-kernel # also rebuild kernel (re-embed updated initramfs)
# scripts/rebuild-after-zinit.sh --refresh-container-mods # rebuild container /lib/modules if missing (kernel modules stage)
# scripts/rebuild-after-zinit.sh --verify-only # only report detected changes, do not rebuild
# scripts/rebuild-after-zinit.sh -- ... # pass extra args to build.sh
set -euo pipefail
@@ -19,6 +20,7 @@ run_tests=0
extra_args=()
rebuild_kernel=0
refresh_container_mods=0
verify_only=0
# Parse flags; pass through any remaining args to build.sh after --
while [[ $# -gt 0 ]]; do
@@ -35,6 +37,10 @@ while [[ $# -gt 0 ]]; do
refresh_container_mods=1
shift
;;
--verify-only)
verify_only=1
shift
;;
--)
shift
extra_args=("$@")
@@ -51,6 +57,108 @@ done
log "PROJECT_ROOT=${PROJECT_ROOT}"
log "STAGES_DIR=${STAGES_DIR}"
# Show current stage status before any changes (host-safe; does not require container)
log "Stage status (before):"
("${PROJECT_ROOT}/scripts/build.sh" --show-stages) || true
# ------------------------------------------------------------
# Container detection helper
# ------------------------------------------------------------
in_container() {
[[ -f /.dockerenv ]] || [[ -f /run/.containerenv ]] || grep -q 'container' /proc/1/cgroup 2>/dev/null
}
# ------------------------------------------------------------
# Change detection (verify what changed since last archive build)
# ------------------------------------------------------------
marker_init="${STAGES_DIR}/initramfs_create.done"
marker_time=0
if [[ -f "$marker_init" ]]; then
marker_time=$(stat -c %Y "$marker_init" 2>/dev/null || echo 0)
fi
log "Detecting changes since last initramfs_create marker: ${marker_init:-<none>}"
check_dir_changed() {
local path="$1"
local cutoff="$2"
local count
count=$(find "$path" -type f -printf '%T@ %p\n' 2>/dev/null | awk -v c="$cutoff" '$1 > c {n++} END {print n+0}')
echo "${count:-0}"
}
list_some_changes() {
local path="$1"
local cutoff="$2"
# list up to 5 example files
find "$path" -type f -printf '%T@ %p\n' 2>/dev/null | awk -v c="$cutoff" '$1 > c {print $2}' | head -n 5
}
zinit_dir="${PROJECT_ROOT}/config/zinit"
init_file="${PROJECT_ROOT}/config/init"
modules_conf="${PROJECT_ROOT}/config/modules.conf"
zinit_changed=0
init_changed=0
modules_changed=0
if [[ -d "$zinit_dir" ]]; then
zinit_changed=$(check_dir_changed "$zinit_dir" "$marker_time")
fi
if [[ -f "$init_file" ]]; then
if [[ $(stat -c %Y "$init_file" 2>/dev/null || echo 0) -gt $marker_time ]]; then init_changed=1; fi
fi
if [[ -f "$modules_conf" ]]; then
if [[ $(stat -c %Y "$modules_conf" 2>/dev/null || echo 0) -gt $marker_time ]]; then modules_changed=1; fi
fi
log "Changes since last archive:"
log " - config/zinit: ${zinit_changed} file(s) changed"
if [[ "$zinit_changed" -gt 0 ]]; then
list_some_changes "$zinit_dir" "$marker_time" | sed 's/^/ * /' || true
fi
log " - config/init: $([[ $init_changed -eq 1 ]] && echo changed || echo unchanged)"
log " - config/modules.conf: $([[ $modules_changed -eq 1 ]] && echo changed || echo unchanged)"
if [[ "$verify_only" -eq 1 ]]; then
log "verify-only set; exiting without rebuild"
exit 0
fi
# ------------------------------------------------------------
# Container /lib/modules/<FULL_VERSION> presence diagnostics
# (we never clear kernel_modules unless --refresh-container-mods is given)
# ------------------------------------------------------------
compute_full_kver() {
# Read from configs without sourcing (safe in any shell)
local build_conf="${PROJECT_ROOT}/config/build.conf"
local kcfg="${PROJECT_ROOT}/config/kernel.config"
local base_ver=""
local localver=""
if [[ -f "$build_conf" ]]; then
base_ver="$(grep -E '^KERNEL_VERSION=' "$build_conf" | head -1 | cut -d= -f2 | tr -d '\"')"
fi
if [[ -f "$kcfg" ]]; then
localver="$(grep -E '^CONFIG_LOCALVERSION=' "$kcfg" | head -1 | cut -d'\"' -f2)"
fi
echo "${base_ver}${localver}"
}
modules_dir_for_full() {
local full="$1"
echo "/lib/modules/${full}"
}
full_kver="$(compute_full_kver)"
container_modules_dir="$(modules_dir_for_full "$full_kver")"
log "Container modules version: ${full_kver:-<unknown>}"
if [[ -d "$container_modules_dir" ]]; then
before_count=$(find "$container_modules_dir" -type f -name '*.ko*' 2>/dev/null | wc -l | tr -d ' ')
log "Before build: ${container_modules_dir} exists with ${before_count} module file(s)"
else
log "Before build: ${container_modules_dir} not present (fresh container scenario)"
fi
# Minimal set of stages to clear when zinit changes:
# - zinit_setup: recopy zinit YAML and init scripts into initramfs
# - validation: re-check initramfs contents
@@ -87,6 +195,7 @@ if [[ "$rebuild_kernel" -eq 1 ]]; then
fi
# Remove completion markers to force incremental rebuild of those stages
log "Planned markers to clear: ${stages_to_clear[*]}"
for s in "${stages_to_clear[@]}"; do
marker="${STAGES_DIR}/${s}.done"
if [[ -f "$marker" ]]; then
@@ -97,20 +206,39 @@ for s in "${stages_to_clear[@]}"; do
fi
done
# Show stage status after marker removal (still host-safe)
log "Stage status (after marker removal):"
("${PROJECT_ROOT}/scripts/build.sh" --show-stages) || true
# Build
log "Starting incremental rebuild (zinit changes)"
# If we plan to rebuild the kernel, force the pipeline to run from initramfs_create
# so the cpio archive is recreated before kernel_build (ignoring prior .done markers).
# IMPORTANT: Do NOT pass --rebuild-from or --force-rebuild; that would force ALL stages to run.
# We rely exclusively on removed markers to minimally re-run only the necessary stages.
build_from_args=()
if [[ "$rebuild_kernel" -eq 1 ]]; then
build_from_args=(--rebuild-from=initramfs_create)
log "Rebuild-from: initramfs_create (guarantee cpio is recreated before kernel_build)"
fi
if [[ "$run_tests" -eq 1 ]]; then
log "Including boot tests"
DEBUG=1 "${PROJECT_ROOT}/scripts/build.sh" "${build_from_args[@]}" "${extra_args[@]}"
if in_container; then
# Run directly when already inside the dev/build container
if [[ "$run_tests" -eq 1 ]]; then
log "Including boot tests (in-container)"
DEBUG=1 "${PROJECT_ROOT}/scripts/build.sh" "${build_from_args[@]}" "${extra_args[@]}"
else
log "Skipping boot tests (in-container)"
DEBUG=1 "${PROJECT_ROOT}/scripts/build.sh" --skip-tests "${build_from_args[@]}" "${extra_args[@]}"
fi
else
log "Skipping boot tests (use --run-tests to include)"
DEBUG=1 "${PROJECT_ROOT}/scripts/build.sh" --skip-tests "${build_from_args[@]}" "${extra_args[@]}"
# Not in container: delegate to dev-container manager which ensures container exists and is running
devctl="${PROJECT_ROOT}/scripts/dev-container.sh"
if [[ ! -x "$devctl" ]]; then
log "[ERROR] Dev container manager not found: ${devctl}"
log "[HINT] Run ./scripts/build.sh directly (it can start a transient container), or start the dev container via ./scripts/dev-container.sh start"
exit 1
fi
if [[ "$run_tests" -eq 1 ]]; then
log "Including boot tests via dev-container"
"$devctl" build "${build_from_args[@]}" "${extra_args[@]}"
else
log "Skipping boot tests via dev-container"
"$devctl" build --skip-tests "${build_from_args[@]}" "${extra_args[@]}"
fi
fi