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