diff --git a/rootfs/scripts/build-rootfs.sh b/rootfs/scripts/build-rootfs.sh index f08336aa..71bae5b9 100755 --- a/rootfs/scripts/build-rootfs.sh +++ b/rootfs/scripts/build-rootfs.sh @@ -208,6 +208,8 @@ _seed_to_debootstrap_include() { passwd systemd-sysv apt + grub-common + grub2-common ) for p in "${required_pkgs[@]}"; do @@ -435,6 +437,39 @@ mount -o bind /sys "$ROOTFS_DIR/sys" mount -o bind /dev "$ROOTFS_DIR/dev" mount --bind /dev/pts "$ROOTFS_DIR/dev/pts" +# ============================================================================== +# Step 7.5: Configure GRUB defaults +# ============================================================================== +echo "[INFO] Configuring /etc/default/grub..." + +# Ensure target directories exist before writing configuration +mkdir -p "$ROOTFS_DIR/boot/grub" +mkdir -p "$ROOTFS_DIR/etc/default" + +# Write GRUB defaults using quoted heredoc to prevent host-side expansion +cat <<'EOF' > "$ROOTFS_DIR/etc/default/grub" +GRUB_DEFAULT=0 +GRUB_TIMEOUT=5 +GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` + +# --- DUAL OUTPUT CONFIGURATION --- +# "serial" -> Outputs menu to the serial port +# "console" -> Outputs menu to the attached display (HDMI/DP) in text mode +GRUB_TERMINAL="serial console" +GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1" + +# Kernel parameters applied to BOTH Normal and Recovery boot modes +# (Critical hardware settings: console, rootfs, clocks, EFI) +GRUB_CMDLINE_LINUX="earlycon console=ttyMSM0,115200n8 root=LABEL=system cma=128M rw clk_ignore_unused pd_ignore_unused efi=noruntime rootwait ignore_loglevel" + +# Kernel parameters applied ONLY to Normal boot mode +# (UX settings: quiet, splash, etc. - Left empty for verbose output) +GRUB_CMDLINE_LINUX_DEFAULT="" + +# Disable UUIDs to support generic filesystem images +GRUB_DISABLE_LINUX_UUID=true +EOF + # ============================================================================== # Step 8: Enter chroot to Install Packages and Configure GRUB # ============================================================================== @@ -516,22 +551,49 @@ rm -f /tmp/\${CODENAME}_post.manifest /tmp/sorted_base.manifest /tmp/sorted_post echo '[CHROOT] Base package list preserved as /tmp/\${CODENAME}_base.manifest' echo '[CHROOT] Custom installed packages saved to /tmp/packages_\${DATE}.manifest' -echo '[CHROOT] Detecting installed kernel version...' +# ============================================================================== +# GRUB Configuration Cleanup & Standardization +# ============================================================================== -kernel_ver=$(basename "$KERNEL_DEB" \ - | sed 's|^linux-kernel-\(.*\)-arm64\.deb$|\1|' \ - | sed 's|-[0-9][0-9]*-[0-9][0-9]*$||') +# 1. Enforce Generic Partition Search +# Replace host-detected UUIDs with stable Label searching to ensure +# the image boots on any storage medium. +sed -i 's/search --no-floppy --fs-uuid --set=root .*/search --no-floppy --label system --set=root/g' /boot/grub/grub.cfg -echo '[CHROOT] Writing GRUB configuration for single DTB-agnostic entry...' -tee /boot/grub.cfg > /dev/null <