disk: create file system accessors and use those
In various places we are interested in the root and boot file- systems. Currently those were accessed via by retrieving the partition that contain them and the accessing the filesystem member. Add accessors to `PartitionTable` that directly return the needed filesystem. This will help if the file system is stored inside a container like LVM or LUKS instead of directly on a partition.
This commit is contained in:
parent
d589317dcb
commit
c8efc7d282
10 changed files with 73 additions and 47 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue