From 26f3f823ac17940a1b0153619f6140f45d856e33 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 27 Apr 2026 13:00:26 -0500 Subject: refactor: verify GRUB_CMDLINE_LINUX seds via prepend_grub_cmdline_linux helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Audited the ~10 silent sed -i sites in the installer against the verification-after pattern that landed for sshd_config last session. Triaged each by failure mode. The two GRUB_CMDLINE_LINUX seds in lib/btrfs.sh have a real silent-failure risk. If /etc/default/grub is missing or malformed and the sed pattern doesn't match, nothing happens. The kernel boots without cryptdevice=. The system can't unlock LUKS at boot. Added prepend_grub_cmdline_linux to lib/common.sh. Same shape as enable_sshd_root_login (sed, then grep, then error if the line wasn't modified). Replaced the two inline seds with helper calls. The HOOKS= seds in installer/archangel and lib/btrfs.sh (six total) don't need verification. A missing HOOKS= line makes mkinitcpio -P fail loudly downstream, so silent-replace failure can't reach a booted system. Added a one-line audit-rationale comment at each of the three locations so the next reader doesn't re-litigate the decision. The FILES= sed at lib/btrfs.sh:213 already self-heals via a sed-then-grep-then-append pattern, so no behavior change there. Filed a separate follow-up to lift that pattern into a named helper for clarity. Bats: 142 → 146. Four new tests in test_common.bats cover normal (empty cmdline, existing cmdline preserved, other lines preserved) and error (missing GRUB_CMDLINE_LINUX line). Lint clean. --- installer/lib/common.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'installer/lib/common.sh') diff --git a/installer/lib/common.sh b/installer/lib/common.sh index 3040799..dfeb245 100644 --- a/installer/lib/common.sh +++ b/installer/lib/common.sh @@ -302,3 +302,21 @@ enable_sshd_root_login() { grep -q '^PermitRootLogin yes$' "$config_file" \ || error "PermitRootLogin not set in $config_file (no matching line to replace)" } + +############################# +# GRUB Configuration +############################# + +# Prepend a string just inside the GRUB_CMDLINE_LINUX="..." quotes in +# /etc/default/grub. Errors if the line isn't present in the file. +# Silently doing nothing here would leave the kernel without the +# parameter — for cryptdevice= that means the system can't unlock the +# root partition at boot, so we want a loud failure during install +# rather than an unbootable system after first reboot. +prepend_grub_cmdline_linux() { + local addition="$1" + local config_file="$2" + sed -i "s|^GRUB_CMDLINE_LINUX=\"|GRUB_CMDLINE_LINUX=\"${addition}|" "$config_file" + grep -qF "GRUB_CMDLINE_LINUX=\"${addition}" "$config_file" \ + || error "GRUB_CMDLINE_LINUX not modified in $config_file (line missing or pattern unmatched)" +} -- cgit v1.2.3