Blame SOURCES/0270-squish-BLS-only-write-etc-kernel-cmdline-if-writable.patch

fd0330
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
fd0330
From: Jonathan Lebon <jonathan@jlebon.com>
fd0330
Date: Wed, 17 Aug 2022 10:26:03 -0400
fd0330
Subject: [PATCH] squish: BLS: only write /etc/kernel/cmdline if writable
fd0330
fd0330
On OSTree systems, `grub2-mkconfig` is run with `/etc` mounted read-only
fd0330
because as part of the promise of transactional updates, we want to make
fd0330
sure that we're not modifying the current deployment's state (`/etc` or
fd0330
`/var`).
fd0330
fd0330
This conflicts with 0837dcdf1 ("BLS: create /etc/kernel/cmdline during
fd0330
mkconfig") which wants to write to `/etc/kernel/cmdline`. I'm not
fd0330
exactly sure on the background there, but based on the comment I think
fd0330
the intent is to fulfill grubby's expectation that the file exists.
fd0330
fd0330
However, in systems like Silverblue, kernel arguments are managed by the
fd0330
rpm-ostree stack and grubby is not shipped at all.
fd0330
fd0330
Adjust the script slightly so that we only write `/etc/kernel/cmdline`
fd0330
if the parent directory is writable.
fd0330
fd0330
In the future, we're hoping to simplify things further on rpm-ostree
fd0330
systems by not running `grub2-mkconfig` at all since libostree already
fd0330
directly writes BLS entries. Doing that would also have avoided this,
fd0330
but ratcheting it into existing systems needs more careful thought.
fd0330
fd0330
Signed-off-by: Jonathan Lebon <jonathan@jlebon.com>
fd0330
fd0330
Fixes: https://github.com/fedora-silverblue/issue-tracker/issues/322
fd0330
---
fd0330
 util/grub.d/10_linux.in | 13 +++++++------
fd0330
 1 file changed, 7 insertions(+), 6 deletions(-)
fd0330
fd0330
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
fd0330
index 5d1fa072f2..4795a63b4c 100644
fd0330
--- a/util/grub.d/10_linux.in
fd0330
+++ b/util/grub.d/10_linux.in
fd0330
@@ -161,12 +161,13 @@ update_bls_cmdline()
fd0330
     local cmdline="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
fd0330
     local -a files=($(get_sorted_bls))
fd0330
 
fd0330
-    if [[ ! -f /etc/kernel/cmdline ]] ||
fd0330
-	   [[ /etc/kernel/cmdline -ot /etc/default/grub ]]; then
fd0330
-	# anaconda has the correct information to create this during install;
fd0330
-	# afterward, grubby will take care of syncing on updates.  If the user
fd0330
-	# has modified /etc/default/grub, try to cope.
fd0330
-	echo "$cmdline" > /etc/kernel/cmdline
fd0330
+    if [ -w /etc/kernel ] &&
fd0330
+           [[ ! -f /etc/kernel/cmdline ||
fd0330
+                  /etc/kernel/cmdline -ot /etc/default/grub ]]; then
fd0330
+        # anaconda has the correct information to create this during install;
fd0330
+        # afterward, grubby will take care of syncing on updates.  If the user
fd0330
+        # has modified /etc/default/grub, try to cope.
fd0330
+        echo "$cmdline" > /etc/kernel/cmdline
fd0330
     fi
fd0330
 
fd0330
     for bls in "${files[@]}"; do