diff --git a/internal/disk/disk.go b/internal/disk/disk.go index 50689c466..79fcb28d3 100644 --- a/internal/disk/disk.go +++ b/internal/disk/disk.go @@ -170,6 +170,32 @@ func (pt PartitionTable) RootPartitionIndex() int { return rootIdx } +// Returns the Filesystem instance for a given mountpoint, if it exists. +func (pt PartitionTable) FindFilesystemForMountpoint(mountpoint string) *Filesystem { + for _, part := range pt.Partitions { + if part.Filesystem == nil { + continue + } + if part.Filesystem.Mountpoint == mountpoint { + return part.Filesystem + } + } + return nil +} + +// Returns the Filesystem instance that corresponds to the root +// filesystem, i.e. the filesystem whose mountpoint is '/'. +func (pt PartitionTable) RootFilesystem() *Filesystem { + return pt.FindFilesystemForMountpoint("/") +} + +// Returns the Filesystem instance that corresponds to the boot +// filesystem, i.e. the filesystem whose mountpoint is '/boot', +// if /boot is on a separate partition, otherwise nil +func (pt PartitionTable) BootFilesystem() *Filesystem { + return pt.FindFilesystemForMountpoint("/boot") +} + // dynamically calculate and update the start point // for each of the existing partitions // return the updated start point diff --git a/internal/distro/rhel84/distro.go b/internal/distro/rhel84/distro.go index 23d5387a1..9953be6cd 100644 --- a/internal/distro/rhel84/distro.go +++ b/internal/distro/rhel84/distro.go @@ -392,13 +392,13 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp 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") + rootFs := pt.RootFilesystem() + if rootFs == nil { + panic("s390x image must have a root filesystem, this is a programming error") } p.AddStage(osbuild.NewKernelCmdlineStage(&osbuild.KernelCmdlineStageOptions{ - RootFsUUID: rootPartition.Filesystem.UUID, + RootFsUUID: rootFs.UUID, KernelOpts: t.kernelOptions, })) } @@ -636,13 +636,13 @@ func (t *imageType) grub2StageOptions(pt *disk.PartitionTable, kernelOptions str 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") + rootFs := pt.RootFilesystem() + if rootFs == nil { + panic("root filesystem must be defined for grub2 stage, this is a programming error") } stageOptions := osbuild.GRUB2StageOptions{ - RootFilesystemUUID: uuid.MustParse(rootPartition.Filesystem.UUID), + RootFilesystemUUID: uuid.MustParse(rootFs.UUID), KernelOptions: kernelOptions, Legacy: legacy, } diff --git a/internal/distro/rhel85/pipelines.go b/internal/distro/rhel85/pipelines.go index 05c778827..226768e33 100644 --- a/internal/distro/rhel85/pipelines.go +++ b/internal/distro/rhel85/pipelines.go @@ -64,11 +64,11 @@ func qcow2Pipelines(t *imageType, customizations *blueprint.Customizations, opti func prependKernelCmdlineStage(pipeline *osbuild.Pipeline, t *imageType, pt *disk.PartitionTable) *osbuild.Pipeline { if t.arch.name == distro.S390xArchName { - rootPartition := pt.RootPartition() - if rootPartition == nil { - panic("s390x image must have a root partition, this is a programming error") + rootFs := pt.RootFilesystem() + if rootFs == nil { + panic("s390x image must have a root filesystem, this is a programming error") } - kernelStage := osbuild.NewKernelCmdlineStage(osbuild.NewKernelCmdlineStageOptions(rootPartition.Filesystem.UUID, t.kernelOptions)) + kernelStage := osbuild.NewKernelCmdlineStage(osbuild.NewKernelCmdlineStageOptions(rootFs.UUID, t.kernelOptions)) pipeline.Stages = append([]*osbuild.Stage{kernelStage}, pipeline.Stages...) } return pipeline @@ -1330,7 +1330,7 @@ func bootloaderConfigStage(t *imageType, partitionTable disk.PartitionTable, ker uefi := t.supportsUEFI() legacy := t.arch.legacy - options := grub2StageOptions(partitionTable.RootPartition(), partitionTable.BootPartition(), kernelOptions, kernel, kernelVer, uefi, legacy, install) + options := grub2StageOptions(partitionTable.RootFilesystem(), partitionTable.BootFilesystem(), kernelOptions, kernel, kernelVer, uefi, legacy, install) options.Greenboot = greenboot return osbuild.NewGRUB2Stage(options) diff --git a/internal/distro/rhel85/stage_options.go b/internal/distro/rhel85/stage_options.go index 90d876f27..1953b8b1c 100644 --- a/internal/distro/rhel85/stage_options.go +++ b/internal/distro/rhel85/stage_options.go @@ -330,20 +330,20 @@ func xorrisofsStageOptions(filename string, arch string, isolinux bool) *osbuild return options } -func grub2StageOptions(rootPartition *disk.Partition, bootPartition *disk.Partition, kernelOptions string, +func grub2StageOptions(rootFs *disk.Filesystem, bootFs *disk.Filesystem, kernelOptions string, kernel *blueprint.KernelCustomization, kernelVer string, uefi bool, legacy string, install bool) *osbuild.GRUB2StageOptions { - if rootPartition == nil { - panic("root partition must be defined for grub2 stage, this is a programming error") + if rootFs == nil { + panic("root filesystem must be defined for grub2 stage, this is a programming error") } stageOptions := osbuild.GRUB2StageOptions{ - RootFilesystemUUID: uuid.MustParse(rootPartition.Filesystem.UUID), + RootFilesystemUUID: uuid.MustParse(rootFs.UUID), KernelOptions: kernelOptions, Legacy: legacy, } - if bootPartition != nil { - bootFsUUID := uuid.MustParse(bootPartition.Filesystem.UUID) + if bootFs != nil { + bootFsUUID := uuid.MustParse(bootFs.UUID) stageOptions.BootFilesystemUUID = &bootFsUUID } diff --git a/internal/distro/rhel86/pipelines.go b/internal/distro/rhel86/pipelines.go index 02521de8a..b50e690de 100644 --- a/internal/distro/rhel86/pipelines.go +++ b/internal/distro/rhel86/pipelines.go @@ -43,11 +43,11 @@ func qcow2Pipelines(t *imageType, customizations *blueprint.Customizations, opti func prependKernelCmdlineStage(pipeline *osbuild.Pipeline, t *imageType, pt *disk.PartitionTable) *osbuild.Pipeline { if t.arch.name == distro.S390xArchName { - rootPartition := pt.RootPartition() - if rootPartition == nil { - panic("s390x image must have a root partition, this is a programming error") + rootFs := pt.RootFilesystem() + if rootFs == nil { + panic("s390x image must have a root filesystem, this is a programming error") } - kernelStage := osbuild.NewKernelCmdlineStage(osbuild.NewKernelCmdlineStageOptions(rootPartition.Filesystem.UUID, t.kernelOptions)) + kernelStage := osbuild.NewKernelCmdlineStage(osbuild.NewKernelCmdlineStageOptions(rootFs.UUID, t.kernelOptions)) pipeline.Stages = append([]*osbuild.Stage{kernelStage}, pipeline.Stages...) } return pipeline @@ -1053,7 +1053,7 @@ func bootloaderConfigStage(t *imageType, partitionTable disk.PartitionTable, ker uefi := t.supportsUEFI() legacy := t.arch.legacy - options := grub2StageOptions(partitionTable.RootPartition(), partitionTable.BootPartition(), kernelOptions, kernel, kernelVer, uefi, legacy, t.arch.distro.vendor, install) + options := grub2StageOptions(partitionTable.RootFilesystem(), partitionTable.BootFilesystem(), kernelOptions, kernel, kernelVer, uefi, legacy, t.arch.distro.vendor, install) options.Greenboot = greenboot return osbuild.NewGRUB2Stage(options) diff --git a/internal/distro/rhel86/stage_options.go b/internal/distro/rhel86/stage_options.go index aa2d8c9c0..3e24f762f 100644 --- a/internal/distro/rhel86/stage_options.go +++ b/internal/distro/rhel86/stage_options.go @@ -364,8 +364,8 @@ func xorrisofsStageOptions(filename, isolabel, arch string, isolinux bool) *osbu return options } -func grub2StageOptions(rootPartition *disk.Partition, - bootPartition *disk.Partition, +func grub2StageOptions(rootFs *disk.Filesystem, + bootFs *disk.Filesystem, kernelOptions string, kernel *blueprint.KernelCustomization, kernelVer string, @@ -373,18 +373,18 @@ func grub2StageOptions(rootPartition *disk.Partition, legacy string, vendor string, install bool) *osbuild.GRUB2StageOptions { - if rootPartition == nil { + if rootFs == nil { panic("root partition must be defined for grub2 stage, this is a programming error") } stageOptions := osbuild.GRUB2StageOptions{ - RootFilesystemUUID: uuid.MustParse(rootPartition.Filesystem.UUID), + RootFilesystemUUID: uuid.MustParse(rootFs.UUID), KernelOptions: kernelOptions, Legacy: legacy, } - if bootPartition != nil { - bootFsUUID := uuid.MustParse(bootPartition.Filesystem.UUID) + if bootFs != nil { + bootFsUUID := uuid.MustParse(bootFs.UUID) stageOptions.BootFilesystemUUID = &bootFsUUID } diff --git a/internal/distro/rhel90/pipelines.go b/internal/distro/rhel90/pipelines.go index bc46e9a56..503924e96 100644 --- a/internal/distro/rhel90/pipelines.go +++ b/internal/distro/rhel90/pipelines.go @@ -42,7 +42,7 @@ func qcow2Pipelines(t *imageType, customizations *blueprint.Customizations, opti } func prependKernelCmdlineStage(pipeline *osbuild.Pipeline, t *imageType, pt *disk.PartitionTable) *osbuild.Pipeline { - rootFsUUID := pt.RootPartition().Filesystem.UUID + rootFsUUID := pt.RootFilesystem().UUID kernelStage := osbuild.NewKernelCmdlineStage(osbuild.NewKernelCmdlineStageOptions(rootFsUUID, t.kernelOptions)) pipeline.Stages = append([]*osbuild.Stage{kernelStage}, pipeline.Stages...) return pipeline @@ -1050,7 +1050,7 @@ func bootloaderConfigStage(t *imageType, partitionTable disk.PartitionTable, ker uefi := t.supportsUEFI() legacy := t.arch.legacy - options := grub2StageOptions(partitionTable.RootPartition(), partitionTable.BootPartition(), kernelOptions, kernel, kernelVer, uefi, legacy, t.arch.distro.vendor, install) + options := grub2StageOptions(partitionTable.RootFilesystem(), partitionTable.BootFilesystem(), kernelOptions, kernel, kernelVer, uefi, legacy, t.arch.distro.vendor, install) options.Greenboot = greenboot return osbuild.NewGRUB2Stage(options) diff --git a/internal/distro/rhel90/stage_options.go b/internal/distro/rhel90/stage_options.go index 9095b4bec..a018606ec 100644 --- a/internal/distro/rhel90/stage_options.go +++ b/internal/distro/rhel90/stage_options.go @@ -364,8 +364,8 @@ func xorrisofsStageOptions(filename, isolabel, arch string, isolinux bool) *osbu return options } -func grub2StageOptions(rootPartition *disk.Partition, - bootPartition *disk.Partition, +func grub2StageOptions(rootFs *disk.Filesystem, + bootFs *disk.Filesystem, kernelOptions string, kernel *blueprint.KernelCustomization, kernelVer string, @@ -373,18 +373,18 @@ func grub2StageOptions(rootPartition *disk.Partition, legacy string, vendor string, install bool) *osbuild.GRUB2StageOptions { - if rootPartition == nil { - panic("root partition must be defined for grub2 stage, this is a programming error") + if rootFs == nil { + panic("root filesystem must be defined for grub2 stage, this is a programming error") } stageOptions := osbuild.GRUB2StageOptions{ - RootFilesystemUUID: uuid.MustParse(rootPartition.Filesystem.UUID), + RootFilesystemUUID: uuid.MustParse(rootFs.UUID), KernelOptions: kernelOptions, Legacy: legacy, } - if bootPartition != nil { - bootFsUUID := uuid.MustParse(bootPartition.Filesystem.UUID) + if bootFs != nil { + bootFsUUID := uuid.MustParse(bootFs.UUID) stageOptions.BootFilesystemUUID = &bootFsUUID } diff --git a/internal/distro/rhel90beta/pipelines.go b/internal/distro/rhel90beta/pipelines.go index f9d95338f..280342ddd 100644 --- a/internal/distro/rhel90beta/pipelines.go +++ b/internal/distro/rhel90beta/pipelines.go @@ -59,7 +59,7 @@ func qcow2Pipelines(t *imageType, customizations *blueprint.Customizations, opti } func prependKernelCmdlineStage(pipeline *osbuild.Pipeline, t *imageType, pt *disk.PartitionTable) *osbuild.Pipeline { - rootFsUUID := pt.RootPartition().Filesystem.UUID + rootFsUUID := pt.RootFilesystem().UUID kernelStage := osbuild.NewKernelCmdlineStage(osbuild.NewKernelCmdlineStageOptions(rootFsUUID, t.kernelOptions)) pipeline.Stages = append([]*osbuild.Stage{kernelStage}, pipeline.Stages...) return pipeline @@ -1139,7 +1139,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(), partitionTable.BootPartition(), kernelOptions, kernel, kernelVer, uefi, legacy)) + return osbuild.NewGRUB2Stage(grub2StageOptions(partitionTable.RootFilesystem(), partitionTable.BootFilesystem(), kernelOptions, kernel, kernelVer, uefi, legacy)) } func bootloaderInstStage(filename string, pt *disk.PartitionTable, arch *architecture, kernelVer string, devices *osbuild.Devices, mounts *osbuild.Mounts, disk *osbuild.Device) *osbuild.Stage { diff --git a/internal/distro/rhel90beta/stage_options.go b/internal/distro/rhel90beta/stage_options.go index 9da2960c6..f4b014c94 100644 --- a/internal/distro/rhel90beta/stage_options.go +++ b/internal/distro/rhel90beta/stage_options.go @@ -309,20 +309,20 @@ func xorrisofsStageOptions(filename string, arch string) *osbuild.XorrisofsStage } } -func grub2StageOptions(rootPartition *disk.Partition, bootPartition *disk.Partition, kernelOptions string, +func grub2StageOptions(rootFs *disk.Filesystem, bootFs *disk.Filesystem, 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") + if rootFs == nil { + panic("root filesystem must be defined for grub2 stage, this is a programming error") } stageOptions := osbuild.GRUB2StageOptions{ - RootFilesystemUUID: uuid.MustParse(rootPartition.Filesystem.UUID), + RootFilesystemUUID: uuid.MustParse(rootFs.UUID), KernelOptions: kernelOptions, Legacy: legacy, } - if bootPartition != nil { - bootFsUUID := uuid.MustParse(bootPartition.Filesystem.UUID) + if bootFs != nil { + bootFsUUID := uuid.MustParse(bootFs.UUID) stageOptions.BootFilesystemUUID = &bootFsUUID }