rhel85/90: allow specifying the boot partition for the grub2 stage
Specifying the boot partition filesystem UUID in grub2 stage is required in case the `/boot` mountpoint is on a separate partition. This is the case of RHEL-8.5 and RHEL-9.0 `ami` and `ec2` images. Extend `disk.PartitionTable` with a new `BootPartition` method, which returns a pointer to partition with FS mountpoint `/boot` if there is such partition, or `nil` otherwise. Extend the RHEL-8.5 and RHEL-9.0 code creating options structure for grub2 osbuild stage to include the boot partition in case it has been provided. Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
a9c280a2fc
commit
7ac1d68fb6
5 changed files with 33 additions and 4 deletions
|
|
@ -120,6 +120,23 @@ func (pt PartitionTable) RootPartition() *Partition {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Returns the /boot partition (the partition whose filesystem has /boot as
|
||||
// a mountpoint) of the partition table. Nil is returned if there's no such
|
||||
// partition.
|
||||
func (pt PartitionTable) BootPartition() *Partition {
|
||||
for _, p := range pt.Partitions {
|
||||
if p.Filesystem == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if p.Filesystem.Mountpoint == "/boot" {
|
||||
return &p
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns the index of the boot partition: the partition whose filesystem has
|
||||
// /boot as a mountpoint. If there is no explicit boot partition, the root
|
||||
// partition is returned.
|
||||
|
|
|
|||
|
|
@ -976,7 +976,7 @@ func bootloaderConfigStage(t *imageType, partitionTable disk.PartitionTable, ker
|
|||
kernelOptions := t.kernelOptions
|
||||
uefi := t.supportsUEFI()
|
||||
legacy := t.arch.legacy
|
||||
return osbuild.NewGRUB2Stage(grub2StageOptions(partitionTable.RootPartition(), kernelOptions, kernel, kernelVer, uefi, legacy))
|
||||
return osbuild.NewGRUB2Stage(grub2StageOptions(partitionTable.RootPartition(), partitionTable.BootPartition(), kernelOptions, kernel, kernelVer, uefi, legacy))
|
||||
}
|
||||
|
||||
func bootloaderInstStage(filename string, pt *disk.PartitionTable, arch *architecture, kernelVer string, devices *osbuild.CopyStageDevices, mounts *osbuild.CopyStageMounts, disk *osbuild.Device) *osbuild.Stage {
|
||||
|
|
|
|||
|
|
@ -313,7 +313,8 @@ func xorrisofsStageOptions(filename string, arch string) *osbuild.XorrisofsStage
|
|||
}
|
||||
}
|
||||
|
||||
func grub2StageOptions(rootPartition *disk.Partition, kernelOptions string, kernel *blueprint.KernelCustomization, kernelVer string, uefi bool, legacy string) *osbuild.GRUB2StageOptions {
|
||||
func grub2StageOptions(rootPartition *disk.Partition, bootPartition *disk.Partition, kernelOptions string,
|
||||
kernel *blueprint.KernelCustomization, kernelVer string, uefi bool, legacy string) *osbuild.GRUB2StageOptions {
|
||||
if rootPartition == nil {
|
||||
panic("root partition must be defined for grub2 stage, this is a programming error")
|
||||
}
|
||||
|
|
@ -324,6 +325,11 @@ func grub2StageOptions(rootPartition *disk.Partition, kernelOptions string, kern
|
|||
Legacy: legacy,
|
||||
}
|
||||
|
||||
if bootPartition != nil {
|
||||
bootFsUUID := uuid.MustParse(bootPartition.Filesystem.UUID)
|
||||
stageOptions.BootFilesystemUUID = &bootFsUUID
|
||||
}
|
||||
|
||||
if uefi {
|
||||
stageOptions.UEFI = &osbuild.GRUB2UEFI{
|
||||
Vendor: "redhat",
|
||||
|
|
|
|||
|
|
@ -975,7 +975,7 @@ func bootloaderConfigStage(t *imageType, partitionTable disk.PartitionTable, ker
|
|||
kernelOptions := t.kernelOptions
|
||||
uefi := t.supportsUEFI()
|
||||
legacy := t.arch.legacy
|
||||
return osbuild.NewGRUB2Stage(grub2StageOptions(partitionTable.RootPartition(), kernelOptions, kernel, kernelVer, uefi, legacy))
|
||||
return osbuild.NewGRUB2Stage(grub2StageOptions(partitionTable.RootPartition(), partitionTable.BootPartition(), kernelOptions, kernel, kernelVer, uefi, legacy))
|
||||
}
|
||||
|
||||
func bootloaderInstStage(filename string, pt *disk.PartitionTable, arch *architecture, kernelVer string, devices *osbuild.CopyStageDevices, mounts *osbuild.CopyStageMounts, disk *osbuild.Device) *osbuild.Stage {
|
||||
|
|
|
|||
|
|
@ -313,7 +313,8 @@ func xorrisofsStageOptions(filename string, arch string) *osbuild.XorrisofsStage
|
|||
}
|
||||
}
|
||||
|
||||
func grub2StageOptions(rootPartition *disk.Partition, kernelOptions string, kernel *blueprint.KernelCustomization, kernelVer string, uefi bool, legacy string) *osbuild.GRUB2StageOptions {
|
||||
func grub2StageOptions(rootPartition *disk.Partition, bootPartition *disk.Partition, kernelOptions string,
|
||||
kernel *blueprint.KernelCustomization, kernelVer string, uefi bool, legacy string) *osbuild.GRUB2StageOptions {
|
||||
if rootPartition == nil {
|
||||
panic("root partition must be defined for grub2 stage, this is a programming error")
|
||||
}
|
||||
|
|
@ -324,6 +325,11 @@ func grub2StageOptions(rootPartition *disk.Partition, kernelOptions string, kern
|
|||
Legacy: legacy,
|
||||
}
|
||||
|
||||
if bootPartition != nil {
|
||||
bootFsUUID := uuid.MustParse(bootPartition.Filesystem.UUID)
|
||||
stageOptions.BootFilesystemUUID = &bootFsUUID
|
||||
}
|
||||
|
||||
if uefi {
|
||||
stageOptions.UEFI = &osbuild.GRUB2UEFI{
|
||||
Vendor: "redhat",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue