Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/distrodefs/bootc-generic/imagetypes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@

supported_options_lists:
supported_options_disk: &supported_options_disk
- "customizations.bootloader"
- "customizations.directories"
- "customizations.disk"
- "customizations.files"
Expand Down
14 changes: 14 additions & 0 deletions pkg/distro/generic/bootc_imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,20 @@
img.OSCustomizations.KernelOptionsAppend = append(img.OSCustomizations.KernelOptionsAppend, kopts.Append)
}

if bl := customizations.GetBootloader(); bl != nil && bl.Grub2 != nil {

Check failure on line 259 in pkg/distro/generic/bootc_imagetype.go

View workflow job for this annotation

GitHub Actions / Validate manifest checksums

customizations.GetBootloader undefined (type *blueprint.Customizations has no field or method GetBootloader)

Check failure on line 259 in pkg/distro/generic/bootc_imagetype.go

View workflow job for this annotation

GitHub Actions / ⌨ Lint

customizations.GetBootloader undefined (type *blueprint.Customizations has no field or method GetBootloader)) (typecheck)

Check failure on line 259 in pkg/distro/generic/bootc_imagetype.go

View workflow job for this annotation

GitHub Actions / 🛃 Container resolver tests

customizations.GetBootloader undefined (type *blueprint.Customizations has no field or method GetBootloader)

Check failure on line 259 in pkg/distro/generic/bootc_imagetype.go

View workflow job for this annotation

GitHub Actions / 🔍 Check source preparation and test configs

customizations.GetBootloader undefined (type *blueprint.Customizations has no field or method GetBootloader)
grub2Cfg := &osbuild.GRUB2Config{}
if len(bl.Grub2.TerminalInput) > 0 {
grub2Cfg.TerminalInput = bl.Grub2.TerminalInput
}
if len(bl.Grub2.TerminalOutput) > 0 {
grub2Cfg.TerminalOutput = bl.Grub2.TerminalOutput
}
if bl.Grub2.Serial != nil {
grub2Cfg.Serial = *bl.Grub2.Serial
}
img.OSCustomizations.Grub2Config = grub2Cfg
}

rootfsMinSize := max(bd.rootfsMinSize, options.Size)

pt, err := t.genPartitionTable(customizations, rootfsMinSize, rng)
Expand Down
16 changes: 16 additions & 0 deletions pkg/manifest/raw_bootc.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,22 @@ func (p *RawBootcImage) serialize() (osbuild.Pipeline, error) {
postStages = append(postStages, ignitionStage)
}

// Apply grub2 console configuration (terminal_input, terminal_output,
// serial) via the grub2.d stage which writes a drop-in config file
// under boot/grub2/. Like ignition, this writes to /boot so we use
// bootupd mounts.
if grub2dCfg := osbuild.NewGrub2DConfigFromGrub2Config(p.OSCustomizations.Grub2Config); grub2dCfg != nil {
grub2dOpts := &osbuild.Grub2DStageOptions{
Config: grub2dCfg,
}
grub2dStage := osbuild.NewGrub2DStage(grub2dOpts)
grub2dStage.Devices, grub2dStage.Mounts, err = osbuild.GenBootupdDevicesMounts(p.filename, p.PartitionTable, p.platform)
if err != nil {
return osbuild.Pipeline{}, fmt.Errorf("gen devices for grub2.d stage failed %w", err)
}
postStages = append(postStages, grub2dStage)
}

pipeline.AddStages(postStages...)

// In case we created any files in the deploy directory we need to relabel
Expand Down
50 changes: 50 additions & 0 deletions pkg/osbuild/grub2_d_stage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package osbuild

// Grub2DStageOptions represents options for the
// org.osbuild.grub2.d stage.
//
// This stage writes a GRUB2 drop-in configuration file at a
// configurable path relative to the filesystem root. The path
// defaults to "boot/grub2/console.cfg".
type Grub2DStageOptions struct {
// Path relative to the filesystem root
// (default: "boot/grub2/console.cfg")
Path string `json:"path,omitempty"`

// GRUB2 configuration to write
Config *Grub2DConfig `json:"config"`
}

// Grub2DConfig contains GRUB2 settings for a drop-in config file.
type Grub2DConfig struct {
TerminalInput []string `json:"terminal_input,omitempty"`
TerminalOutput []string `json:"terminal_output,omitempty"`
Serial string `json:"serial,omitempty"`
}

func (Grub2DStageOptions) isStageOptions() {}

func NewGrub2DStage(options *Grub2DStageOptions) *Stage {
return &Stage{
Type: "org.osbuild.grub2.d",
Options: options,
}
}

// NewGrub2DConfigFromGrub2Config creates a Grub2DConfig from a
// GRUB2Config, extracting only the console-related fields.
// Returns nil if no console settings are present.
func NewGrub2DConfigFromGrub2Config(cfg *GRUB2Config) *Grub2DConfig {
if cfg == nil {
return nil
}
c := &Grub2DConfig{
TerminalInput: cfg.TerminalInput,
TerminalOutput: cfg.TerminalOutput,
Serial: cfg.Serial,
}
if len(c.TerminalInput) == 0 && len(c.TerminalOutput) == 0 && c.Serial == "" {
return nil
}
return c
}
Loading