@@ -147,6 +147,9 @@ type QemuBuilder struct {
147
147
Pdeathsig bool
148
148
Argv []string
149
149
150
+ // AppendKernelArguments are appended to the bootloader config
151
+ AppendKernelArguments string
152
+
150
153
// IgnitionNetworkKargs are written to /boot/ignition
151
154
IgnitionNetworkKargs string
152
155
@@ -353,9 +356,8 @@ func (gf *coreosGuestfish) destroy() {
353
356
}
354
357
}
355
358
356
- // setupIgnition copies the ignition file inside the disk image and/or sets
357
- // networking kernel arguments
358
- func setupIgnition (confPath string , knetargs string , diskImagePath string , diskSectorSize int ) error {
359
+ // setupPreboot performs changes necessary before the disk is booted
360
+ func setupPreboot (confPath , knetargs , kargs string , diskImagePath string , diskSectorSize int ) error {
359
361
gf , err := newGuestfish (diskImagePath , diskSectorSize )
360
362
if err != nil {
361
363
return err
@@ -380,6 +382,34 @@ func setupIgnition(confPath string, knetargs string, diskImagePath string, diskS
380
382
}
381
383
}
382
384
385
+ if kargs != "" {
386
+ confpathout , err := exec .Command ("guestfish" , gf .remote , "glob-expand" , "/loader/entries/ostree*conf" ).Output ()
387
+ if err != nil {
388
+ return errors .Wrapf (err , "finding bootloader config path" )
389
+ }
390
+ confs := strings .Split (strings .TrimSpace (string (confpathout )), "\n " )
391
+ if len (confs ) != 1 {
392
+ return fmt .Errorf ("Multiple values for bootloader config: %v" , confpathout )
393
+ }
394
+ confpath := confs [0 ]
395
+
396
+ origconf , err := exec .Command ("guestfish" , gf .remote , "read-file" , confpath ).Output ()
397
+ if err != nil {
398
+ return errors .Wrapf (err , "reading bootloader config" )
399
+ }
400
+ var buf strings.Builder
401
+ for _ , line := range strings .Split (string (origconf ), "\n " ) {
402
+ if strings .HasPrefix (line , "options " ) {
403
+ line += " " + kargs
404
+ }
405
+ buf .Write ([]byte (line ))
406
+ buf .Write ([]byte ("\n " ))
407
+ }
408
+ if err := exec .Command ("guestfish" , gf .remote , "write" , confpath , buf .String ()).Run (); err != nil {
409
+ return errors .Wrapf (err , "writing bootloader config" )
410
+ }
411
+ }
412
+
383
413
if err := exec .Command ("guestfish" , gf .remote , "umount-all" ).Run (); err != nil {
384
414
return errors .Wrapf (err , "guestfish umount failed" )
385
415
}
@@ -440,8 +470,9 @@ func (builder *QemuBuilder) addDiskImpl(disk *Disk, primary bool) error {
440
470
// If the board doesn't support -fw_cfg or we were explicitly
441
471
// requested, inject via libguestfs on the primary disk.
442
472
requiresInjection := builder .Config != "" && (builder .ForceConfigInjection || ! builder .supportsFwCfg ())
443
- if requiresInjection || builder .IgnitionNetworkKargs != "" {
444
- if err = setupIgnition (builder .Config , builder .IgnitionNetworkKargs , dstFileName , disk .SectorSize ); err != nil {
473
+ if requiresInjection || builder .IgnitionNetworkKargs != "" || builder .AppendKernelArguments != "" {
474
+ if err = setupPreboot (builder .Config , builder .IgnitionNetworkKargs , builder .AppendKernelArguments ,
475
+ dstFileName , disk .SectorSize ); err != nil {
445
476
return errors .Wrapf (err , "ignition injection with guestfs failed" )
446
477
}
447
478
}
0 commit comments