diff --git a/internal/distro/rhel85/stage_options.go b/internal/distro/rhel85/stage_options.go index f06bb68f6..b75eadd50 100644 --- a/internal/distro/rhel85/stage_options.go +++ b/internal/distro/rhel85/stage_options.go @@ -4,8 +4,10 @@ import ( "fmt" "path/filepath" + "github.com/google/uuid" "github.com/osbuild/osbuild-composer/internal/blueprint" "github.com/osbuild/osbuild-composer/internal/crypt" + "github.com/osbuild/osbuild-composer/internal/disk" osbuild "github.com/osbuild/osbuild-composer/internal/osbuild2" "github.com/osbuild/osbuild-composer/internal/rpmmd" ) @@ -306,3 +308,43 @@ func xorrisofsStageOptions(filename string, arch string) *osbuild.XorrisofsStage IsohybridMBR: "/usr/share/syslinux/isohdpfx.bin", } } + +func grub2StageOptions(pt *disk.PartitionTable, kernelOptions string, kernel *blueprint.KernelCustomization, packages []rpmmd.PackageSpec, uefi bool, legacy string) *osbuild.GRUB2StageOptions { + if pt == nil { + panic("partition table must be defined for grub2 stage, this is a programming error") + } + rootPartition := pt.RootPartition() + if rootPartition == nil { + panic("root partition must be defined for grub2 stage, this is a programming error") + } + + stageOptions := osbuild.GRUB2StageOptions{ + RootFilesystemUUID: uuid.MustParse(rootPartition.Filesystem.UUID), + KernelOptions: kernelOptions, + Legacy: legacy, + } + + if uefi { + stageOptions.UEFI = &osbuild.GRUB2UEFI{ + Vendor: "redhat", + } + } + + if !uefi { + stageOptions.Legacy = legacy + } + + if kernel != nil { + if kernel.Append != "" { + stageOptions.KernelOptions += " " + kernel.Append + } + for _, pkg := range packages { + if pkg.Name == kernel.Name { + stageOptions.SavedEntry = "ffffffffffffffffffffffffffffffff-" + pkg.Version + "-" + pkg.Release + "." + pkg.Arch + break + } + } + } + + return &stageOptions +}