Skip to content

Commit 1739457

Browse files
committed
Support setting what type of mount configuration to set in disk.yaml
This extends the current internal boolean mountUnits options to an enum that also allows to disable both fstab and mount units. Additionally, it also adds the option "mount_configuration" to the bootc disk.yaml embedded config file, allowing bootc images to configure this. For now, distro.ImageConfig still has MountUnits, because changing that would break the yaml format. However, this could be changed in the future. MOUNT_CONFIGURATION_FSTAB has value 0, to make the default match the default for a mountUnit boolean (i.e. false). Note: The previous MountUnits option also affected the generated kernel config options in some cases. We do the same now even if the option is set to none.
1 parent 501cba3 commit 1739457

13 files changed

Lines changed: 160 additions & 46 deletions

File tree

pkg/bib/osinfo/osinfo.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/osbuild/images/pkg/bib/blueprintload"
1616
"github.com/osbuild/images/pkg/disk"
1717
"github.com/osbuild/images/pkg/distro"
18+
"github.com/osbuild/images/pkg/osbuild"
1819
)
1920

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

44-
PartitionTable *disk.PartitionTable
45+
MountConfiguration *osbuild.MountConfiguration
46+
PartitionTable *disk.PartitionTable
4547
}
4648

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

133135
type diskYAML struct {
134-
PartitionTable *disk.PartitionTable `json:"partition_table" yaml:"partition_table"`
136+
MountConfiguration *osbuild.MountConfiguration `json:"mount_configuration" yaml:"mount_configuration"`
137+
PartitionTable *disk.PartitionTable `json:"partition_table" yaml:"partition_table"`
135138
}
136139

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

153-
return disk.PartitionTable, nil
156+
return &disk, nil
154157
}
155158

156159
func readKernelInfo(root string) (*KernelInfo, error) {
@@ -205,10 +208,16 @@ func Load(root string) (*Info, error) {
205208
return nil, err
206209
}
207210

208-
pt, err := readPartitionTable(root)
211+
diskYaml, err := readDiskYaml(root)
209212
if err != nil {
210213
return nil, err
211214
}
215+
var mc *osbuild.MountConfiguration
216+
var pt *disk.PartitionTable
217+
if diskYaml != nil {
218+
mc = diskYaml.MountConfiguration
219+
pt = diskYaml.PartitionTable
220+
}
212221

213222
kernelInfo, err := readKernelInfo(root)
214223
if err != nil {
@@ -239,6 +248,7 @@ func Load(root string) (*Info, error) {
239248
SELinuxPolicy: selinuxPolicy,
240249
ImageCustomization: customization,
241250
KernelInfo: kernelInfo,
251+
MountConfiguration: mc,
242252
PartitionTable: pt,
243253
}, nil
244254
}

pkg/distro/bootc/bootc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ func (t *BootcImageType) Manifest(bp *blueprint.Blueprint, options distro.ImageO
313313
if t.arch.distro.buildSourceInfo != nil {
314314
img.OSCustomizations.BuildSELinux = t.arch.distro.buildSourceInfo.SELinuxPolicy
315315
}
316+
if t.arch.distro.sourceInfo != nil && t.arch.distro.sourceInfo.MountConfiguration != nil {
317+
img.OSCustomizations.MountConfiguration = *t.arch.distro.sourceInfo.MountConfiguration
318+
}
316319

317320
img.OSCustomizations.KernelOptionsAppend = []string{
318321
"rw",

pkg/distro/generic/images.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ func osCustomizations(t *imageType, osPackageSet rpmmd.PackageSet, options distr
318318
osc.MachineIdUninitialized = *imageConfig.MachineIdUninitialized
319319
}
320320

321-
if imageConfig.MountUnits != nil {
322-
osc.MountUnits = *imageConfig.MountUnits
321+
if imageConfig.MountUnits != nil && *imageConfig.MountUnits {
322+
osc.MountConfiguration = osbuild.MOUNT_CONFIGURATION_UNITS
323323
}
324324

325325
osc.VersionlockPackages = imageConfig.VersionlockPackages

pkg/image/bootc_disk.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func NewBootcDiskImage(platform platform.Platform, filename string, container co
3030
Base: NewBase("bootc-raw-image", platform, filename),
3131
ContainerSource: &container,
3232
BuildContainerSource: &buildContainer,
33+
OSCustomizations: manifest.OSCustomizations{
34+
MountConfiguration: osbuild.MOUNT_CONFIGURATION_UNITS, // default use mount units for bootc disk images
35+
},
3336
}
3437
}
3538

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

115118
// In BIB, we export multiple images from the same pipeline so we use the
116119
// filename as the basename for each export and set the extensions based on

pkg/manifest/common.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package manifest
22

33
import (
4+
"fmt"
5+
46
"github.com/osbuild/images/pkg/disk"
57
"github.com/osbuild/images/pkg/osbuild"
68
)
@@ -9,14 +11,19 @@ import (
911
// collection of org.osbuild.systemd.unit.create stages for .mount and .swap
1012
// units (and an org.osbuild.systemd stage to enable them) depending on the
1113
// pipeline configuration.
12-
func filesystemConfigStages(pt *disk.PartitionTable, mountUnits bool) ([]*osbuild.Stage, error) {
13-
if mountUnits {
14+
func filesystemConfigStages(pt *disk.PartitionTable, mountConfiguration osbuild.MountConfiguration) ([]*osbuild.Stage, error) {
15+
switch mountConfiguration {
16+
case osbuild.MOUNT_CONFIGURATION_UNITS:
1417
return osbuild.GenSystemdMountStages(pt)
15-
} else {
18+
case osbuild.MOUNT_CONFIGURATION_FSTAB:
1619
opts, err := osbuild.NewFSTabStageOptions(pt)
1720
if err != nil {
1821
return nil, err
1922
}
2023
return []*osbuild.Stage{osbuild.NewFSTabStage(opts)}, nil
24+
case osbuild.MOUNT_CONFIGURATION_NONE:
25+
return []*osbuild.Stage{}, nil
26+
default:
27+
panic(fmt.Sprintf("Unexpected mount configuration %d", mountConfiguration))
2128
}
2229
}

pkg/manifest/os.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ type OSCustomizations struct {
182182
// "ConditionFirstBoot" to work in systemd
183183
MachineIdUninitialized bool
184184

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

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

740740
if pt := p.PartitionTable; pt != nil {
741-
rootUUID, kernelOptions, err := osbuild.GenImageKernelOptions(p.PartitionTable, p.OSCustomizations.MountUnits)
741+
rootUUID, kernelOptions, err := osbuild.GenImageKernelOptions(p.PartitionTable, p.OSCustomizations.MountConfiguration)
742742
if err != nil {
743743
panic(err)
744744
}
@@ -752,7 +752,7 @@ func (p *OS) serialize() osbuild.Pipeline {
752752
}))
753753
}
754754

755-
fsCfgStages, err := filesystemConfigStages(pt, p.OSCustomizations.MountUnits)
755+
fsCfgStages, err := filesystemConfigStages(pt, p.OSCustomizations.MountConfiguration)
756756
if err != nil {
757757
panic(err)
758758
}

pkg/manifest/os_test.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,19 @@ func checkStagesForMountUnits(t *testing.T, stages []*osbuild.Stage, expectedUni
305305

306306
}
307307

308+
func checkStagesForNoMounts(t *testing.T, stages []*osbuild.Stage) {
309+
fstab := findStage("org.osbuild.fstab", stages)
310+
require.Nil(t, fstab)
311+
312+
systemdStages := findStages("org.osbuild.systemd.unit.create", stages)
313+
require.Nil(t, systemdStages)
314+
}
315+
308316
func TestOSPipelineFStabStage(t *testing.T) {
309317
os := manifest.NewTestOS()
310318

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

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

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

324332
checkStagesForMountUnits(t, os.Serialize().Stages, expectedUnits)
325333
}
326334

335+
func TestOSPipelineMountNoneStages(t *testing.T) {
336+
os := manifest.NewTestOS()
337+
338+
os.PartitionTable = testdisk.MakeFakePartitionTable("/", "/home")
339+
os.OSCustomizations.MountConfiguration = osbuild.MOUNT_CONFIGURATION_NONE
340+
341+
checkStagesForNoMounts(t, os.Serialize().Stages)
342+
}
343+
327344
func TestLanguageIncludesLocaleStage(t *testing.T) {
328345
os := manifest.NewTestOS()
329346

pkg/manifest/ostree_deployment.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ type OSTreeDeploymentCustomizations struct {
4343
// user options in the build configuration.
4444
LockRoot bool
4545

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

5151
// OSTreeDeployment represents the filesystem tree of a target image based
@@ -300,7 +300,7 @@ func (p *OSTreeDeployment) serialize() osbuild.Pipeline {
300300
},
301301
},
302302
}))
303-
_, kernelOpts, err := osbuild.GenImageKernelOptions(p.PartitionTable, p.MountUnits)
303+
_, kernelOpts, err := osbuild.GenImageKernelOptions(p.PartitionTable, p.MountConfiguration)
304304
if err != nil {
305305
panic(err)
306306
}
@@ -343,7 +343,7 @@ func (p *OSTreeDeployment) serialize() osbuild.Pipeline {
343343
configStage.MountOSTree(p.osName, ref, 0)
344344
pipeline.AddStage(configStage)
345345

346-
fsCfgStages, err := filesystemConfigStages(p.PartitionTable, p.MountUnits)
346+
fsCfgStages, err := filesystemConfigStages(p.PartitionTable, p.MountConfiguration)
347347
if err != nil {
348348
panic(err)
349349
}

pkg/manifest/ostree_deployment_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/osbuild/images/internal/testdisk"
99
"github.com/osbuild/images/pkg/arch"
1010
"github.com/osbuild/images/pkg/manifest"
11+
"github.com/osbuild/images/pkg/osbuild"
1112
"github.com/osbuild/images/pkg/ostree"
1213
"github.com/osbuild/images/pkg/platform"
1314
"github.com/osbuild/images/pkg/rpmmd"
@@ -45,8 +46,8 @@ func NewTestOSTreeDeployment() *manifest.OSTreeDeployment {
4546
func TestOSTreeDeploymentPipelineFStabStage(t *testing.T) {
4647
pipeline := NewTestOSTreeDeployment()
4748

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

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

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

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

65+
func TestOSTreeDeploymentPipelineNoMountUnitStages(t *testing.T) {
66+
pipeline := NewTestOSTreeDeployment()
67+
68+
pipeline.PartitionTable = testdisk.MakeFakePartitionTable("/", "/home")
69+
pipeline.MountConfiguration = osbuild.MOUNT_CONFIGURATION_NONE
70+
71+
checkStagesForNoMounts(t, manifest.SerializeWith(pipeline, testCommitInputs()).Stages)
72+
}
73+
6474
func TestAddInlineOSTreeDeployment(t *testing.T) {
6575
deployment := NewTestOSTreeDeployment()
6676

pkg/manifest/raw_bootc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ type RawBootcImage struct {
4545
// selected profile
4646
SELinux string
4747

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

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

179-
fsCfgStages, err := filesystemConfigStages(pt, p.MountUnits)
179+
fsCfgStages, err := filesystemConfigStages(pt, p.MountConfiguration)
180180
if err != nil {
181181
panic(err)
182182
}

0 commit comments

Comments
 (0)