From 23e36119b9c70dedd7533f792f40779cd6db0d58 Mon Sep 17 00:00:00 2001 From: fiftydinar <65243233+fiftydinar@users.noreply.github.com> Date: Sun, 15 Dec 2024 11:02:37 +0100 Subject: [PATCH] feat: `initramfs` module (#376) * feat: `initramfs` module * chore: Add `initramfs` to `modules.json` * docs: Mention `dracut.conf.d` files as modifications which need initramfs regeneration * docs: Style fix * docs: Style fix * docs: One more style fix * docs: Add note about difference between `rpm-ostree initramfs` & this module * docs: Further explanation of initramfs * docs: Style fixes * docs: Style fix * docs: Grammar fixes * chore: Add check for Fedora 41+ * docs: Add note about F41+ support * docs: Add 3 dots for note * chore: Grammar improvement in log * chore: Some more explanations in log for old Fedora version * chore: Add error message for cliwrapped images * chore: Use cliwrapped dracut if available * docs: Apply caution card suggestion Co-authored-by: xyny <60004820+xynydev@users.noreply.github.com> * docs: Apply suggestion about modifications list Co-authored-by: xyny <60004820+xynydev@users.noreply.github.com> * docs: Apply grammar suggestion for when this module should be used Co-authored-by: xyny <60004820+xynydev@users.noreply.github.com> * chore: Make log message about initramfs regeneration state clearer Co-authored-by: xyny <60004820+xynydev@users.noreply.github.com> * docs: Apply suggestion about expanded module description Co-authored-by: xyny <60004820+xynydev@users.noreply.github.com> * docs: RAM instead of ram * chore: Fix log typo * docs: Update description in typeschema * docs: Update description in module.yml * chore: Notify of more than 1 qualified kernel before initramfs image variable * chore: finalize shortdesc wording --------- Co-authored-by: xyny <60004820+xynydev@users.noreply.github.com> --- modules.json | 1 + modules/initramfs/README.md | 23 +++++++++++++++++ modules/initramfs/initramfs.sh | 44 +++++++++++++++++++++++++++++++++ modules/initramfs/initramfs.tsp | 10 ++++++++ modules/initramfs/module.yml | 4 +++ 5 files changed, 82 insertions(+) create mode 100644 modules/initramfs/README.md create mode 100644 modules/initramfs/initramfs.sh create mode 100644 modules/initramfs/initramfs.tsp create mode 100644 modules/initramfs/module.yml diff --git a/modules.json b/modules.json index ab77836..66afaa8 100644 --- a/modules.json +++ b/modules.json @@ -10,6 +10,7 @@ "https://raw.githubusercontent.com/blue-build/modules/main/modules/gschema-overrides/module.yml", "https://raw.githubusercontent.com/blue-build/modules/main/modules/justfiles/module.yml", "https://raw.githubusercontent.com/blue-build/modules/main/modules/rpm-ostree/module.yml", + "https://raw.githubusercontent.com/blue-build/modules/main/modules/initramfs/module.yml", "https://raw.githubusercontent.com/blue-build/modules/main/modules/script/module.yml", "https://raw.githubusercontent.com/blue-build/modules/main/modules/signing/module.yml", "https://raw.githubusercontent.com/blue-build/modules/main/modules/systemd/module.yml", diff --git a/modules/initramfs/README.md b/modules/initramfs/README.md new file mode 100644 index 0000000..ae8de62 --- /dev/null +++ b/modules/initramfs/README.md @@ -0,0 +1,23 @@ +# `initramfs` + +:::caution +This module is only supported for Fedora 41+ images. +::: + +The `initramfs` module is used to regenerate initramfs, which is the temporary file system loaded into RAM, as part of the early Linux startup process, used by many things happening during boot. + +If you are trying to modify something related to the kernel or boot sequence (such as plymouth), but you don't see any changes applied to the system, you'll likely need to use this module. + +You need to regenerate initramfs at least when doing any of the following: +- modifying `modprobe.d` config files +- modifying `modules-load.d` config files +- modifying `dracut.conf.d` config files +- customizing `plymouth` theming +- other unknown modifications + +You only need to run the regeneration once per build, not separately for each modification requiring it. It is recommended to set this module as one of the last in your recipe, to ensure that initramfs regeneration will cover all the modifications done before it. + +:::note +Client-side initramfs regeneration like `rpm-ostree initramfs` & `rpm-ostree initramfs-etc` are for local-users only & not to be confused with this module's build-time initramfs regeneration. +This module regenerates the system initramfs during the build process, while `rpm-ostree initramfs` & `rpm-ostree initramfs-etc` regenerate the local initramfs on top of the system one every update on the local-user's system. +::: diff --git a/modules/initramfs/initramfs.sh b/modules/initramfs/initramfs.sh new file mode 100644 index 0000000..76ed8e5 --- /dev/null +++ b/modules/initramfs/initramfs.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if ! command -v rpm-ostree &> /dev/null || ! command -v bootc &> /dev/null; then + echo "This module is only compatible with Fedora Atomic images" + exit 1 +fi + +if [[ "${OS_VERSION}" -le 40 ]]; then + echo "This module is only compatible with Fedora 41+ images." + exit 1 +fi + +# If images already installed cliwrap, use it. Only used in transition period, so it should be removed when base images like Ublue remove cliwrap +if [[ -f "/usr/libexec/rpm-ostree/wrapped/dracut" ]]; then + DRACUT="/usr/libexec/rpm-ostree/wrapped/dracut" +else + DRACUT="/usr/bin/dracut" +fi + +# NOTE! +# This won't work when Fedora starts to utilize UKIs (Unified Kernel Images). +# UKIs will contain kernel + initramfs + bootloader. +# Refactor the module to support UKIs once they are starting to be used, if possible. +# That won't be soon, so this module should work for good period of time + +KERNEL_MODULES_PATH="/usr/lib/modules" +readarray -t QUALIFIED_KERNEL < <(find "${KERNEL_MODULES_PATH}" -mindepth 1 -maxdepth 1 -type d -printf "%f\n") + +if [[ "${#QUALIFIED_KERNEL[@]}" -gt 1 ]]; then + echo "ERROR: There are several versions of kernel's initramfs." + echo " Cannot determine which one to regenerate." + echo " There is a possibility that you have multiple kernels installed in the image." + echo " Please only include 1 kernel in the image to solve this issue." + exit 1 +fi + +INITRAMFS_IMAGE="${KERNEL_MODULES_PATH}/${QUALIFIED_KERNEL[*]}/initramfs.img" + +echo "Starting initramfs regeneration for kernel version: ${QUALIFIED_KERNEL[*]}" + +"${DRACUT}" --no-hostonly --kver "${QUALIFIED_KERNEL[*]}" --reproducible -v --add ostree -f "${INITRAMFS_IMAGE}" +chmod 0600 "${INITRAMFS_IMAGE}" diff --git a/modules/initramfs/initramfs.tsp b/modules/initramfs/initramfs.tsp new file mode 100644 index 0000000..a159d0d --- /dev/null +++ b/modules/initramfs/initramfs.tsp @@ -0,0 +1,10 @@ +import "@typespec/json-schema"; +using TypeSpec.JsonSchema; + +@jsonSchema("/modules/initramfs.json") +model InitramfsModule { + /** The initramfs module is used to regenerate initramfs, needed to apply some modifications early in the Linux startup process. + * https://blue-build.org/reference/modules/initramfs/ + */ + type: "initramfs"; +} diff --git a/modules/initramfs/module.yml b/modules/initramfs/module.yml new file mode 100644 index 0000000..f432b7b --- /dev/null +++ b/modules/initramfs/module.yml @@ -0,0 +1,4 @@ +name: initramfs +shortdesc: The `initramfs` module is used to regenerate initramfs, needed to apply some modifications early in the Linux startup process +example: | + type: initramfs