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