[RFC,5/5] initramfs: allow to set the generator command

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

Commit Message

Quirin Gylstorff Sept. 5, 2025, 11:27 a.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

This allows to exchange the initramfs generator.

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 meta/classes/initramfs.bbclass | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Jan Kiszka Sept. 5, 2025, 12:32 p.m. UTC | #1
On 05.09.25 13:27, Quirin Gylstorff wrote:
> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> 
> This allows to exchange the initramfs generator.
> 
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
>  meta/classes/initramfs.bbclass | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/meta/classes/initramfs.bbclass b/meta/classes/initramfs.bbclass
> index 658ef0ac..f9c919de 100644
> --- a/meta/classes/initramfs.bbclass
> +++ b/meta/classes/initramfs.bbclass
> @@ -10,6 +10,7 @@ INITRAMFS_INSTALL ?= ""
>  INITRAMFS_PREINSTALL ?= ""
>  INITRAMFS_ROOTFS ?= "${WORKDIR}/rootfs"
>  INITRAMFS_IMAGE_NAME = "${INITRAMFS_FULLNAME}.initrd.img"
> +INITRAMFS_GENERATOR_PKG ??= "initramfs-tools"
>  INITRD_DEPLOY_FILE = "${INITRAMFS_IMAGE_NAME}"
>  
>  # Install proper kernel
> @@ -26,6 +27,6 @@ DEPENDS += "${INITRAMFS_INSTALL}"
>  
>  ROOTFSDIR = "${INITRAMFS_ROOTFS}"
>  ROOTFS_FEATURES = "generate-manifest"
> -ROOTFS_PACKAGES = "initramfs-tools ${INITRAMFS_PREINSTALL} ${INITRAMFS_INSTALL}"
> +ROOTFS_PACKAGES = "${INITRAMFS_GENERATOR_PKG} ${INITRAMFS_PREINSTALL} ${INITRAMFS_INSTALL}"
>  
>  inherit rootfs

Do we need extra safety belts for the case that users create custom
initramfs hooks and set the wrong INITRAMFS_GENERATOR_PKG?

Jan
Quirin Gylstorff Sept. 5, 2025, 12:41 p.m. UTC | #2
On 9/5/25 14:32, Jan Kiszka wrote:
> On 05.09.25 13:27, Quirin Gylstorff wrote:
>> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>
>> This allows to exchange the initramfs generator.
>>
>> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>> ---
>>   meta/classes/initramfs.bbclass | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/meta/classes/initramfs.bbclass b/meta/classes/initramfs.bbclass
>> index 658ef0ac..f9c919de 100644
>> --- a/meta/classes/initramfs.bbclass
>> +++ b/meta/classes/initramfs.bbclass
>> @@ -10,6 +10,7 @@ INITRAMFS_INSTALL ?= ""
>>   INITRAMFS_PREINSTALL ?= ""
>>   INITRAMFS_ROOTFS ?= "${WORKDIR}/rootfs"
>>   INITRAMFS_IMAGE_NAME = "${INITRAMFS_FULLNAME}.initrd.img"
>> +INITRAMFS_GENERATOR_PKG ??= "initramfs-tools"
>>   INITRD_DEPLOY_FILE = "${INITRAMFS_IMAGE_NAME}"
>>   
>>   # Install proper kernel
>> @@ -26,6 +27,6 @@ DEPENDS += "${INITRAMFS_INSTALL}"
>>   
>>   ROOTFSDIR = "${INITRAMFS_ROOTFS}"
>>   ROOTFS_FEATURES = "generate-manifest"
>> -ROOTFS_PACKAGES = "initramfs-tools ${INITRAMFS_PREINSTALL} ${INITRAMFS_INSTALL}"
>> +ROOTFS_PACKAGES = "${INITRAMFS_GENERATOR_PKG} ${INITRAMFS_PREINSTALL} ${INITRAMFS_INSTALL}"
>>   
>>   inherit rootfs
> 
> Do we need extra safety belts for the case that users create custom
> initramfs hooks and set the wrong INITRAMFS_GENERATOR_PKG?

I am not sure if this will survive the next iteration. Reusing the 
initramfs class for dracut initrd leads to major pains if using in 
layers where the INITRAMFS_(PRE)INSTALL is set by *.conf.

My current plan is to split it up and create a base class.

Quirn
> 
> Jan
>
Jan Kiszka Sept. 5, 2025, 12:52 p.m. UTC | #3
On 05.09.25 14:41, Quirin Gylstorff wrote:
> 
> 
> On 9/5/25 14:32, Jan Kiszka wrote:
>> On 05.09.25 13:27, Quirin Gylstorff wrote:
>>> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>>
>>> This allows to exchange the initramfs generator.
>>>
>>> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>> ---
>>>   meta/classes/initramfs.bbclass | 3 ++-
>>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/meta/classes/initramfs.bbclass b/meta/classes/
>>> initramfs.bbclass
>>> index 658ef0ac..f9c919de 100644
>>> --- a/meta/classes/initramfs.bbclass
>>> +++ b/meta/classes/initramfs.bbclass
>>> @@ -10,6 +10,7 @@ INITRAMFS_INSTALL ?= ""
>>>   INITRAMFS_PREINSTALL ?= ""
>>>   INITRAMFS_ROOTFS ?= "${WORKDIR}/rootfs"
>>>   INITRAMFS_IMAGE_NAME = "${INITRAMFS_FULLNAME}.initrd.img"
>>> +INITRAMFS_GENERATOR_PKG ??= "initramfs-tools"
>>>   INITRD_DEPLOY_FILE = "${INITRAMFS_IMAGE_NAME}"
>>>     # Install proper kernel
>>> @@ -26,6 +27,6 @@ DEPENDS += "${INITRAMFS_INSTALL}"
>>>     ROOTFSDIR = "${INITRAMFS_ROOTFS}"
>>>   ROOTFS_FEATURES = "generate-manifest"
>>> -ROOTFS_PACKAGES = "initramfs-tools ${INITRAMFS_PREINSTALL}
>>> ${INITRAMFS_INSTALL}"
>>> +ROOTFS_PACKAGES = "${INITRAMFS_GENERATOR_PKG}
>>> ${INITRAMFS_PREINSTALL} ${INITRAMFS_INSTALL}"
>>>     inherit rootfs
>>
>> Do we need extra safety belts for the case that users create custom
>> initramfs hooks and set the wrong INITRAMFS_GENERATOR_PKG?
> 
> I am not sure if this will survive the next iteration. Reusing the
> initramfs class for dracut initrd leads to major pains if using in
> layers where the INITRAMFS_(PRE)INSTALL is set by *.conf.

No, it's really about flagging / preventing unsupported combos. We will
continue to support initramfs-hooks for a longer while, backward
compatibility. But now user should not try to generate custom initramfs
with those hooks while having switched to a different generator.

> 
> My current plan is to split it up and create a base class.

We will probably need completely different helpers to create custom
dracut modules, no?

Jan
Quirin Gylstorff Sept. 5, 2025, 1:03 p.m. UTC | #4
On 9/5/25 14:52, Jan Kiszka wrote:
> On 05.09.25 14:41, Quirin Gylstorff wrote:
>>
>>
>> On 9/5/25 14:32, Jan Kiszka wrote:
>>> On 05.09.25 13:27, Quirin Gylstorff wrote:
>>>> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>>>
>>>> This allows to exchange the initramfs generator.
>>>>
>>>> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>>>> ---
>>>>    meta/classes/initramfs.bbclass | 3 ++-
>>>>    1 file changed, 2 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/meta/classes/initramfs.bbclass b/meta/classes/
>>>> initramfs.bbclass
>>>> index 658ef0ac..f9c919de 100644
>>>> --- a/meta/classes/initramfs.bbclass
>>>> +++ b/meta/classes/initramfs.bbclass
>>>> @@ -10,6 +10,7 @@ INITRAMFS_INSTALL ?= ""
>>>>    INITRAMFS_PREINSTALL ?= ""
>>>>    INITRAMFS_ROOTFS ?= "${WORKDIR}/rootfs"
>>>>    INITRAMFS_IMAGE_NAME = "${INITRAMFS_FULLNAME}.initrd.img"
>>>> +INITRAMFS_GENERATOR_PKG ??= "initramfs-tools"
>>>>    INITRD_DEPLOY_FILE = "${INITRAMFS_IMAGE_NAME}"
>>>>      # Install proper kernel
>>>> @@ -26,6 +27,6 @@ DEPENDS += "${INITRAMFS_INSTALL}"
>>>>      ROOTFSDIR = "${INITRAMFS_ROOTFS}"
>>>>    ROOTFS_FEATURES = "generate-manifest"
>>>> -ROOTFS_PACKAGES = "initramfs-tools ${INITRAMFS_PREINSTALL}
>>>> ${INITRAMFS_INSTALL}"
>>>> +ROOTFS_PACKAGES = "${INITRAMFS_GENERATOR_PKG}
>>>> ${INITRAMFS_PREINSTALL} ${INITRAMFS_INSTALL}"
>>>>      inherit rootfs
>>>
>>> Do we need extra safety belts for the case that users create custom
>>> initramfs hooks and set the wrong INITRAMFS_GENERATOR_PKG?
>>
>> I am not sure if this will survive the next iteration. Reusing the
>> initramfs class for dracut initrd leads to major pains if using in
>> layers where the INITRAMFS_(PRE)INSTALL is set by *.conf.
> 
> No, it's really about flagging / preventing unsupported combos. We will
> continue to support initramfs-hooks for a longer while, backward
> compatibility. But now user should not try to generate custom initramfs
> with those hooks while having switched to a different generator.

Currently it breaks on the package installation level if the dependency 
are correct. As initramfs-tools are incompatible with dracut. We need to
check the dependencies of the package before installing it to avoid 
this. For now i can check if there are recipes with a specific name in 
ROOTFS_PACKAGE but there is always the possibility to that it will break 
on installation.

> 
>>
>> My current plan is to split it up and create a base class.
> 
> We will probably need completely different helpers to create custom
> dracut modules, no?

Yes we need a new set of helpers. I will look into it after the basic 
infrastructure is in place.


 > > Jan
> 
Quirin

Patch

diff --git a/meta/classes/initramfs.bbclass b/meta/classes/initramfs.bbclass
index 658ef0ac..f9c919de 100644
--- a/meta/classes/initramfs.bbclass
+++ b/meta/classes/initramfs.bbclass
@@ -10,6 +10,7 @@  INITRAMFS_INSTALL ?= ""
 INITRAMFS_PREINSTALL ?= ""
 INITRAMFS_ROOTFS ?= "${WORKDIR}/rootfs"
 INITRAMFS_IMAGE_NAME = "${INITRAMFS_FULLNAME}.initrd.img"
+INITRAMFS_GENERATOR_PKG ??= "initramfs-tools"
 INITRD_DEPLOY_FILE = "${INITRAMFS_IMAGE_NAME}"
 
 # Install proper kernel
@@ -26,6 +27,6 @@  DEPENDS += "${INITRAMFS_INSTALL}"
 
 ROOTFSDIR = "${INITRAMFS_ROOTFS}"
 ROOTFS_FEATURES = "generate-manifest"
-ROOTFS_PACKAGES = "initramfs-tools ${INITRAMFS_PREINSTALL} ${INITRAMFS_INSTALL}"
+ROOTFS_PACKAGES = "${INITRAMFS_GENERATOR_PKG} ${INITRAMFS_PREINSTALL} ${INITRAMFS_INSTALL}"
 
 inherit rootfs