-
Notifications
You must be signed in to change notification settings - Fork 8
build-rootfs: Transition from custom GRUB config to upstream standard (update-grub) #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0147de2
build-rootfs: Replace manual GRUB config with standard update-grub wo…
bjordiscollaku f0e40b9
Fix typo in package name from 'grub2-commong' to 'grub2-common'
bjordiscollaku 34dc75f
build-rootfs: Move GRUB config generation to host to fix nesting issues
bjordiscollaku b1d0c09
build-rootfs: Fix missing /boot/grub directory causing update-grub fa…
bjordiscollaku 6cc7faf
build-rootfs: Sanitize generated GRUB config for generic portability
bjordiscollaku db20d11
build-rootfs: Remove unused kernel version detection logic
bjordiscollaku 14ae106
build-rootfs: Remove redundant update-grub invocation
bjordiscollaku 677c9b3
build-rootfs: Enable dual-output GRUB menu (Serial + Console)
bjordiscollaku 45b7d83
Merge branch 'main' into dev/bjordiscollaku
bjordiscollaku 4a44f23
build-rootfs: Implement post-processing Device Tree injection for Debian
bjordiscollaku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 <<GRUBCFG | ||
| set timeout=5 | ||
| # 2. Clean Kernel Command Line | ||
| # Remove the host-detected root device (e.g., root=/dev/nvme0n1p1) to prevent | ||
| # conflicts with our 'root=LABEL=system' argument. | ||
| sed -i 's/root=\/dev\/[^ ]* //g' /boot/grub/grub.cfg | ||
|
|
||
| menuentry \"\${DISTRO} \${CODENAME}\" { | ||
| search --no-floppy --label system --set=root | ||
| linux /boot/vmlinuz-\$kernel_ver earlycon console=ttyMSM0,115200n8 root=LABEL=system cma=128M rw clk_ignore_unused pd_ignore_unused efi=noruntime rootwait ignore_loglevel | ||
| initrd /boot/initrd.img-\$kernel_ver | ||
| } | ||
| GRUBCFG | ||
| # 3. Legacy Compatibility | ||
| # Create a relative symlink for bootloaders expecting the old path. | ||
| ln -sf grub/grub.cfg /boot/grub.cfg | ||
|
|
||
| # ============================================================================== | ||
| # Device Tree Configuration for Debian platforms | ||
| # ============================================================================== | ||
|
|
||
| if [ \"\${distro_lc}\" = \"debian\" ]; then | ||
| echo '[INFO][CHROOT] Debian target detected. Configuring platform Device Tree...' | ||
|
|
||
| # Locate the platform Device Tree Blob (DTB) in standard library or firmware paths | ||
| DTB_PATH=\$(find /usr/lib /lib/firmware -name \"glymur-crd.dtb\" -print -quit) | ||
|
|
||
| if [ -n \"\$DTB_PATH\" ]; then | ||
| echo \"[INFO][CHROOT] Platform DTB resolved: \$DTB_PATH\" | ||
|
|
||
| # Ensure DTB is accessible in the bootloader's filesystem scope | ||
| ln -sf \"\$DTB_PATH\" /boot/dtb | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Not sure why first comment is not showing up, sorry for the dup) /boot/dtb can only exist once; GRUB config generation will generate entries for each kernel, you want to tap into that to generate entries for each kernel with a devicetree line from the right kernel. |
||
|
|
||
| # Inject the devicetree directive into the generated GRUB configuration. | ||
| # This appends the command immediately following the 'initrd' load. | ||
| sed -i \"/^[[:space:]]*initrd/a \ devicetree /boot/dtb\" /boot/grub/grub.cfg | ||
|
|
||
| echo '[SUCCESS][CHROOT] Device Tree directive injected into /boot/grub/grub.cfg' | ||
| else | ||
| echo '[WARN][CHROOT] Target DTB (glymur-crd.dtb) not found. Skipping injection.' | ||
| fi | ||
| fi | ||
| " | ||
|
|
||
| # ============================================================================== | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why hardcode glymur-crd.dtb? How will this image work on other systems?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional devicetree injection is to temporarily support glymur enablement in CI/nightly, up until multi-dtb (combined or FIT) dtb.bin is supported on glymur platform, just like in Hamoa IoT, in which case conditional injection of this hardcoded devicetree path in grub menuentry completely vanishes, alongside the "ln -sf $DTB_PATH /boot/dtb".
Result is then devicetree agnostic generalized grub config generated straight from update-grub (which runs as part of postinst script of the kernel deb package).