[RFC PATCH v3 05/10] Add class to generate custom dracut initramfs

6 views
Skip to first unread message

Quirin Gylstorff

unread,
Oct 6, 2025, 2:32:19 PM (8 days ago) Oct 6
to isar-...@googlegroups.com, jan.k...@siemens.com, felix.mo...@siemens.com, cedric.h...@siemens.com
From: Quirin Gylstorff <quirin.g...@siemens.com>

This class allows to customize a dracut initramfs by using
configuration files add addition modules and drivers.

It is recommended to use the addition of modules and drivers
sparely and prefer dracut configuration files.

This class has the option to add custom modules automatically to
the initramfs if:
- The modules are provided by the ISAR build system
- The module name is part of the package name, valid names are
- dracut-<module-name>
- <module-name>-dracut
- <something>-dracut-<module-name>

Signed-off-by: Quirin Gylstorff <quirin.g...@siemens.com>
---
meta/classes/initrd-dracut.bbclass | 49 ++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 meta/classes/initrd-dracut.bbclass

diff --git a/meta/classes/initrd-dracut.bbclass b/meta/classes/initrd-dracut.bbclass
new file mode 100644
index 00000000..a06296cc
--- /dev/null
+++ b/meta/classes/initrd-dracut.bbclass
@@ -0,0 +1,49 @@
+# This software is a part of ISAR.
+# This class provides the necessary options to
+# customize a dracut based initramfs.
+#
+# This class should not provide every dracut cmdline
+# option possible. Use the dracut configuration files.
+
+INITRAMFS_GENERATOR_PKG = "dracut"
+
+# The preferred way to configure dracut is to
+# provide dracut-config-<your-config> package which
+# contains all necessary config options
+DRACUT_CONFIG_PATH ??= ""
+DRACUT_EXTRA_DRIVERS ??= ""
+DRACUT_EXTRA_MODULES ??= ""
+DRACUT_EXTRACT_MODULES_FROM_PACKAGE_NAMES ??= "False"
+def extend_dracut_cmdline(d):
+ config_path = d.getVar('DRACUT_CONFIG_PATH') or ''
+ extra_drivers = d.getVar('DRACUT_CONFIG_PATH') or ''
+ extra_modules = d.getVar('DRACUT_CONFIG_PATH') or ''
+ enable_module_extraction = bb.utils.to_boolean(d.getVar('DRACUT_EXTRACT_MODULES_FROM_PACKAGE_LIST'))
+ pkg_list = d.getVar('INITRAMFS_INSTALL') or ''
+
+ cmdline = []
+ modules_from_pkg_names = []
+ if enable_module_extraction:
+ for pkg in pkg_list.split():
+ # Skip dracut-config-* packages
+ if pkg.startswith('dracut-config-'):
+ continue
+ elif pkg.startswith('dracut-'):
+ modules_from_pkg_names.append(pkg[7:])
+ elif pkg.endswith('-dracut'):
+ modules_from_pkg_names.append(pkg[:-7])
+ elif '-dracut-' in pkg:
+ _, module_name = pkg.split('-dracut-', 1)
+ modules_from_pkg_names.append(module_name)
+ extra_modules = extra_modules + ' ' +' '.join(modules_from_pkg_names)
+
+ if config_path:
+ cmdline.append(f"--conf {config_path}")
+ if extra_drivers:
+ cmdline.append(f"--add-drivers {extra_drivers}")
+ if extra_modules:
+ cmdline.append(f"--add {extra_modules}")
+ return ' '.join(cmdline)
+
+ROOTFS_INITRAMFS_GENERATOR_CMDLINE += "${@ extend_dracut_cmdline()}"
+inherit initramfs
--
2.51.0

cedric.h...@siemens.com

unread,
Oct 9, 2025, 1:22:08 AM (6 days ago) Oct 9
to quirin.g...@siemens.com, isar-...@googlegroups.com, Kiszka, Jan, MOESSBAUER, Felix
On Mon, 2025-10-06 at 20:31 +0200, Quirin Gylstorff wrote:
> From: Quirin Gylstorff <quirin.g...@siemens.com>
>
> This class allows to customize a dracut initramfs by using
> configuration files add addition modules and drivers.

why restricting support for dracut to initramfs image recipes and not
supporting a switch to dracut for "normal" rootfs? I believe your patch
series provides all the required infrastructure to support both use-
cases
Cedric Hombourger
Siemens AG
www.siemens.com

cedric.h...@siemens.com

unread,
Oct 9, 2025, 2:21:57 AM (6 days ago) Oct 9
to quirin.g...@siemens.com, isar-...@googlegroups.com, Kiszka, Jan, MOESSBAUER, Felix
On Mon, 2025-10-06 at 20:31 +0200, Quirin Gylstorff wrote:
don't we need to pass (d) ?

> +inherit initramfs


Quirin Gylstorff

unread,
Oct 9, 2025, 2:52:35 AM (6 days ago) Oct 9
to Hombourger, Cedric (FT FDS CES LX), isar-...@googlegroups.com, Kiszka, Jan (FT RPD CED), Moessbauer, Felix (FT RPD CED OES-DE)


On 10/9/25 07:22, Hombourger, Cedric (FT FDS CES LX) wrote:
> On Mon, 2025-10-06 at 20:31 +0200, Quirin Gylstorff wrote:
>> From: Quirin Gylstorff <quirin.g...@siemens.com>
>>
>> This class allows to customize a dracut initramfs by using
>> configuration files add addition modules and drivers.
>
> why restricting support for dracut to initramfs image recipes and not
> supporting a switch to dracut for "normal" rootfs? I believe your patch
> series provides all the required infrastructure to support both use-
> cases
>

I didn't test it - but it should be possible to install dracut and it
should switch normal rootfs to dracut.

This needs to be done by the user.

Quirin>>

Quirin Gylstorff

unread,
Oct 9, 2025, 2:53:57 AM (6 days ago) Oct 9
to Hombourger, Cedric (FT FDS CES LX), isar-...@googlegroups.com, Kiszka, Jan (FT RPD CED), Moessbauer, Felix (FT RPD CED OES-DE)
Yes, there is d missing i need to check why in didn't fail my tests.
Quirin

>> +inherit initramfs
>
>

Reply all
Reply to author
Forward
0 new messages