rpm-ostree/SOURCES/0001-initramfs-Fix-using-local-etc-when-also-replacing-ke.patch
2021-09-10 04:00:07 +00:00

112 lines
5.2 KiB
Diff

From 1675058768263b804148c7a737b00a480d6b32f8 Mon Sep 17 00:00:00 2001
From: Jonathan Lebon <jonathan@jlebon.com>
Date: Wed, 26 Feb 2020 11:14:51 -0500
Subject: [PATCH] initramfs: Fix using local /etc when also replacing kernel
Instead of basing our decision to use the local `/etc` on whether we're
using `dracut --rebuild`, base it directly on a boolean parameter.
This is relevant in the client-side when initramfs regeneration is
requested as well as a kernel override. In such cases, we do want to use
the local `/etc`, but we'd skip that path because we didn't also use
`dracut --rebuild`.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1806588
---
src/daemon/rpmostree-sysroot-upgrader.c | 9 ++++++---
src/libpriv/rpmostree-kernel.c | 6 ++----
src/libpriv/rpmostree-kernel.h | 1 +
src/libpriv/rpmostree-postprocess.c | 2 +-
tests/vmcheck/test-override-kernel.sh | 9 +++++++++
5 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/src/daemon/rpmostree-sysroot-upgrader.c b/src/daemon/rpmostree-sysroot-upgrader.c
index e3f5acef..f84e20c6 100644
--- a/src/daemon/rpmostree-sysroot-upgrader.c
+++ b/src/daemon/rpmostree-sysroot-upgrader.c
@@ -1097,9 +1097,12 @@ perform_local_assembly (RpmOstreeSysrootUpgrader *self,
g_assert (kernel_state && kernel_path);
g_auto(GLnxTmpfile) initramfs_tmpf = { 0, };
- if (!rpmostree_run_dracut (self->tmprootfs_dfd, add_dracut_argv, kver,
- initramfs_path, NULL, &initramfs_tmpf,
- cancellable, error))
+ /* NB: We only use the real root's /etc if initramfs regeneration is explicitly
+ * requested. IOW, just replacing the kernel still gets use stock settings, like the
+ * server side. */
+ if (!rpmostree_run_dracut (self->tmprootfs_dfd, add_dracut_argv, kver, initramfs_path,
+ rpmostree_origin_get_regenerate_initramfs (self->origin),
+ NULL, &initramfs_tmpf, cancellable, error))
return FALSE;
if (!rpmostree_finalize_kernel (self->tmprootfs_dfd, bootdir, kver, kernel_path,
diff --git a/src/libpriv/rpmostree-kernel.c b/src/libpriv/rpmostree-kernel.c
index d1f0c90c..a1e4546c 100644
--- a/src/libpriv/rpmostree-kernel.c
+++ b/src/libpriv/rpmostree-kernel.c
@@ -475,6 +475,7 @@ rpmostree_run_dracut (int rootfs_dfd,
const char *const* argv,
const char *kver,
const char *rebuild_from_initramfs,
+ gboolean use_root_etc,
GLnxTmpDir *dracut_host_tmpdir,
GLnxTmpfile *out_initramfs_tmpf,
GCancellable *cancellable,
@@ -562,10 +563,7 @@ rpmostree_run_dracut (int rootfs_dfd,
&tmpf, error))
goto out;
- /* If we're rebuilding, we use the *current* /etc so we pick up any modified
- * config files. Otherwise, we use the usr/etc defaults.
- */
- if (rebuild_from_initramfs)
+ if (use_root_etc)
{
bwrap = rpmostree_bwrap_new_base (rootfs_dfd, error);
if (!bwrap)
diff --git a/src/libpriv/rpmostree-kernel.h b/src/libpriv/rpmostree-kernel.h
index fb9d8a1b..32a36511 100644
--- a/src/libpriv/rpmostree-kernel.h
+++ b/src/libpriv/rpmostree-kernel.h
@@ -54,6 +54,7 @@ rpmostree_run_dracut (int rootfs_dfd,
const char *const* argv,
const char *kver,
const char *rebuild_from_initramfs,
+ gboolean use_root_etc,
GLnxTmpDir *dracut_host_tmpdir,
GLnxTmpfile *out_initramfs_tmpf,
GCancellable *cancellable,
diff --git a/src/libpriv/rpmostree-postprocess.c b/src/libpriv/rpmostree-postprocess.c
index ce7424a1..186817be 100644
--- a/src/libpriv/rpmostree-postprocess.c
+++ b/src/libpriv/rpmostree-postprocess.c
@@ -447,7 +447,7 @@ process_kernel_and_initramfs (int rootfs_dfd,
return FALSE;
if (!rpmostree_run_dracut (rootfs_dfd,
(const char *const*)dracut_argv->pdata, kver,
- NULL, &dracut_host_tmpd,
+ NULL, FALSE, &dracut_host_tmpd,
&initramfs_tmpf, cancellable, error))
return FALSE;
/* No reason to have the initramfs not be world-readable since
diff --git a/tests/vmcheck/test-override-kernel.sh b/tests/vmcheck/test-override-kernel.sh
index 0e8c91b7..4bde242a 100755
--- a/tests/vmcheck/test-override-kernel.sh
+++ b/tests/vmcheck/test-override-kernel.sh
@@ -60,3 +60,12 @@ assert_streq "$(wc -l < modules-dirs.txt)" "2"
assert_file_has_content_literal modules-dirs.txt $kernel_release
echo "ok override kernel"
+
+# And check that we can regenerate the initramfs and include files from our /etc
+vm_cmd touch /etc/foobar.conf
+vm_rpmostree initramfs --enable --arg=-I --arg=/etc/foobar.conf
+newroot=$(vm_get_deployment_root 0)
+vm_cmd lsinitrd ${newroot}/usr/lib/modules/${kernel_release}/initramfs.img > lsinitrd.txt
+assert_file_has_content_literal lsinitrd.txt etc/foobar.conf
+
+echo "ok override kernel with custom initramfs args"
--
2.24.1