Skip to content

Conversation

@aale24
Copy link
Contributor

@aale24 aale24 commented Jun 8, 2025

Add support for specifying kernel drivers to be included or omitted in the dracut initrd configuration. This extends the existing dracut configuration capabilities by allowing users to:

  • Configure specific drivers through the element:

  • Control driver inclusion/omission in both system and installation initrds through:

    • add_drivers/omit_drivers in dracut.conf
    • --drivers/--omit-drivers command line options

Key changes:

  • Add driver attribute to dracut schema definition
  • Implement driver handling in BootImageDracut
  • Add driver support in DiskBuilder and InstallImageBuilder
  • Update XMLState to process driver configurations
  • Add comprehensive test coverage for driver handling

Example usage:


Partially Fixes #2808

Add support for specifying kernel drivers to be included or omitted
in the dracut initrd configuration. This extends the existing dracut
configuration capabilities by allowing users to:

- Configure specific drivers through the <dracut> element:
   <dracut driver="driver_name"/>

- Control driver inclusion/omission in both system and installation
   initrds through:
   - add_drivers/omit_drivers in dracut.conf
   - --drivers/--omit-drivers command line options

Key changes:
- Add driver attribute to dracut schema definition
- Implement driver handling in BootImageDracut
- Add driver support in DiskBuilder and InstallImageBuilder
- Update XMLState to process driver configurations
- Add comprehensive test coverage for driver handling

Example usage:
<initrd action="add">
    <dracut driver="erofs"/>
</initrd>
Copy link
Collaborator

@schaefi schaefi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks much for your work. Just one remark of a Kernel class that we should re-use and a question regarding the creation of auto generated data. Thanks much

Comment on lines 397 to 419
def _get_drivers(self) -> List[str]:
try:
kernel_version = Command.run([
'chroot', self.boot_root_directory,
'uname', '-r'
]).output.strip()
cmd = Command.run(
[
'chroot', self.boot_root_directory,
'cat', f'/lib/modules/{kernel_version}/modules.dep'
]
)
drivers = []
for line in cmd.output.splitlines():
if line:
driver_path = line.split(':')[0].strip()
driver_name = os.path.basename(driver_path).split('.ko')[0]
drivers.append(driver_name)
return drivers
except Exception as e:
log.warning(f"Error reading drivers: {str(e)}")
return []

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We offer a Kernel class that simplifies retrieving data like the kernel version. Can we make use of this code instead of sort of duplicating the code. e.g.

from kiwi.system.kernel import Kernel
kernel = Kernel(root_dir)
kernel_info = kernel.get_kernel()
print(kernel_info.version)

feel free to extend the Kernel interface if need be. Thanks much

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now using kernel_info.version to obtain the kernel version. Thank you for suggesting using the Kernel class.

subclass = None
superclass = None
def __init__(self, module=None, uefi=None):
def __init__(self, module=None, driver=None, uefi=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a stupid question and just to put me right. The xml_parse.py is like the schema/kiwi.rng an auto generated file. So am I correct that you only modified schema/kiwi.rnc and then called make kiwi/schema/kiwi.rng to auto generated the API ? If yes, all is good, if not and you have manually modified xml_parse.py or schema/kiwi.rng then please let it create through the make target. Thanks much

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the latest commit, I ran make kiwi/schema/kiwi.rng, but I had to manually adjust the output in kiwi/xml_parse.py to use f-string formatting because generateDS.py tool doesn't generate the output using f-string format

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aale24 I can keep this for now but please have in mind that the next schema changes might revert this back to the way how the generatedDS module handles it. Did you had a programmatic way to move from format sequences into f strings ? If yes we should add that to the Makefile as a step after generateDS.

In addition I could not find an issue in the auto generated API with regards to format sequences vs. f-strings. So did you had a specific reason why this change was required ?

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schaefi. You're correct that this situation requires some clarification:

  1. The change to f-strings was initially made in this commit: 28ed67e
  2. When I ran make kiwi/schema/kiwi.rng, the generateDS tool reverted the f-strings back to format sequences in kiwi/xml_parse.py.
  3. To maintain consistency with the earlier commit and to avoid introducing unnecessary changes in the PR, I manually adjusted the output in kiwi/xml_parse.py back to f-strings after running the make command.

You're right that this manual adjustment isn't ideal, as future schema changes might revert it again. Currently, I don't have a programmatic way to convert format sequences to f-strings automatically but I could create an issue and work on that. Let me know if you want to use the f-string format in kiwi/xml_parse.py

@schaefi
Copy link
Collaborator

schaefi commented Jun 10, 2025

Oh and I forgot to mention we need at least some words about the new elements in the documentation. Please find it here:

  • doc/source/image_description/elements.rst

There is already documentation for the existing elements, just add the new ones as you see fit. Thanks

@aale24
Copy link
Contributor Author

aale24 commented Jun 10, 2025

Thanks for the comments, I will be working on them.

- Use Kernel class instead of direct commands
- Adjust tests to match the new implementation
- Add documentation for the new driver functionality
@aale24 aale24 requested a review from schaefi June 14, 2025 22:36
Copy link
Collaborator

@schaefi schaefi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great now, thanks much 👍

@schaefi schaefi merged commit b57dbd2 into OSInside:main Jun 16, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhanced Dracut Configuration Options in Image Description

2 participants