rhel84/grub2: set saved_entry

Explicitly set the kernel to boot into.

Also change the blueprint/kernenl handling:

Rather than only falling back to the default kernel name for
getting the package list, let GetKernel() always return the
correct result so we can rely on this being consistent.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2021-02-19 20:38:05 +00:00 committed by Ondřej Budai
parent e4b9453d40
commit 0efc345b2d
8 changed files with 45 additions and 29 deletions

View file

@ -104,13 +104,10 @@ func (b *Blueprint) GetPackages() []string {
packages = append(packages, "@"+group.Name) packages = append(packages, "@"+group.Name)
} }
if kc := b.Customizations.GetKernel(); kc != nil && kc.Name != "" { kc := b.Customizations.GetKernel()
kpkg := Package{Name: b.Customizations.Kernel.Name} kpkg := Package{Name: kc.Name}
packages = append(packages, kpkg.ToNameVersion()) packages = append(packages, kpkg.ToNameVersion())
} else { // no Kernel specified; add default
kpkg := Package{Name: "kernel"}
packages = append(packages, kpkg.ToNameVersion())
}
return packages return packages
} }

View file

@ -155,11 +155,21 @@ func (c *Customizations) GetGroups() []GroupCustomization {
} }
func (c *Customizations) GetKernel() *KernelCustomization { func (c *Customizations) GetKernel() *KernelCustomization {
if c == nil { var name string
return nil var append string
if c != nil && c.Kernel != nil {
name = c.Kernel.Name
append = c.Kernel.Append
} }
return c.Kernel if name == "" {
name = "kernel"
}
return &KernelCustomization{
Name: name,
Append: append,
}
} }
func (c *Customizations) GetFirewall() *FirewallCustomization { func (c *Customizations) GetFirewall() *FirewallCustomization {

View file

@ -1,8 +1,9 @@
package blueprint package blueprint
import ( import (
"github.com/stretchr/testify/assert"
"testing" "testing"
"github.com/stretchr/testify/assert"
) )
func TestGetHostname(t *testing.T) { func TestGetHostname(t *testing.T) {
@ -22,6 +23,7 @@ func TestGetKernel(t *testing.T) {
expectedKernel := KernelCustomization{ expectedKernel := KernelCustomization{
Append: "--test", Append: "--test",
Name: "kernel",
} }
TestCustomizations := Customizations{ TestCustomizations := Customizations{
@ -214,7 +216,7 @@ func TestNoCustomizationsInBlueprint(t *testing.T) {
assert.Nil(t, TestBP.Customizations.GetHostname()) assert.Nil(t, TestBP.Customizations.GetHostname())
assert.Nil(t, TestBP.Customizations.GetUsers()) assert.Nil(t, TestBP.Customizations.GetUsers())
assert.Nil(t, TestBP.Customizations.GetGroups()) assert.Nil(t, TestBP.Customizations.GetGroups())
assert.Nil(t, TestBP.Customizations.GetKernel()) assert.Equal(t, &KernelCustomization{Name: "kernel"}, TestBP.Customizations.GetKernel())
assert.Nil(t, TestBP.Customizations.GetFirewall()) assert.Nil(t, TestBP.Customizations.GetFirewall())
assert.Nil(t, TestBP.Customizations.GetServices()) assert.Nil(t, TestBP.Customizations.GetServices())

View file

@ -434,7 +434,7 @@ func (t *imageType) fsTabStageOptions(uefi bool) *osbuild.FSTabStageOptions {
func (t *imageType) grub2StageOptions(kernelOptions string, kernel *blueprint.KernelCustomization, uefi bool) *osbuild.GRUB2StageOptions { func (t *imageType) grub2StageOptions(kernelOptions string, kernel *blueprint.KernelCustomization, uefi bool) *osbuild.GRUB2StageOptions {
id := uuid.MustParse("76a22bf4-f153-4541-b6c7-0332c0dfaeac") id := uuid.MustParse("76a22bf4-f153-4541-b6c7-0332c0dfaeac")
if kernel != nil { if kernel != nil && kernel.Append != "" {
kernelOptions += " " + kernel.Append kernelOptions += " " + kernel.Append
} }

View file

@ -446,7 +446,7 @@ func (t *imageType) fsTabStageOptions(uefi bool) *osbuild.FSTabStageOptions {
func (t *imageType) grub2StageOptions(kernelOptions string, kernel *blueprint.KernelCustomization, uefi bool) *osbuild.GRUB2StageOptions { func (t *imageType) grub2StageOptions(kernelOptions string, kernel *blueprint.KernelCustomization, uefi bool) *osbuild.GRUB2StageOptions {
id := uuid.MustParse("76a22bf4-f153-4541-b6c7-0332c0dfaeac") id := uuid.MustParse("76a22bf4-f153-4541-b6c7-0332c0dfaeac")
if kernel != nil { if kernel != nil && kernel.Append != "" {
kernelOptions += " " + kernel.Append kernelOptions += " " + kernel.Append
} }

View file

@ -475,7 +475,7 @@ func (t *imageType) fsTabStageOptions(uefi bool) *osbuild.FSTabStageOptions {
func (t *imageType) grub2StageOptions(kernelOptions string, kernel *blueprint.KernelCustomization, uefi bool) *osbuild.GRUB2StageOptions { func (t *imageType) grub2StageOptions(kernelOptions string, kernel *blueprint.KernelCustomization, uefi bool) *osbuild.GRUB2StageOptions {
id := uuid.MustParse("0bd700f8-090f-4556-b797-b340297ea1bd") id := uuid.MustParse("0bd700f8-090f-4556-b797-b340297ea1bd")
if kernel != nil { if kernel != nil && kernel.Append != "" {
kernelOptions += " " + kernel.Append kernelOptions += " " + kernel.Append
} }

View file

@ -303,7 +303,7 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp
if t.bootable { if t.bootable {
if t.arch.Name() != "s390x" { if t.arch.Name() != "s390x" {
p.AddStage(osbuild.NewGRUB2Stage(t.grub2StageOptions(pt, t.kernelOptions, c.GetKernel(), t.arch.uefi, t.arch.legacy))) p.AddStage(osbuild.NewGRUB2Stage(t.grub2StageOptions(pt, t.kernelOptions, c.GetKernel(), packageSpecs, t.arch.uefi, t.arch.legacy)))
} }
} }
@ -523,7 +523,7 @@ func (t *imageType) systemdStageOptions(enabledServices, disabledServices []stri
} }
} }
func (t *imageType) grub2StageOptions(pt *disk.PartitionTable, kernelOptions string, kernel *blueprint.KernelCustomization, uefi bool, legacy string) *osbuild.GRUB2StageOptions { func (t *imageType) grub2StageOptions(pt *disk.PartitionTable, kernelOptions string, kernel *blueprint.KernelCustomization, packages []rpmmd.PackageSpec, uefi bool, legacy string) *osbuild.GRUB2StageOptions {
if pt == nil { if pt == nil {
panic("partition table must be defined for grub2 stage, this is a programming error") panic("partition table must be defined for grub2 stage, this is a programming error")
} }
@ -532,13 +532,12 @@ func (t *imageType) grub2StageOptions(pt *disk.PartitionTable, kernelOptions str
panic("root partition must be defined for grub2 stage, this is a programming error") panic("root partition must be defined for grub2 stage, this is a programming error")
} }
id := uuid.MustParse(rootPartition.Filesystem.UUID) stageOptions := osbuild.GRUB2StageOptions{
RootFilesystemUUID: uuid.MustParse(rootPartition.Filesystem.UUID),
if kernel != nil { KernelOptions: kernelOptions,
kernelOptions += " " + kernel.Append Legacy: legacy,
} }
var uefiOptions *osbuild.GRUB2UEFI
if uefi { if uefi {
var vendor string var vendor string
if t.arch.distro.isCentos { if t.arch.distro.isCentos {
@ -546,21 +545,28 @@ func (t *imageType) grub2StageOptions(pt *disk.PartitionTable, kernelOptions str
} else { } else {
vendor = "redhat" vendor = "redhat"
} }
uefiOptions = &osbuild.GRUB2UEFI{ stageOptions.UEFI = &osbuild.GRUB2UEFI{
Vendor: vendor, Vendor: vendor,
} }
} }
if !uefi { if !uefi {
legacy = t.arch.legacy stageOptions.Legacy = t.arch.legacy
} }
return &osbuild.GRUB2StageOptions{ if kernel != nil {
RootFilesystemUUID: id, if kernel.Append != "" {
KernelOptions: kernelOptions, stageOptions.KernelOptions += " " + kernel.Append
Legacy: legacy, }
UEFI: uefiOptions, for _, pkg := range packages {
if pkg.Name == kernel.Name {
stageOptions.SavedEntry = "ffffffffffffffffffffffffffffffff-" + pkg.Version + "-" + pkg.Release + "." + pkg.Arch
break
}
}
} }
return &stageOptions
} }
func (t *imageType) selinuxStageOptions() *osbuild.SELinuxStageOptions { func (t *imageType) selinuxStageOptions() *osbuild.SELinuxStageOptions {

View file

@ -16,6 +16,7 @@ type GRUB2StageOptions struct {
KernelOptions string `json:"kernel_opts,omitempty"` KernelOptions string `json:"kernel_opts,omitempty"`
Legacy string `json:"legacy,omitempty"` Legacy string `json:"legacy,omitempty"`
UEFI *GRUB2UEFI `json:"uefi,omitempty"` UEFI *GRUB2UEFI `json:"uefi,omitempty"`
SavedEntry string `json:"saved_entry,omitempty"`
} }
type GRUB2UEFI struct { type GRUB2UEFI struct {