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