Skip to content

Commit

Permalink
distro/rhel84: remove hardcoded root partition UUIDs
Browse files Browse the repository at this point in the history
Let's use the root partition UUID from the partition table instead of
hardcoding the value.

Signed-off-by: Ondřej Budai <[email protected]>
  • Loading branch information
ondrejbudai committed Dec 15, 2020
1 parent d52c1ea commit ae0d1b8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
17 changes: 17 additions & 0 deletions internal/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ func (pt PartitionTable) FSTabStageOptions() *osbuild.FSTabStageOptions {
return &options
}

// Returns the root partition (the partition whose filesystem has / as
// a mountpoint) of the partition table. Nil is returned if there's no such
// partition.
func (pt PartitionTable) RootPartition() *Partition {
for _, p := range pt.Partitions {
if p.Filesystem == nil {
continue
}

if p.Filesystem.Mountpoint == "/" {
return &p
}
}

return nil
}

// Converts Partition to osbuild.QEMUPartition that encodes the same partition.
func (p Partition) QEMUPartition() osbuild.QEMUPartition {
var fs *osbuild.QEMUFilesystem
Expand Down
25 changes: 21 additions & 4 deletions internal/distro/rhel84/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,17 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp
p.SetBuild(t.buildPipeline(repos, *t.arch, buildPackageSpecs), "org.osbuild.rhel84")

if t.arch.Name() == "s390x" {
if pt == nil {
panic("s390x image must have a partition table, this is a programming error")
}

rootPartition := pt.RootPartition()
if rootPartition == nil {
panic("s390x image must have a root partition, this is a programming error")
}

p.AddStage(osbuild.NewKernelCmdlineStage(&osbuild.KernelCmdlineStageOptions{
RootFsUUID: "efe8afea-c0a8-45dc-8e6e-499279f6fa5d",
RootFsUUID: rootPartition.UUID,
KernelOpts: "net.ifnames=0 crashkernel=auto",
}))
}
Expand All @@ -256,7 +265,7 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp

if t.bootable {
if t.arch.Name() != "s390x" {
p.AddStage(osbuild.NewGRUB2Stage(t.grub2StageOptions(t.kernelOptions, c.GetKernel(), t.arch.uefi, t.arch.legacy)))
p.AddStage(osbuild.NewGRUB2Stage(t.grub2StageOptions(pt, t.kernelOptions, c.GetKernel(), t.arch.uefi, t.arch.legacy)))
}
}

Expand Down Expand Up @@ -448,8 +457,16 @@ func (t *imageType) systemdStageOptions(enabledServices, disabledServices []stri
}
}

func (t *imageType) grub2StageOptions(kernelOptions string, kernel *blueprint.KernelCustomization, uefi bool, legacy string) *osbuild.GRUB2StageOptions {
id := uuid.MustParse("efe8afea-c0a8-45dc-8e6e-499279f6fa5d")
func (t *imageType) grub2StageOptions(pt *disk.PartitionTable, kernelOptions string, kernel *blueprint.KernelCustomization, 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")
}

id := uuid.MustParse(rootPartition.Filesystem.UUID)

if kernel != nil {
kernelOptions += " " + kernel.Append
Expand Down

0 comments on commit ae0d1b8

Please sign in to comment.