osbuild2: deduplicate ziplInstStageOptions()
Use single NewZiplInstStageOptions() from osbuild2 instead of implementing in each distro.
This commit is contained in:
parent
890f380384
commit
6b3802739b
9 changed files with 40 additions and 52 deletions
|
|
@ -1291,7 +1291,7 @@ func bootloaderInstStage(filename string, pt *disk.PartitionTable, arch *archite
|
|||
}
|
||||
|
||||
if arch.name == distro.S390xArchName {
|
||||
return osbuild.NewZiplInstStage(ziplInstStageOptions(kernelVer, pt), disk, devices, mounts)
|
||||
return osbuild.NewZiplInstStage(osbuild.NewZiplInstStageOptions(kernelVer, pt), disk, devices, mounts)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -349,18 +349,6 @@ func sfdiskStageOptions(pt *disk.PartitionTable) *osbuild.SfdiskStageOptions {
|
|||
return stageOptions
|
||||
}
|
||||
|
||||
func ziplInstStageOptions(kernel string, pt *disk.PartitionTable) *osbuild.ZiplInstStageOptions {
|
||||
bootPartIndex := pt.BootPartitionIndex()
|
||||
if bootPartIndex == -1 {
|
||||
panic("failed to find boot or root partition for zipl.inst stage")
|
||||
}
|
||||
|
||||
return &osbuild.ZiplInstStageOptions{
|
||||
Kernel: kernel,
|
||||
Location: pt.BytesToSectors(pt.Partitions[bootPartIndex].Start),
|
||||
}
|
||||
}
|
||||
|
||||
func qemuStageOptions(filename, format, compat string) *osbuild.QEMUStageOptions {
|
||||
var options osbuild.QEMUFormatOptions
|
||||
switch format {
|
||||
|
|
|
|||
|
|
@ -1015,7 +1015,7 @@ func bootloaderInstStage(filename string, pt *disk.PartitionTable, arch *archite
|
|||
}
|
||||
|
||||
if arch.name == distro.S390xArchName {
|
||||
return osbuild.NewZiplInstStage(ziplInstStageOptions(kernelVer, pt), disk, devices, mounts)
|
||||
return osbuild.NewZiplInstStage(osbuild.NewZiplInstStageOptions(kernelVer, pt), disk, devices, mounts)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -383,18 +383,6 @@ func sfdiskStageOptions(pt *disk.PartitionTable) *osbuild.SfdiskStageOptions {
|
|||
return stageOptions
|
||||
}
|
||||
|
||||
func ziplInstStageOptions(kernel string, pt *disk.PartitionTable) *osbuild.ZiplInstStageOptions {
|
||||
bootPartIndex := pt.BootPartitionIndex()
|
||||
if bootPartIndex == -1 {
|
||||
panic("failed to find boot or root partition for zipl.inst stage")
|
||||
}
|
||||
|
||||
return &osbuild.ZiplInstStageOptions{
|
||||
Kernel: kernel,
|
||||
Location: pt.BytesToSectors(pt.Partitions[bootPartIndex].Start),
|
||||
}
|
||||
}
|
||||
|
||||
func qemuStageOptions(filename, format, compat string) *osbuild.QEMUStageOptions {
|
||||
var options osbuild.QEMUFormatOptions
|
||||
switch format {
|
||||
|
|
|
|||
|
|
@ -1004,7 +1004,7 @@ func bootloaderInstStage(filename string, pt *disk.PartitionTable, arch *archite
|
|||
}
|
||||
|
||||
if arch.name == distro.S390xArchName {
|
||||
return osbuild.NewZiplInstStage(ziplInstStageOptions(kernelVer, pt), disk, devices, mounts)
|
||||
return osbuild.NewZiplInstStage(osbuild.NewZiplInstStageOptions(kernelVer, pt), disk, devices, mounts)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -383,18 +383,6 @@ func sfdiskStageOptions(pt *disk.PartitionTable) *osbuild.SfdiskStageOptions {
|
|||
return stageOptions
|
||||
}
|
||||
|
||||
func ziplInstStageOptions(kernel string, pt *disk.PartitionTable) *osbuild.ZiplInstStageOptions {
|
||||
bootPartIndex := pt.BootPartitionIndex()
|
||||
if bootPartIndex == -1 {
|
||||
panic("failed to find boot or root partition for zipl.inst stage")
|
||||
}
|
||||
|
||||
return &osbuild.ZiplInstStageOptions{
|
||||
Kernel: kernel,
|
||||
Location: pt.BytesToSectors(pt.Partitions[bootPartIndex].Start),
|
||||
}
|
||||
}
|
||||
|
||||
func qemuStageOptions(filename, format, compat string) *osbuild.QEMUStageOptions {
|
||||
var options osbuild.QEMUFormatOptions
|
||||
switch format {
|
||||
|
|
|
|||
|
|
@ -1091,7 +1091,7 @@ func bootloaderInstStage(filename string, pt *disk.PartitionTable, arch *archite
|
|||
}
|
||||
|
||||
if arch.name == distro.S390xArchName {
|
||||
return osbuild.NewZiplInstStage(ziplInstStageOptions(kernelVer, pt), disk, devices, mounts)
|
||||
return osbuild.NewZiplInstStage(osbuild.NewZiplInstStageOptions(kernelVer, pt), disk, devices, mounts)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -328,18 +328,6 @@ func sfdiskStageOptions(pt *disk.PartitionTable) *osbuild.SfdiskStageOptions {
|
|||
return stageOptions
|
||||
}
|
||||
|
||||
func ziplInstStageOptions(kernel string, pt *disk.PartitionTable) *osbuild.ZiplInstStageOptions {
|
||||
bootPartIndex := pt.BootPartitionIndex()
|
||||
if bootPartIndex == -1 {
|
||||
panic("failed to find boot or root partition for zipl.inst stage")
|
||||
}
|
||||
|
||||
return &osbuild.ZiplInstStageOptions{
|
||||
Kernel: kernel,
|
||||
Location: pt.BytesToSectors(pt.Partitions[bootPartIndex].Start),
|
||||
}
|
||||
}
|
||||
|
||||
func qemuStageOptions(filename, format, compat string) *osbuild.QEMUStageOptions {
|
||||
var options osbuild.QEMUFormatOptions
|
||||
switch format {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package osbuild2
|
||||
|
||||
import "github.com/osbuild/osbuild-composer/internal/disk"
|
||||
|
||||
// Install the Z Initial Program Loader
|
||||
|
||||
type ZiplInstStageOptions struct {
|
||||
|
|
@ -27,3 +29,37 @@ func NewZiplInstStage(options *ZiplInstStageOptions, disk *Device, devices *Devi
|
|||
Mounts: *mounts,
|
||||
}
|
||||
}
|
||||
|
||||
func NewZiplInstStageOptions(kernel string, pt *disk.PartitionTable) *ZiplInstStageOptions {
|
||||
bootIdx := -1
|
||||
rootIdx := -1
|
||||
for idx := range pt.Partitions {
|
||||
// NOTE: we only support having /boot at the top level of the partition
|
||||
// table (e.g., not in LUKS or LVM), so we don't need to descend into
|
||||
// VolumeContainer types. If /boot is on the root partition, then the
|
||||
// root partition needs to be at the top level.
|
||||
partition := &pt.Partitions[idx]
|
||||
if partition.Payload == nil {
|
||||
continue
|
||||
}
|
||||
if partition.Payload.GetMountpoint() == "/boot" {
|
||||
bootIdx = idx
|
||||
} else if partition.Payload.GetMountpoint() == "/" {
|
||||
rootIdx = idx
|
||||
}
|
||||
}
|
||||
if bootIdx == -1 {
|
||||
// if there's no boot partition, fall back to root
|
||||
if rootIdx == -1 {
|
||||
// no root either!?
|
||||
panic("failed to find boot or root partition for zipl.inst stage")
|
||||
}
|
||||
bootIdx = rootIdx
|
||||
}
|
||||
|
||||
bootPart := pt.Partitions[bootIdx]
|
||||
return &ZiplInstStageOptions{
|
||||
Kernel: kernel,
|
||||
Location: pt.BytesToSectors(bootPart.Start),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue