Skip to content

Commit

Permalink
initramfs: Use dracut args from commitmeta if available
Browse files Browse the repository at this point in the history
This is the second half of the previous commit. We check if the
canonical dracut args are available in the commit metadata, and prefer
those over using `--rebuild`. The latter is delegated as a backcompat
fallback.
  • Loading branch information
jlebon committed Feb 26, 2020
1 parent a2e911e commit b248d17
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
30 changes: 29 additions & 1 deletion src/daemon/rpmostree-sysroot-upgrader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@ perform_local_assembly (RpmOstreeSysrootUpgrader *self,
rpmostree_context_get_kernel_changed (self->ctx) ||
rpmostree_origin_get_regenerate_initramfs (self->origin);
g_autoptr(GVariant) kernel_state = NULL;
g_autoptr(GPtrArray) initramfs_args = g_ptr_array_new_with_free_func (g_free);
const char *bootdir = NULL;
const char *kver = NULL;
const char *kernel_path = NULL;
Expand All @@ -1069,9 +1070,30 @@ perform_local_assembly (RpmOstreeSysrootUpgrader *self,
kernel_state = rpmostree_find_kernel (self->tmprootfs_dfd, cancellable, error);
if (!kernel_state)
return FALSE;

/* note we extract the initramfs path here but we only use it as a fallback to use
* with `--rebuild` if we're missing `initramfs-args` in the commit metadata -- in the
* future, we could remove this entirely */
g_variant_get (kernel_state, "(&s&s&sm&s)",
&kver, &bootdir,
&kernel_path, &initramfs_path);

/* also try to extract initramfs args from the base commit */
g_autoptr(GVariant) base_commit = NULL;
if (!ostree_repo_load_variant (self->repo, OSTREE_OBJECT_TYPE_COMMIT,
self->base_revision, &base_commit, error))
return FALSE;

g_autoptr(GVariant) metadata = g_variant_get_child_value (base_commit, 0);
g_autoptr(GVariantDict) metadata_dict = g_variant_dict_new (metadata);

g_autofree char **args = NULL;
if (g_variant_dict_lookup (metadata_dict, "rpmostree.initramfs-args", "^a&s", &args))
{
initramfs_path = NULL;
for (char **it = args; it && *it; it++)
g_ptr_array_add (initramfs_args, g_strdup (*it));
}
}

/* If *just* the kernel changed, all we need to do is run depmod here.
Expand All @@ -1087,9 +1109,13 @@ perform_local_assembly (RpmOstreeSysrootUpgrader *self,

if (kernel_or_initramfs_changed)
{
/* append the extra args */
const char *const* add_dracut_argv = NULL;
if (rpmostree_origin_get_regenerate_initramfs (self->origin))
add_dracut_argv = rpmostree_origin_get_initramfs_args (self->origin);
for (char **it = (char**)add_dracut_argv; it && *it; it++)
g_ptr_array_add (initramfs_args, g_strdup (*it));
g_ptr_array_add (initramfs_args, NULL);

g_auto(RpmOstreeProgress) task = { 0, };
rpmostree_output_task_begin (&task, "Generating initramfs");
Expand All @@ -1100,7 +1126,9 @@ perform_local_assembly (RpmOstreeSysrootUpgrader *self,
/* 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,
if (!rpmostree_run_dracut (self->tmprootfs_dfd,
(const char* const*)initramfs_args->pdata,
kver, initramfs_path,
rpmostree_origin_get_regenerate_initramfs (self->origin),
NULL, &initramfs_tmpf, cancellable, error))
return FALSE;
Expand Down
7 changes: 2 additions & 5 deletions src/libpriv/rpmostree-kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,8 @@ rpmostree_run_dracut (int rootfs_dfd,
error))
return FALSE;

/* Previously we used to error out if argv or rebuild_from_initramfs were both
* not set; now we simply use the defaults (which in Fedora today also means
* implicitly hostonly). That case is for `rpm-ostree override replace
* kernel.*.x86_64.rpm`.
*/
/* Note rebuild_from_initramfs now is only used as a fallback in the client-side regen
* path when we can't fetch the canonical initramfs args to use. */

if (rebuild_from_initramfs)
{
Expand Down
4 changes: 4 additions & 0 deletions tests/vmcheck/test-override-kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ vm_cmd lsinitrd ${newroot}/usr/lib/modules/${kernel_release}/initramfs.img > lsi
assert_file_has_content_literal lsinitrd.txt etc/foobar.conf

echo "ok override kernel with custom initramfs args"

# FCOS omits lvm; check that we still omit lvm here too
assert_file_has_content_literal lsinitrd.txt "--omit 'lvm'"
echo "ok override kernel uses base initramfs args"

0 comments on commit b248d17

Please sign in to comment.