build: guard INITRAMFS_ARCHIVE in stage_kernel_build for incremental runs
Some checks failed
Build Zero OS Initramfs / build (push) Has been cancelled
Build Zero OS Initramfs / test-matrix (qemu, basic) (push) Has been cancelled
Build Zero OS Initramfs / test-matrix (qemu, serial) (push) Has been cancelled

initramfs: ensure essential dirs incl. /home exist during finalize and validate 'home' as essential item
This commit is contained in:
2025-09-09 17:00:38 +02:00
parent 998e40c2e5
commit 16955ea84f
2 changed files with 21 additions and 2 deletions

View File

@@ -397,6 +397,17 @@ function main_build_process() {
function stage_kernel_build() {
local kernel_output="${DIST_DIR}/vmlinuz.efi"
# Ensure INITRAMFS_ARCHIVE is set even if initramfs_create/test were skipped previously
if [[ -z "${INITRAMFS_ARCHIVE:-}" ]]; then
local archive_path="${DIST_DIR}/initramfs.cpio.xz"
if [[ "${archive_path}" != /* ]]; then
archive_path="${PROJECT_ROOT}/${archive_path#./}"
fi
export INITRAMFS_ARCHIVE="${archive_path}"
log_debug "stage_kernel_build: defaulting INITRAMFS_ARCHIVE=${INITRAMFS_ARCHIVE}"
fi
kernel_build_with_initramfs "$KERNEL_CONFIG" "$INITRAMFS_ARCHIVE" "$kernel_output"
export KERNEL_OUTPUT="$kernel_output"
}

View File

@@ -631,6 +631,14 @@ EOF
log_info "Branding disabled: leaving /etc/motd, /etc/issue and root password unchanged"
fi
# Ensure essential Linux filesystem directories exist (defensive), including /home
# Some earlier stages or cleanups may have run in previous builds; enforce presence now.
log_info "Ensuring essential directories exist (including /home)"
local _ensure_dirs=("dev" "proc" "sys" "tmp" "run" "mnt" "home" "root" "opt" "srv" "media" "media/cdrom" "media/floppy" "media/usb")
for _d in "${_ensure_dirs[@]}"; do
safe_mkdir "${initramfs_dir}/${_d}"
done
# Ensure ntp.conf exists for hooks. Create only if absent, do not overwrite.
if [[ ! -f "${initramfs_dir}/etc/ntp.conf" ]]; then
log_info "Creating ntp.conf with Google NTP servers (absent)"
@@ -735,7 +743,7 @@ function initramfs_create_cpio() {
local pre_cpio_file_count
pre_cpio_file_count=$(find "${initramfs_dir}" -mindepth 1 | wc -l || echo "0")
log_info "Pre-CPIO sanity: ${pre_cpio_file_count} files under ${initramfs_dir}"
local _essential_items=("init" "sbin/zinit" "bin/busybox" "etc/zinit" "lib" "usr/bin" "var" "tmp" "proc" "sys" "dev")
local _essential_items=("init" "sbin/zinit" "bin/busybox" "etc/zinit" "lib" "usr/bin" "home" "var" "tmp" "proc" "sys" "dev")
for _item in "${_essential_items[@]}"; do
if [[ -e "${initramfs_dir}/${_item}" ]]; then
log_debug "pre-cpio OK: ${_item}"