Skip to content

Commit 602443e

Browse files
rootfs: run update-grub after all package installs
Problem - update-grub was executed immediately after the direct kernel `dpkg -i`, before overlay apt packages and local-debs repo packages were installed. - When the effective kernel came from overlay manifest apt sources, GRUB generation could observe stale kernel state. Implementation - Move post-bootloader actions to after all install sources complete: 1. firmware `dpkg -i` (optional) 2. kernel `dpkg -i` (optional) 3. overlay manifest apt packages 4. local-debs apt repository packages 5. update-grub 6. grub cleanup/normalization 7. package manifest capture/delta generation - Keep the explicit update-grub invocation in the chroot (do not rely on hook execution gated by systemd runtime presence). Result - Bootloader state reflects final package-set convergence rather than an intermediate state. - The kernel delivery path (direct deb vs apt overlay vs local deb repo) no longer changes GRUB correctness. Scope - Install-order and bootloader-timing correction only; the DTB policy cleanup remains separate. Signed-off-by: Bjordis Collaku <bcollaku@qti.qualcomm.com>
1 parent 5d1f840 commit 602443e

1 file changed

Lines changed: 33 additions & 24 deletions

File tree

rootfs/scripts/build-rootfs.sh

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
# (via apt or local .deb) inside the rootfs.
1919
# - Supports injecting custom apt sources from the package manifest.
2020
# - Optionally injects custom kernel and firmware .deb packages.
21+
# - Supports installing kernel packages via APT through the --overlay manifest
22+
# (source: apt); update-grub runs after all installs regardless of kernel path.
2123
# - Supports installing local .deb packages (--local-debs) with full dependency resolution
2224
# via a temporary local APT repository built inside the rootfs.
2325
# - Installs user-specified packages from seed and/or overlay manifest.
@@ -625,10 +627,6 @@ echo '[CHROOT] Installing custom firmware and kernel...'
625627
$CMD_FW_INSTALL
626628
$CMD_KERNEL_INSTALL
627629
628-
# Run update-grub explicitly: the zz-update-grub hook skips it in a chroot
629-
# because systemd is not running (/run/systemd/system absent).
630-
update-grub
631-
632630
adduser --disabled-password --gecos '' qcom
633631
echo 'qcom:qcom' | chpasswd
634632
usermod -aG sudo qcom
@@ -653,20 +651,15 @@ else
653651
echo '[CHROOT] No local .deb packages found; skipping.'
654652
fi
655653
656-
echo '[CHROOT] Capturing post-install package list...'
657-
dpkg-query -W -f='\${Package} \${Version}\n' > /tmp/\${CODENAME}_post.manifest
658-
659-
echo '[CHROOT] Sorting and computing package delta...'
660-
sort /tmp/\${CODENAME}_base.manifest > /tmp/sorted_base.manifest
661-
sort /tmp/\${CODENAME}_post.manifest > /tmp/sorted_post.manifest
662-
DATE=\$(date +%Y-%m-%d)
663-
comm -13 /tmp/sorted_base.manifest /tmp/sorted_post.manifest > /tmp/packages_\${DATE}.manifest
664-
665-
echo '[CHROOT] Cleaning up intermediate files...'
666-
rm -f /tmp/\${CODENAME}_post.manifest /tmp/sorted_base.manifest /tmp/sorted_post.manifest
667-
668-
echo '[CHROOT] Base package list preserved as /tmp/\${CODENAME}_base.manifest'
669-
echo '[CHROOT] Custom installed packages saved to /tmp/packages_\${DATE}.manifest'
654+
# ==============================================================================
655+
# Run update-grub after ALL installs (firmware, kernel via dpkg or apt, manifest,
656+
# local-debs). This ensures GRUB sees whichever kernel was installed last,
657+
# regardless of the delivery path.
658+
# The zz-update-grub hook skips update-grub in a chroot because systemd is not
659+
# running (/run/systemd/system absent), so we call it explicitly here.
660+
# ==============================================================================
661+
echo '[CHROOT] Running update-grub after all package installs...'
662+
update-grub
670663
671664
# ==============================================================================
672665
# GRUB Configuration Cleanup & Standardization
@@ -686,27 +679,43 @@ sed -i 's/root=\/dev\/[^ ]* //g' /boot/grub/grub.cfg
686679
# Device Tree Configuration for Debian platforms
687680
# ==============================================================================
688681
689-
if [ \"\${distro_lc}\" = \"debian\" ]; then
682+
if [ "\${distro_lc}" = "debian" ]; then
690683
echo '[INFO][CHROOT] Debian target detected. Configuring platform Device Tree...'
691684
692685
# Locate the platform Device Tree Blob (DTB) in standard library or firmware paths
693-
DTB_PATH=\$(find /usr/lib /lib/firmware -name \"glymur-crd.dtb\" -print -quit)
686+
DTB_PATH=\$(find /usr/lib /lib/firmware -name "glymur-crd.dtb" -print -quit)
694687
695-
if [ -n \"\$DTB_PATH\" ]; then
696-
echo \"[INFO][CHROOT] Platform DTB resolved: \$DTB_PATH\"
688+
if [ -n "\$DTB_PATH" ]; then
689+
echo "[INFO][CHROOT] Platform DTB resolved: \$DTB_PATH"
697690
698691
# Ensure DTB is accessible in the bootloader's filesystem scope
699-
ln -sf \"\$DTB_PATH\" /boot/dtb
692+
ln -sf "\$DTB_PATH" /boot/dtb
700693
701694
# Inject the devicetree directive into the generated GRUB configuration.
702695
# This appends the command immediately following the 'initrd' load.
703-
sed -i \"/^[[:space:]]*initrd/a \ devicetree /boot/dtb\" /boot/grub/grub.cfg
696+
sed -i "/^[[:space:]]*initrd/a \ devicetree /boot/dtb" /boot/grub/grub.cfg
704697
705698
echo '[SUCCESS][CHROOT] Device Tree directive injected into /boot/grub/grub.cfg'
706699
else
707700
echo '[WARN][CHROOT] Target DTB (glymur-crd.dtb) not found. Skipping injection.'
708701
fi
709702
fi
703+
704+
echo '[CHROOT] Capturing post-install package list...'
705+
dpkg-query -W -f='\${Package} \${Version}\n' > /tmp/\${CODENAME}_post.manifest
706+
707+
echo '[CHROOT] Sorting and computing package delta...'
708+
sort /tmp/\${CODENAME}_base.manifest > /tmp/sorted_base.manifest
709+
sort /tmp/\${CODENAME}_post.manifest > /tmp/sorted_post.manifest
710+
DATE=\$(date +%Y-%m-%d)
711+
comm -13 /tmp/sorted_base.manifest /tmp/sorted_post.manifest > /tmp/packages_\${DATE}.manifest
712+
713+
echo '[CHROOT] Cleaning up intermediate files...'
714+
rm -f /tmp/\${CODENAME}_post.manifest /tmp/sorted_base.manifest /tmp/sorted_post.manifest
715+
716+
echo '[CHROOT] Base package list preserved as /tmp/\${CODENAME}_base.manifest'
717+
echo '[CHROOT] Custom installed packages saved to /tmp/packages_\${DATE}.manifest'
718+
710719
"
711720

712721
# ==============================================================================

0 commit comments

Comments
 (0)