public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Subject: [gentoo-dev] [PATCH 1/7] linux-mod-r1.eclass: add USE=initramfs
Date: Tue, 14 May 2024 13:59:06 +0200	[thread overview]
Message-ID: <20240514115924.29167-1-andrewammerlaan@gentoo.org> (raw)

Adds a new variable that adds the "initramfs" flag when set. This new
flag controls whether or not the modules that were built should be
included in the initramfs. If the modules should be included, then we
also rebuild the initramfs/uki in post_install using installkernel.

Bug: https://bugs.gentoo.org/923025
Bug: https://bugs.gentoo.org/928271
Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
 eclass/linux-mod-r1.eclass | 54 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/eclass/linux-mod-r1.eclass b/eclass/linux-mod-r1.eclass
index 4b267aae4db1..d9651f962604 100644
--- a/eclass/linux-mod-r1.eclass
+++ b/eclass/linux-mod-r1.eclass
@@ -131,6 +131,15 @@ IDEPEND="
 	sys-apps/kmod[tools]
 "
 
+if [[ ${MODULES_INITRAMFS_IUSE} ]]; then
+	IUSE+=" ${MODULES_INITRAMFS_IUSE}"
+	IDEPEND+="
+		${MODULES_INITRAMFS_IUSE#+}? (
+			sys-kernel/installkernel
+		)
+	"
+fi
+
 if [[ -n ${MODULES_OPTIONAL_IUSE} ]]; then
 	: "${MODULES_OPTIONAL_IUSE#+}? ( | )"
 	RDEPEND=${_/|/${RDEPEND}} DEPEND=${_/|/${DEPEND}} \
@@ -179,6 +188,22 @@ fi
 #
 # May want to look at KERNEL_CHOST before considering this.
 
+# @ECLASS_VARIABLE: MODULES_INITRAMFS_IUSE
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# If set, adds the specified USE flag. When this flag is enabled the
+# installed kernel modules are registered for inclusion in the dracut
+# initramfs. Additionally, if distribution kernels are used
+# (USE="dist-kernel") then these kernels are re-installed.
+#
+# The typical recommended value is "initramfs" or "+initramfs" (global
+# IUSE).
+#
+# If MODULES_INITRAMFS_IUSE is not set, or the specified flag is not
+# enabled, then the installed kernel modules are omitted from the
+# dracut initramfs.
+
 # @ECLASS_VARIABLE: MODULES_SIGN_HASH
 # @USER_VARIABLE
 # @DEFAULT_UNSET
@@ -471,6 +496,19 @@ linux-mod-r1_pkg_postinst() {
 	dist-kernel_compressed_module_cleanup "${EROOT}/lib/modules/${KV_FULL}"
 	_modules_update_depmod
 
+	if [[ -z ${ROOT} && ${MODULES_INITRAMFS_IUSE} ]] &&
+		use dist-kernel && use ${MODULES_INITRAMFS_IUSE#+}
+	then
+			dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+	fi
+
+	if has_version virtual/dist-kernel && ! use dist-kernel; then
+		ewarn "virtual/dist-kernel is installed, but USE=\"dist-kernel\""
+		ewarn "is not enabled for ${CATEGORY}/${PN}."
+		ewarn "It's recommended to globally enable the dist-kernel USE flag"
+		ewarn "to automatically trigger initramfs rebuilds on kernel updates"
+	fi
+
 	# post_process ensures modules were installed and that the eclass' USE
 	# are likely not no-ops (unfortunately postinst itself may be missed)
 	[[ -v _MODULES_GLOBAL[ran:post_process] ]] ||
@@ -550,6 +588,7 @@ modules_post_process() {
 	# which can lead to unnecessarily increased size or stale modules)
 #	_modules_process_depmod.d "${mods[@]#"${path}/"}"
 
+	_modules_process_dracut.conf.d "${mods[@]##*/}"
 	_modules_process_strip "${mods[@]}"
 	_modules_process_sign "${mods[@]}"
 	_modules_sanity_modversion "${mods[@]}" # after strip/sign in case broke it
@@ -904,6 +943,21 @@ _modules_process_depmod.d() {
 	)
 }
 
+# @FUNCTION: _modules_process_dracut.conf.d
+# @USAGE: <module>...
+# @INTERNAL
+# @DESCRIPTION:
+# Create dracut.conf.d snippet defining if module should be included in the
+# initramfs.
+_modules_process_dracut.conf.d() {
+	(
+		insinto /usr/lib/dracut/dracut.conf.d
+		[[ ${MODULES_INITRAMFS_IUSE} ]] && use ${MODULES_INITRAMFS_IUSE#+} &&
+			: add || : omit
+		newins - 10-${PN}.conf <<<"${_}_drivers+=\" ${*%.ko} \""
+	)
+}
+
 # @FUNCTION: _modules_process_sign
 # @USAGE: <module>...
 # @INTERNAL
-- 
2.45.0



             reply	other threads:[~2024-05-14 11:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14 11:59 Andrew Ammerlaan [this message]
2024-05-14 11:59 ` [gentoo-dev] [PATCH 2/7] profiles/use.desc: add new global flag "initramfs" Andrew Ammerlaan
2024-05-14 11:59 ` [gentoo-dev] [PATCH 3/7] sys-fs/zfs-kmod: add USE=initramfs, and enable by default Andrew Ammerlaan
2024-05-14 11:59 ` [gentoo-dev] [PATCH 4/7] sys-firmware/intel-microcode: add USE=dist-kernel Andrew Ammerlaan
2024-05-14 11:59 ` [gentoo-dev] [PATCH 5/7] sys-kernel/linux-firmware: " Andrew Ammerlaan
2024-05-14 11:59 ` [gentoo-dev] [PATCH 6/7] linux-info.eclass: respect eselect kernel setting in binpkgs Andrew Ammerlaan
2024-05-15 16:02   ` Mike Gilbert
2024-05-14 11:59 ` [gentoo-dev] [PATCH 7/7] linux-mod-r1.eclass: do not reset kernel env vars " Andrew Ammerlaan
2024-05-14 12:02   ` [gentoo-dev] [PATCH 0/7] Changes to dracut kernel module/microcode handling Andrew Nowa Ammerlaan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240514115924.29167-1-andrewammerlaan@gentoo.org \
    --to=andrewammerlaan@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox