Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions pkg/bib/osinfo/osinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/osbuild/images/pkg/bib/blueprintload"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/distro"
"github.com/osbuild/images/pkg/osbuild"
)

// XXX: use image-builder instead?
Expand All @@ -41,7 +42,8 @@ type Info struct {
ImageCustomization *blueprint.Customizations
KernelInfo *KernelInfo

PartitionTable *disk.PartitionTable
MountConfiguration *osbuild.MountConfiguration
PartitionTable *disk.PartitionTable
}

func validateOSRelease(osrelease map[string]string) error {
Expand Down Expand Up @@ -131,10 +133,11 @@ func readImageCustomization(root string) (*blueprint.Customizations, error) {
}

type diskYAML struct {
PartitionTable *disk.PartitionTable `json:"partition_table" yaml:"partition_table"`
MountConfiguration *osbuild.MountConfiguration `json:"mount_configuration" yaml:"mount_configuration"`
PartitionTable *disk.PartitionTable `json:"partition_table" yaml:"partition_table"`
}

func readPartitionTable(root string) (*disk.PartitionTable, error) {
func readDiskYaml(root string) (*diskYAML, error) {
p := path.Join(root, bibPathPrefix, "disk.yaml")
var disk diskYAML
f, err := os.Open(p)
Expand All @@ -150,7 +153,7 @@ func readPartitionTable(root string) (*disk.PartitionTable, error) {
return nil, fmt.Errorf("cannot parse disk definitions from %q: %w", p, err)
}

return disk.PartitionTable, nil
return &disk, nil
}

func readKernelInfo(root string) (*KernelInfo, error) {
Expand Down Expand Up @@ -205,10 +208,16 @@ func Load(root string) (*Info, error) {
return nil, err
}

pt, err := readPartitionTable(root)
diskYaml, err := readDiskYaml(root)
if err != nil {
return nil, err
}
var mc *osbuild.MountConfiguration
var pt *disk.PartitionTable
if diskYaml != nil {
mc = diskYaml.MountConfiguration
pt = diskYaml.PartitionTable
}

kernelInfo, err := readKernelInfo(root)
if err != nil {
Expand Down Expand Up @@ -239,6 +248,7 @@ func Load(root string) (*Info, error) {
SELinuxPolicy: selinuxPolicy,
ImageCustomization: customization,
KernelInfo: kernelInfo,
MountConfiguration: mc,
PartitionTable: pt,
}, nil
}
3 changes: 3 additions & 0 deletions pkg/distro/bootc/bootc.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ func (t *BootcImageType) Manifest(bp *blueprint.Blueprint, options distro.ImageO
if t.arch.distro.buildSourceInfo != nil {
img.OSCustomizations.BuildSELinux = t.arch.distro.buildSourceInfo.SELinuxPolicy
}
if t.arch.distro.sourceInfo != nil && t.arch.distro.sourceInfo.MountConfiguration != nil {
img.OSCustomizations.MountConfiguration = *t.arch.distro.sourceInfo.MountConfiguration
}

img.OSCustomizations.KernelOptionsAppend = []string{
"rw",
Expand Down
4 changes: 2 additions & 2 deletions pkg/distro/generic/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ func osCustomizations(t *imageType, osPackageSet rpmmd.PackageSet, options distr
osc.MachineIdUninitialized = *imageConfig.MachineIdUninitialized
}

if imageConfig.MountUnits != nil {
osc.MountUnits = *imageConfig.MountUnits
if imageConfig.MountUnits != nil && *imageConfig.MountUnits {
osc.MountConfiguration = osbuild.MOUNT_CONFIGURATION_UNITS
}

osc.VersionlockPackages = imageConfig.VersionlockPackages
Expand Down
5 changes: 4 additions & 1 deletion pkg/image/bootc_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func NewBootcDiskImage(platform platform.Platform, filename string, container co
Base: NewBase("bootc-raw-image", platform, filename),
ContainerSource: &container,
BuildContainerSource: &buildContainer,
OSCustomizations: manifest.OSCustomizations{
MountConfiguration: osbuild.MOUNT_CONFIGURATION_UNITS, // default use mount units for bootc disk images
},
}
}

Expand Down Expand Up @@ -110,7 +113,7 @@ func (img *BootcDiskImage) InstantiateManifestFromContainers(m *manifest.Manifes
rawImage.Directories = img.OSCustomizations.Directories
rawImage.KernelOptionsAppend = img.OSCustomizations.KernelOptionsAppend
rawImage.SELinux = img.OSCustomizations.SELinux
rawImage.MountUnits = true // always use mount units for bootc disk images
rawImage.MountConfiguration = img.OSCustomizations.MountConfiguration

// In BIB, we export multiple images from the same pipeline so we use the
// filename as the basename for each export and set the extensions based on
Expand Down
13 changes: 10 additions & 3 deletions pkg/manifest/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package manifest

import (
"fmt"

"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/osbuild"
)
Expand All @@ -9,14 +11,19 @@ import (
// collection of org.osbuild.systemd.unit.create stages for .mount and .swap
// units (and an org.osbuild.systemd stage to enable them) depending on the
// pipeline configuration.
func filesystemConfigStages(pt *disk.PartitionTable, mountUnits bool) ([]*osbuild.Stage, error) {
if mountUnits {
func filesystemConfigStages(pt *disk.PartitionTable, mountConfiguration osbuild.MountConfiguration) ([]*osbuild.Stage, error) {
switch mountConfiguration {
case osbuild.MOUNT_CONFIGURATION_UNITS:
return osbuild.GenSystemdMountStages(pt)
} else {
case osbuild.MOUNT_CONFIGURATION_FSTAB:
opts, err := osbuild.NewFSTabStageOptions(pt)
if err != nil {
return nil, err
}
return []*osbuild.Stage{osbuild.NewFSTabStage(opts)}, nil
case osbuild.MOUNT_CONFIGURATION_NONE:
return []*osbuild.Stage{}, nil
default:
panic(fmt.Sprintf("Unexpected mount configuration %d", mountConfiguration))
}
}
10 changes: 5 additions & 5 deletions pkg/manifest/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ type OSCustomizations struct {
// "ConditionFirstBoot" to work in systemd
MachineIdUninitialized bool

// MountUnits creates systemd .mount units to describe the filesystem
// instead of writing to /etc/fstab
MountUnits bool
// What type of mount configuration should we create, systemd units, fstab
// or none
MountConfiguration osbuild.MountConfiguration

// VersionlockPackges uses dnf versionlock to lock a package to the version
// that is installed during image build, preventing it from being updated.
Expand Down Expand Up @@ -738,7 +738,7 @@ func (p *OS) serialize() osbuild.Pipeline {
}

if pt := p.PartitionTable; pt != nil {
rootUUID, kernelOptions, err := osbuild.GenImageKernelOptions(p.PartitionTable, p.OSCustomizations.MountUnits)
rootUUID, kernelOptions, err := osbuild.GenImageKernelOptions(p.PartitionTable, p.OSCustomizations.MountConfiguration)
if err != nil {
panic(err)
}
Expand All @@ -752,7 +752,7 @@ func (p *OS) serialize() osbuild.Pipeline {
}))
}

fsCfgStages, err := filesystemConfigStages(pt, p.OSCustomizations.MountUnits)
fsCfgStages, err := filesystemConfigStages(pt, p.OSCustomizations.MountConfiguration)
if err != nil {
panic(err)
}
Expand Down
23 changes: 20 additions & 3 deletions pkg/manifest/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,19 @@ func checkStagesForMountUnits(t *testing.T, stages []*osbuild.Stage, expectedUni

}

func checkStagesForNoMounts(t *testing.T, stages []*osbuild.Stage) {
fstab := findStage("org.osbuild.fstab", stages)
require.Nil(t, fstab)

systemdStages := findStages("org.osbuild.systemd.unit.create", stages)
require.Nil(t, systemdStages)
}

func TestOSPipelineFStabStage(t *testing.T) {
os := manifest.NewTestOS()

os.PartitionTable = testdisk.MakeFakePartitionTable("/") // PT specifics don't matter
os.OSCustomizations.MountUnits = false // set it explicitly just to be sure
os.PartitionTable = testdisk.MakeFakePartitionTable("/") // PT specifics don't matter
os.OSCustomizations.MountConfiguration = osbuild.MOUNT_CONFIGURATION_FSTAB // set it explicitly just to be sure

checkStagesForFSTab(t, os.Serialize().Stages)
}
Expand All @@ -319,11 +327,20 @@ func TestOSPipelineMountUnitStages(t *testing.T) {

expectedUnits := []string{"-.mount", "home.mount"}
os.PartitionTable = testdisk.MakeFakePartitionTable("/", "/home")
os.OSCustomizations.MountUnits = true
os.OSCustomizations.MountConfiguration = osbuild.MOUNT_CONFIGURATION_UNITS

checkStagesForMountUnits(t, os.Serialize().Stages, expectedUnits)
}

func TestOSPipelineMountNoneStages(t *testing.T) {
Comment thread
mvo5 marked this conversation as resolved.
os := manifest.NewTestOS()

os.PartitionTable = testdisk.MakeFakePartitionTable("/", "/home")
os.OSCustomizations.MountConfiguration = osbuild.MOUNT_CONFIGURATION_NONE

checkStagesForNoMounts(t, os.Serialize().Stages)
}

func TestLanguageIncludesLocaleStage(t *testing.T) {
os := manifest.NewTestOS()

Expand Down
10 changes: 5 additions & 5 deletions pkg/manifest/ostree_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ type OSTreeDeploymentCustomizations struct {
// user options in the build configuration.
LockRoot bool

// MountUnits creates systemd .mount units to describe the filesystem
// instead of writing to /etc/fstab
MountUnits bool
// What type of mount configuration should we create, systemd units, fstab
// or none
MountConfiguration osbuild.MountConfiguration
}

// OSTreeDeployment represents the filesystem tree of a target image based
Expand Down Expand Up @@ -300,7 +300,7 @@ func (p *OSTreeDeployment) serialize() osbuild.Pipeline {
},
},
}))
_, kernelOpts, err := osbuild.GenImageKernelOptions(p.PartitionTable, p.MountUnits)
_, kernelOpts, err := osbuild.GenImageKernelOptions(p.PartitionTable, p.MountConfiguration)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -343,7 +343,7 @@ func (p *OSTreeDeployment) serialize() osbuild.Pipeline {
configStage.MountOSTree(p.osName, ref, 0)
pipeline.AddStage(configStage)

fsCfgStages, err := filesystemConfigStages(p.PartitionTable, p.MountUnits)
fsCfgStages, err := filesystemConfigStages(p.PartitionTable, p.MountConfiguration)
if err != nil {
panic(err)
}
Expand Down
16 changes: 13 additions & 3 deletions pkg/manifest/ostree_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/osbuild/images/internal/testdisk"
"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/manifest"
"github.com/osbuild/images/pkg/osbuild"
"github.com/osbuild/images/pkg/ostree"
"github.com/osbuild/images/pkg/platform"
"github.com/osbuild/images/pkg/rpmmd"
Expand Down Expand Up @@ -45,8 +46,8 @@ func NewTestOSTreeDeployment() *manifest.OSTreeDeployment {
func TestOSTreeDeploymentPipelineFStabStage(t *testing.T) {
pipeline := NewTestOSTreeDeployment()

pipeline.PartitionTable = testdisk.MakeFakePartitionTable("/") // PT specifics don't matter
pipeline.MountUnits = false // set it explicitly just to be sure
pipeline.PartitionTable = testdisk.MakeFakePartitionTable("/") // PT specifics don't matter
pipeline.MountConfiguration = osbuild.MOUNT_CONFIGURATION_FSTAB // set it explicitly just to be sure

checkStagesForFSTab(t, manifest.SerializeWith(pipeline, testCommitInputs()).Stages)
}
Expand All @@ -56,11 +57,20 @@ func TestOSTreeDeploymentPipelineMountUnitStages(t *testing.T) {

expectedUnits := []string{"-.mount", "home.mount"}
pipeline.PartitionTable = testdisk.MakeFakePartitionTable("/", "/home")
pipeline.MountUnits = true
pipeline.MountConfiguration = osbuild.MOUNT_CONFIGURATION_UNITS

checkStagesForMountUnits(t, manifest.SerializeWith(pipeline, testCommitInputs()).Stages, expectedUnits)
}

func TestOSTreeDeploymentPipelineNoMountUnitStages(t *testing.T) {
pipeline := NewTestOSTreeDeployment()

pipeline.PartitionTable = testdisk.MakeFakePartitionTable("/", "/home")
pipeline.MountConfiguration = osbuild.MOUNT_CONFIGURATION_NONE

checkStagesForNoMounts(t, manifest.SerializeWith(pipeline, testCommitInputs()).Stages)
}

func TestAddInlineOSTreeDeployment(t *testing.T) {
deployment := NewTestOSTreeDeployment()

Expand Down
8 changes: 4 additions & 4 deletions pkg/manifest/raw_bootc.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type RawBootcImage struct {
// selected profile
SELinux string

// MountUnits creates systemd .mount units to describe the filesystem
// instead of writing to /etc/fstab
MountUnits bool
// What type of mount configuration should we create, systemd units, fstab
// or none
MountConfiguration osbuild.MountConfiguration

// Source pipeline for files written to raw partitions
SourcePipeline string
Expand Down Expand Up @@ -176,7 +176,7 @@ func (p *RawBootcImage) serialize() osbuild.Pipeline {
mounts = append(mounts, *osbuild.NewOSTreeDeploymentMountDefault("ostree.deployment", osbuild.OSTreeMountSourceMount))
mounts = append(mounts, *osbuild.NewBindMount("bind-ostree-deployment-to-tree", "mount://", "tree://"))

fsCfgStages, err := filesystemConfigStages(pt, p.MountUnits)
fsCfgStages, err := filesystemConfigStages(pt, p.MountConfiguration)
if err != nil {
panic(err)
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/manifest/raw_bootc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func TestRawBootcPipelineFSTabStage(t *testing.T) {
pipeline := makeFakeRawBootcPipeline()

pipeline.PartitionTable = testdisk.MakeFakePartitionTable("/", "/boot/efi") // PT requires /boot/efi
pipeline.MountUnits = false // set it explicitly just to be sure
pipeline.MountConfiguration = osbuild.MOUNT_CONFIGURATION_FSTAB // set it explicitly just to be sure

checkStagesForFSTab(t, pipeline.Serialize().Stages)
}
Expand All @@ -358,7 +358,16 @@ func TestRawBootcPipelineMountUnitStages(t *testing.T) {

expectedUnits := []string{"-.mount", "home.mount", "boot-efi.mount"}
pipeline.PartitionTable = testdisk.MakeFakePartitionTable("/", "/home", "/boot/efi")
pipeline.MountUnits = true
pipeline.MountConfiguration = osbuild.MOUNT_CONFIGURATION_UNITS

checkStagesForMountUnits(t, pipeline.Serialize().Stages, expectedUnits)
}

func TestRawBootcPipelineNoMountsStages(t *testing.T) {
pipeline := makeFakeRawBootcPipeline()

pipeline.PartitionTable = testdisk.MakeFakePartitionTable("/", "/home", "/boot/efi")
pipeline.MountConfiguration = osbuild.MOUNT_CONFIGURATION_NONE

checkStagesForNoMounts(t, pipeline.Serialize().Stages)
}
Loading
Loading