dracut: quote DRACUT_EXTRA_MODULES/DRIVERS for --add

Message ID 20260630114346.14229-1-kumar.rakesh@siemens.com
State Under Review
Headers show
Series dracut: quote DRACUT_EXTRA_MODULES/DRIVERS for --add | expand

Commit Message

Kumar, Rakesh June 30, 2026, 11:43 a.m. UTC
extend_dracut_cmdline() joined multiple modules/drivers into the
--add / --add-drivers arguments without quoting. With more than one
entry the shell split the list, so dracut consumed only the first
module and treated the rest as positional arguments (the output image
path), breaking initramfs generation. Quote the lists so they are
passed as a single argument.

Signed-off-by: Rakesh Kumar <kumar.rakesh@siemens.com>
---
 meta/classes-recipe/initrd-dracut.bbclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

MOESSBAUER, Felix June 30, 2026, 11:50 a.m. UTC | #1
On Tue, 2026-06-30 at 07:43 -0400, 'Rakesh Kumar' via isar-users wrote:
> extend_dracut_cmdline() joined multiple modules/drivers into the
> --add / --add-drivers arguments without quoting. With more than one
> entry the shell split the list, so dracut consumed only the first
> module and treated the rest as positional arguments (the output image
> path), breaking initramfs generation. Quote the lists so they are
> passed as a single argument.

+ CC Quirin

Hi, good catch, but please also add a fixes tag.

> 
> Signed-off-by: Rakesh Kumar <kumar.rakesh@siemens.com>
> ---
>  meta/classes-recipe/initrd-dracut.bbclass | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/classes-recipe/initrd-dracut.bbclass b/meta/classes-recipe/initrd-dracut.bbclass
> index bb4b50b7..542b1fbe 100644
> --- a/meta/classes-recipe/initrd-dracut.bbclass
> +++ b/meta/classes-recipe/initrd-dracut.bbclass
> @@ -48,9 +48,9 @@ def extend_dracut_cmdline(d):
>      if config_path:
>          cmdline.append(f"--conf {config_path}")
>      if extra_drivers:
> -        cmdline.append(f"--add-drivers {extra_drivers}")
> +        cmdline.append(f'--add-drivers "{extra_drivers}"')

Nit: Wouldn't it be better to use single quotes around {extra_drivers}
to ensure shell variables are not expanded within the quote?

Felix

>      if extra_modules:
> -        cmdline.append(f"--add {extra_modules}")
> +        cmdline.append(f'--add "{extra_modules}"')
>      return ' '.join(cmdline)
>  
>  ROOTFS_INITRAMFS_GENERATOR_CMDLINE:append = " ${@ extend_dracut_cmdline(d)}"
> -- 
> 2.39.5
> 
> -- 
> You received this message because you are subscribed to the Google Groups "isar-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/isar-users/20260630114346.14229-1-kumar.rakesh%40siemens.com.
Quirin Gylstorff June 30, 2026, 1:48 p.m. UTC | #2
On 6/30/26 1:50 PM, Moessbauer, Felix (FT RPD CED OES-DE) wrote:
> On Tue, 2026-06-30 at 07:43 -0400, 'Rakesh Kumar' via isar-users wrote:
>> extend_dracut_cmdline() joined multiple modules/drivers into the
>> --add / --add-drivers arguments without quoting. With more than one
>> entry the shell split the list, so dracut consumed only the first
>> module and treated the rest as positional arguments (the output image
>> path), breaking initramfs generation. Quote the lists so they are
>> passed as a single argument.
> 
> + CC Quirin
> 
> Hi, good catch, but please also add a fixes tag.
> 

Thanks for the fix.

I never tested the cmdline with multiple modules/drivers as my intention 
was to use the variables only for development. In production all 
modules/drivers should be added via a dracut config.

Quirin
>>
>> Signed-off-by: Rakesh Kumar <kumar.rakesh@siemens.com>
>> ---
>>   meta/classes-recipe/initrd-dracut.bbclass | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/meta/classes-recipe/initrd-dracut.bbclass b/meta/classes-recipe/initrd-dracut.bbclass
>> index bb4b50b7..542b1fbe 100644
>> --- a/meta/classes-recipe/initrd-dracut.bbclass
>> +++ b/meta/classes-recipe/initrd-dracut.bbclass
>> @@ -48,9 +48,9 @@ def extend_dracut_cmdline(d):
>>       if config_path:
>>           cmdline.append(f"--conf {config_path}")
>>       if extra_drivers:
>> -        cmdline.append(f"--add-drivers {extra_drivers}")
>> +        cmdline.append(f'--add-drivers "{extra_drivers}"')
> 
> Nit: Wouldn't it be better to use single quotes around {extra_drivers}
> to ensure shell variables are not expanded within the quote?
> 
> Felix
> 
>>       if extra_modules:
>> -        cmdline.append(f"--add {extra_modules}")
>> +        cmdline.append(f'--add "{extra_modules}"')
>>       return ' '.join(cmdline)
>>   
>>   ROOTFS_INITRAMFS_GENERATOR_CMDLINE:append = " ${@ extend_dracut_cmdline(d)}"
>> -- 
>> 2.39.5
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups "isar-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
>> To view this discussion visit https://groups.google.com/d/msgid/isar-users/20260630114346.14229-1-kumar.rakesh%40siemens.com.
Kumar, Rakesh June 30, 2026, 2:36 p.m. UTC | #3
Hi Felix,

I actually tried single quotes and it broke the build with `getopt: option '--add' requires an argument` .  The reason probably is in
https://github.com/ilbers/isar/blob/b90b722fc2666b806a64f0bf5ca0feeb9b6f203b/meta/classes-recipe/rootfs.bbclass#L660

BitBake substitutes our --add "..." into a string that's already wrapped in single quotes. If we use single quotes for the module list, those inner ' characters close the outer single-quoted block early, the quoting collapses, and the multi-module list is no longer passed as one argument to --add - hence the failure.

Double quotes seems correct choice here: they pass literally through the outer single-quoted context and are then interpreted by the inner `sh -ec`, which groups mod1 mod2 into a single --add argument as intended.


Regards,
Rakesh

-----Original Message-----
From: Gylstorff, Quirin (FT RPD CED OES-DE) <quirin.gylstorff@siemens.com>
Sent: 30 June 2026 19:18
To: Moessbauer, Felix (FT RPD CED OES-DE) <felix.moessbauer@siemens.com>; Kumar, Rakesh (FT FDS CES LX PBU 1) <kumar.rakesh@siemens.com>; isar-users@googlegroups.com
Subject: Re: [PATCH] dracut: quote DRACUT_EXTRA_MODULES/DRIVERS for --add



On 6/30/26 1:50 PM, Moessbauer, Felix (FT RPD CED OES-DE) wrote:
> On Tue, 2026-06-30 at 07:43 -0400, 'Rakesh Kumar' via isar-users wrote:
>> extend_dracut_cmdline() joined multiple modules/drivers into the
>> --add / --add-drivers arguments without quoting. With more than one
>> entry the shell split the list, so dracut consumed only the first
>> module and treated the rest as positional arguments (the output image
>> path), breaking initramfs generation. Quote the lists so they are
>> passed as a single argument.
>
> + CC Quirin
>
> Hi, good catch, but please also add a fixes tag.
>

Thanks for the fix.

I never tested the cmdline with multiple modules/drivers as my intention was to use the variables only for development. In production all modules/drivers should be added via a dracut config.

Quirin
>>
>> Signed-off-by: Rakesh Kumar <kumar.rakesh@siemens.com>
>> ---
>>   meta/classes-recipe/initrd-dracut.bbclass | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/meta/classes-recipe/initrd-dracut.bbclass
>> b/meta/classes-recipe/initrd-dracut.bbclass
>> index bb4b50b7..542b1fbe 100644
>> --- a/meta/classes-recipe/initrd-dracut.bbclass
>> +++ b/meta/classes-recipe/initrd-dracut.bbclass
>> @@ -48,9 +48,9 @@ def extend_dracut_cmdline(d):
>>       if config_path:
>>           cmdline.append(f"--conf {config_path}")
>>       if extra_drivers:
>> -        cmdline.append(f"--add-drivers {extra_drivers}")
>> +        cmdline.append(f'--add-drivers "{extra_drivers}"')
>
> Nit: Wouldn't it be better to use single quotes around {extra_drivers}
> to ensure shell variables are not expanded within the quote?
>
> Felix
>
>>       if extra_modules:
>> -        cmdline.append(f"--add {extra_modules}")
>> +        cmdline.append(f'--add "{extra_modules}"')
>>       return ' '.join(cmdline)
>>
>>   ROOTFS_INITRAMFS_GENERATOR_CMDLINE:append = " ${@ extend_dracut_cmdline(d)}"
>> --
>> 2.39.5
>>
>> --
>> You received this message because you are subscribed to the Google Groups "isar-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
>> To view this discussion visit https://groups.google.com/d/msgid/isar-users/20260630114346.14229-1-kumar.rakesh%40siemens.com.
MOESSBAUER, Felix June 30, 2026, 3:10 p.m. UTC | #4
On Tue, 2026-06-30 at 14:36 +0000, Kumar, Rakesh (FT FDS CES LX PBU 1)
wrote:
> Hi Felix,
> 
> I actually tried single quotes and it broke the build with `getopt: option '--add' requires an argument` .  The reason probably is in
> https://github.com/ilbers/isar/blob/b90b722fc2666b806a64f0bf5ca0feeb9b6f203b/meta/classes-recipe/rootfs.bbclass#L660

Indeed. We should better use a here document to avoid these surprises.
But this is better cleaned up after the rootless switch, as we then
have wrappers.

> 
> BitBake substitutes our --add "..." into a string that's already wrapped in single quotes. If we use single quotes for the module list, those inner ' characters close the outer single-quoted block early, the quoting collapses, and the multi-module list is no longer passed as one argument to --add - hence the failure.

Yep.

> 
> Double quotes seems correct choice here: they pass literally through the outer single-quoted context and are then interpreted by the inner `sh -ec`, which groups mod1 mod2 into a single --add argument as intended.

Hidden interface, but we have to clean this up after rootless.
For now the current patch is ok.

Reviewed-by: Felix Moessbauer <felix.moessbauer@siemens.com>

Felix

> 
> 
> Regards,
> Rakesh
> 
> -----Original Message-----
> From: Gylstorff, Quirin (FT RPD CED OES-DE) <quirin.gylstorff@siemens.com>
> Sent: 30 June 2026 19:18
> To: Moessbauer, Felix (FT RPD CED OES-DE) <felix.moessbauer@siemens.com>; Kumar, Rakesh (FT FDS CES LX PBU 1) <kumar.rakesh@siemens.com>; isar-users@googlegroups.com
> Subject: Re: [PATCH] dracut: quote DRACUT_EXTRA_MODULES/DRIVERS for --add
> 
> 
> 
> On 6/30/26 1:50 PM, Moessbauer, Felix (FT RPD CED OES-DE) wrote:
> > On Tue, 2026-06-30 at 07:43 -0400, 'Rakesh Kumar' via isar-users wrote:
> > > extend_dracut_cmdline() joined multiple modules/drivers into the
> > > --add / --add-drivers arguments without quoting. With more than one
> > > entry the shell split the list, so dracut consumed only the first
> > > module and treated the rest as positional arguments (the output image
> > > path), breaking initramfs generation. Quote the lists so they are
> > > passed as a single argument.
> > 
> > + CC Quirin
> > 
> > Hi, good catch, but please also add a fixes tag.
> > 
> 
> Thanks for the fix.
> 
> I never tested the cmdline with multiple modules/drivers as my intention was to use the variables only for development. In production all modules/drivers should be added via a dracut config.
> 
> Quirin
> > > 
> > > Signed-off-by: Rakesh Kumar <kumar.rakesh@siemens.com>
> > > ---
> > >   meta/classes-recipe/initrd-dracut.bbclass | 4 ++--
> > >   1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/meta/classes-recipe/initrd-dracut.bbclass
> > > b/meta/classes-recipe/initrd-dracut.bbclass
> > > index bb4b50b7..542b1fbe 100644
> > > --- a/meta/classes-recipe/initrd-dracut.bbclass
> > > +++ b/meta/classes-recipe/initrd-dracut.bbclass
> > > @@ -48,9 +48,9 @@ def extend_dracut_cmdline(d):
> > >       if config_path:
> > >           cmdline.append(f"--conf {config_path}")
> > >       if extra_drivers:
> > > -        cmdline.append(f"--add-drivers {extra_drivers}")
> > > +        cmdline.append(f'--add-drivers "{extra_drivers}"')
> > 
> > Nit: Wouldn't it be better to use single quotes around {extra_drivers}
> > to ensure shell variables are not expanded within the quote?
> > 
> > Felix
> > 
> > >       if extra_modules:
> > > -        cmdline.append(f"--add {extra_modules}")
> > > +        cmdline.append(f'--add "{extra_modules}"')
> > >       return ' '.join(cmdline)
> > > 
> > >   ROOTFS_INITRAMFS_GENERATOR_CMDLINE:append = " ${@ extend_dracut_cmdline(d)}"
> > > --
> > > 2.39.5
> > > 
> > > --
> > > You received this message because you are subscribed to the Google Groups "isar-users" group.
> > > To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
> > > To view this discussion visit https://groups.google.com/d/msgid/isar-users/20260630114346.14229-1-kumar.rakesh%40siemens.com.

Patch

diff --git a/meta/classes-recipe/initrd-dracut.bbclass b/meta/classes-recipe/initrd-dracut.bbclass
index bb4b50b7..542b1fbe 100644
--- a/meta/classes-recipe/initrd-dracut.bbclass
+++ b/meta/classes-recipe/initrd-dracut.bbclass
@@ -48,9 +48,9 @@  def extend_dracut_cmdline(d):
     if config_path:
         cmdline.append(f"--conf {config_path}")
     if extra_drivers:
-        cmdline.append(f"--add-drivers {extra_drivers}")
+        cmdline.append(f'--add-drivers "{extra_drivers}"')
     if extra_modules:
-        cmdline.append(f"--add {extra_modules}")
+        cmdline.append(f'--add "{extra_modules}"')
     return ' '.join(cmdline)
 
 ROOTFS_INITRAMFS_GENERATOR_CMDLINE:append = " ${@ extend_dracut_cmdline(d)}"