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

Message ID 20251006183214.1593195-6-Quirin.Gylstorff@siemens.com
State RFC
Headers show
Series Add support for dracut | expand

Commit Message

Quirin Gylstorff Oct. 6, 2025, 6:31 p.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@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.gylstorff@siemens.com>
---
 meta/classes/initrd-dracut.bbclass | 49 ++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 meta/classes/initrd-dracut.bbclass

Comments

cedric.hombourger@siemens.com Oct. 9, 2025, 5:22 a.m. UTC | #1
On Mon, 2025-10-06 at 20:31 +0200, Quirin Gylstorff wrote:
> From: Quirin Gylstorff <quirin.gylstorff@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

> 
> 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.gylstorff@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_LIS
> T'))
> +    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
cedric.hombourger@siemens.com Oct. 9, 2025, 6:21 a.m. UTC | #2
On Mon, 2025-10-06 at 20:31 +0200, Quirin Gylstorff wrote:
> From: Quirin Gylstorff <quirin.gylstorff@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.gylstorff@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_LIS
> T'))
> +    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()}"

don't we need to pass (d) ?

> +inherit initramfs
Quirin Gylstorff Oct. 9, 2025, 6:52 a.m. UTC | #3
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.gylstorff@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>>
>> 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.gylstorff@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_LIS
>> T'))
>> +    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
> 
> 
>
Quirin Gylstorff Oct. 9, 2025, 6:53 a.m. UTC | #4
On 10/9/25 08:21, Hombourger, Cedric (FT FDS CES LX) wrote:
> On Mon, 2025-10-06 at 20:31 +0200, Quirin Gylstorff wrote:
>> From: Quirin Gylstorff <quirin.gylstorff@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.gylstorff@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_LIS
>> T'))
>> +    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()}"
> 
> don't we need to pass (d) ?
> 
Yes, there is d missing i need to check why in didn't fail my tests.
Quirin

>> +inherit initramfs
> 
>

Patch

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