scripts: Add kernel option validation in prepare_linux

Add validation checks to prepare_linux() to catch invalid
kernel option combinations early:

- Error if --build-guest-kernel and CH_CUSTOM_KERNEL are
  both provided, as they are mutually exclusive.
- On x86_64, error if only one of CH_CUSTOM_KERNEL or
  CH_CUSTOM_BZIMAGE is set; both must be provided together.
- Fix kernel-already-present check: use per-architecture
  branches with correct bash syntax (elif instead of
  else-if, [[ ]] instead of [ && ]) so aarch64 and x86_64
  are each handled properly.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
Muminul Islam
2026-04-27 13:06:59 -07:00
committed by Rob Bradford
parent bb8bbb2961
commit 48e671011c

View File

@@ -187,15 +187,32 @@ download_linux() {
}
prepare_linux() {
if [ "$build_kernel" = true ] && [ -n "$CH_CUSTOM_KERNEL" ]; then
echo "ERROR: --build-guest-kernel and CH_CUSTOM_KERNEL are mutually exclusive"
exit 1
fi
if [ "$(uname -m)" = "x86_64" ]; then
if { [ -n "$CH_CUSTOM_KERNEL" ] && [ -z "$CH_CUSTOM_BZIMAGE" ]; } ||
{ [ -z "$CH_CUSTOM_KERNEL" ] && [ -n "$CH_CUSTOM_BZIMAGE" ]; }; then
echo "ERROR: On x86_64, both CH_CUSTOM_KERNEL and CH_CUSTOM_BZIMAGE must be provided"
exit 1
fi
fi
if [ "$(uname -m)" = "aarch64" ]; then
KERNEL_FILE="$WORKLOADS_DIR/Image-arm64"
else
if [[ -f "$KERNEL_FILE" ]]; then
echo "Kernel already present at $KERNEL_FILE, skipping"
return
fi
elif [ "$(uname -m)" = "x86_64" ]; then
KERNEL_FILE="$WORKLOADS_DIR/vmlinux-x86_64"
BZIMAGE_FILE="$WORKLOADS_DIR/bzImage-x86_64"
fi
if [[ -f "$KERNEL_FILE" && -f "$BZIMAGE_FILE" ]]; then
echo "Kernel already present at $KERNEL_FILE, skipping"
return
if [[ -f "$KERNEL_FILE" ]] && [[ -f "$BZIMAGE_FILE" ]]; then
echo "Kernel already present at $KERNEL_FILE and bzImage at $BZIMAGE_FILE, skipping"
return
fi
fi
if [ "$build_kernel" = true ]; then