From 9d617ab0104d6be050a92d1eeb5a82d8877da707 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 18 Oct 2026 01:24:03 -0700 Subject: [PATCH] fix(scripts): report the grub.cfg default entry, and stop claiming what was checked The pending-entry grep anchored on "menuentry 'Ubuntu'" with -A4 and matched no linux line, so the script printed nothing where it should have shown the next boot's command line; the PENDING line then said "is in grub.cfg" when the loop only ever compared the tracked file against /proc/cmdline. Now the default entry's linux line is parsed with awk (first linux line of the first Ubuntu menuentry, which is what GRUB_DEFAULT=0 selects), its iommu token is printed, and a mismatch against the tracked file warns by name. --- scripts/set-dankclaw-bootline.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/set-dankclaw-bootline.sh b/scripts/set-dankclaw-bootline.sh index 3b7a2f4..758d331 100755 --- a/scripts/set-dankclaw-bootline.sh +++ b/scripts/set-dankclaw-bootline.sh @@ -46,8 +46,14 @@ else sudo update-grub fi -echo "== pending entry" -sudo grep -m1 "menuentry 'Ubuntu'" -A4 /boot/grub/grub.cfg | grep -m1 linux | tr ' ' '\n' | grep -E '^(iommu|amd_iommu)' || true +# The DEFAULT entry is the first 'Ubuntu' menuentry's linux line: that is the +# command line the next boot actually gets. (GRUB_DEFAULT=0 here, so first it is.) +echo "== grub.cfg default entry" +CFG="$(sudo awk '/menuentry .Ubuntu/ && !seen {seen=1} + seen && /^[[:space:]]*linux/ {print; exit}' /boot/grub/grub.cfg)" +[ -n "$CFG" ] || { echo "could not read the default linux line from grub.cfg" >&2; exit 1; } +printf '%s\n' "$CFG" | tr ' \t' '\n' | grep -E '^(iommu|amd_iommu)=' || echo "(no iommu token in the default entry)" + echo "== running kernel" tr '\0' ' ' < /proc/cmdline; echo @@ -56,9 +62,14 @@ NOW="$(cat /proc/cmdline)" for tok in $WANT; do case " $NOW " in *" $tok "*) ;; - *) echo "PENDING: '$tok' is in grub.cfg but not in the running kernel — needs a reboot" ;; + *) echo "PENDING: '$tok' is not in the running kernel" ;; esac done +WANT_IOMMU="$(printf '%s\n' $WANT | grep -E '^(iommu|amd_iommu)=' | head -1)" +CFG_IOMMU="$(printf '%s\n' "$CFG" | tr ' \t' '\n' | grep -E '^(iommu|amd_iommu)=' | head -1)" +if [ "$WANT_IOMMU" != "$CFG_IOMMU" ]; then + echo "WARN: grub.cfg default entry says '${CFG_IOMMU:-none}', tracked file says '${WANT_IOMMU:-none}'" >&2 +fi if [ "$REBOOT" = 1 ]; then echo "== rebooting now"