distro/rhel84: generate fstab stage from partition table
Now that we have an abstract partition table definition, we can use it to generate org.osbuild.fstab stage options. This is extremely nice because it removes magic contains. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
parent
76926ecd35
commit
d52c1ea1f8
2 changed files with 79 additions and 37 deletions
|
|
@ -4,7 +4,11 @@
|
|||
// All of them can be 1:1 converted to osbuild.QEMUAssemblerOptions.
|
||||
package disk
|
||||
|
||||
import "github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
)
|
||||
|
||||
type PartitionTable struct {
|
||||
// Size of the disk.
|
||||
|
|
@ -34,6 +38,12 @@ type Filesystem struct {
|
|||
UUID string
|
||||
Label string
|
||||
Mountpoint string
|
||||
// The fourth field of fstab(5); fs_mntops
|
||||
FSTabOptions string
|
||||
// The fifth field of fstab(5); fs_freq
|
||||
FSTabFreq uint64
|
||||
// The sixth field of fstab(5); fs_passno
|
||||
FSTabPassNo uint64
|
||||
}
|
||||
|
||||
// Converts PartitionTable to osbuild.QEMUAssemblerOptions that encode
|
||||
|
|
@ -52,6 +62,26 @@ func (pt PartitionTable) QEMUAssemblerOptions() osbuild.QEMUAssemblerOptions {
|
|||
}
|
||||
}
|
||||
|
||||
// Generates org.osbuild.fstab stage options from this partition table.
|
||||
func (pt PartitionTable) FSTabStageOptions() *osbuild.FSTabStageOptions {
|
||||
var options osbuild.FSTabStageOptions
|
||||
for _, p := range pt.Partitions {
|
||||
fs := p.Filesystem
|
||||
if fs == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
options.AddFilesystem(fs.UUID, fs.Type, fs.Mountpoint, fs.FSTabOptions, fs.FSTabFreq, fs.FSTabPassNo)
|
||||
}
|
||||
|
||||
// sort the entries by PassNo to maintain backward compatibility
|
||||
sort.Slice(options.FileSystems, func(i, j int) bool {
|
||||
return options.FileSystems[i].PassNo < options.FileSystems[j].PassNo
|
||||
})
|
||||
|
||||
return &options
|
||||
}
|
||||
|
||||
// Converts Partition to osbuild.QEMUPartition that encodes the same partition.
|
||||
func (p Partition) QEMUPartition() osbuild.QEMUPartition {
|
||||
var fs *osbuild.QEMUFilesystem
|
||||
|
|
|
|||
|
|
@ -231,6 +231,12 @@ func sources(packages []rpmmd.PackageSpec) *osbuild.Sources {
|
|||
}
|
||||
|
||||
func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOptions, repos []rpmmd.RepoConfig, packageSpecs, buildPackageSpecs []rpmmd.PackageSpec) (*osbuild.Pipeline, error) {
|
||||
var pt *disk.PartitionTable
|
||||
if t.partitionTableGenerator != nil {
|
||||
table := t.partitionTableGenerator(options, t.arch)
|
||||
pt = &table
|
||||
}
|
||||
|
||||
p := &osbuild.Pipeline{}
|
||||
p.SetBuild(t.buildPipeline(repos, *t.arch, buildPackageSpecs), "org.osbuild.rhel84")
|
||||
|
||||
|
|
@ -244,8 +250,11 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp
|
|||
p.AddStage(osbuild.NewRPMStage(t.rpmStageOptions(*t.arch, repos, packageSpecs)))
|
||||
p.AddStage(osbuild.NewFixBLSStage())
|
||||
|
||||
if pt != nil {
|
||||
p.AddStage(osbuild.NewFSTabStage(pt.FSTabStageOptions()))
|
||||
}
|
||||
|
||||
if t.bootable {
|
||||
p.AddStage(osbuild.NewFSTabStage(t.fsTabStageOptions(t.arch.uefi)))
|
||||
if t.arch.Name() != "s390x" {
|
||||
p.AddStage(osbuild.NewGRUB2Stage(t.grub2StageOptions(t.kernelOptions, c.GetKernel(), t.arch.uefi, t.arch.legacy)))
|
||||
}
|
||||
|
|
@ -328,12 +337,6 @@ func (t *imageType) pipeline(c *blueprint.Customizations, options distro.ImageOp
|
|||
))
|
||||
}
|
||||
|
||||
var pt *disk.PartitionTable
|
||||
if t.partitionTableGenerator != nil {
|
||||
table := t.partitionTableGenerator(options, t.arch)
|
||||
pt = &table
|
||||
}
|
||||
|
||||
p.Assembler = t.assembler(pt, options, t.arch)
|
||||
|
||||
return p, nil
|
||||
|
|
@ -445,15 +448,6 @@ func (t *imageType) systemdStageOptions(enabledServices, disabledServices []stri
|
|||
}
|
||||
}
|
||||
|
||||
func (t *imageType) fsTabStageOptions(uefi bool) *osbuild.FSTabStageOptions {
|
||||
options := osbuild.FSTabStageOptions{}
|
||||
options.AddFilesystem("efe8afea-c0a8-45dc-8e6e-499279f6fa5d", "xfs", "/", "defaults", 0, 0)
|
||||
if uefi {
|
||||
options.AddFilesystem("7B77-95E7", "vfat", "/boot/efi", "defaults,uid=0,gid=0,umask=077,shortname=winnt", 0, 2)
|
||||
}
|
||||
return &options
|
||||
}
|
||||
|
||||
func (t *imageType) grub2StageOptions(kernelOptions string, kernel *blueprint.KernelCustomization, uefi bool, legacy string) *osbuild.GRUB2StageOptions {
|
||||
id := uuid.MustParse("efe8afea-c0a8-45dc-8e6e-499279f6fa5d")
|
||||
|
||||
|
|
@ -506,9 +500,12 @@ func defaultPartitionTable(imageOptions distro.ImageOptions, arch distro.Arch) d
|
|||
Type: "C12A7328-F81F-11D2-BA4B-00A0C93EC93B",
|
||||
UUID: "68B2905B-DF3E-4FB3-80FA-49D1E773AA33",
|
||||
Filesystem: &disk.Filesystem{
|
||||
Type: "vfat",
|
||||
UUID: "7B77-95E7",
|
||||
Mountpoint: "/boot/efi",
|
||||
Type: "vfat",
|
||||
UUID: "7B77-95E7",
|
||||
Mountpoint: "/boot/efi",
|
||||
FSTabOptions: "defaults,uid=0,gid=0,umask=077,shortname=winnt",
|
||||
FSTabFreq: 0,
|
||||
FSTabPassNo: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -516,10 +513,13 @@ func defaultPartitionTable(imageOptions distro.ImageOptions, arch distro.Arch) d
|
|||
Type: "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
|
||||
UUID: "6264D520-3FB9-423F-8AB8-7A0A8E3D3562",
|
||||
Filesystem: &disk.Filesystem{
|
||||
Type: "xfs",
|
||||
UUID: "efe8afea-c0a8-45dc-8e6e-499279f6fa5d",
|
||||
Label: "root",
|
||||
Mountpoint: "/",
|
||||
Type: "xfs",
|
||||
UUID: "efe8afea-c0a8-45dc-8e6e-499279f6fa5d",
|
||||
Label: "root",
|
||||
Mountpoint: "/",
|
||||
FSTabOptions: "defaults",
|
||||
FSTabFreq: 0,
|
||||
FSTabPassNo: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -536,9 +536,12 @@ func defaultPartitionTable(imageOptions distro.ImageOptions, arch distro.Arch) d
|
|||
Type: "C12A7328-F81F-11D2-BA4B-00A0C93EC93B",
|
||||
UUID: "68B2905B-DF3E-4FB3-80FA-49D1E773AA33",
|
||||
Filesystem: &disk.Filesystem{
|
||||
Type: "vfat",
|
||||
UUID: "7B77-95E7",
|
||||
Mountpoint: "/boot/efi",
|
||||
Type: "vfat",
|
||||
UUID: "7B77-95E7",
|
||||
Mountpoint: "/boot/efi",
|
||||
FSTabOptions: "defaults,uid=0,gid=0,umask=077,shortname=winnt",
|
||||
FSTabFreq: 0,
|
||||
FSTabPassNo: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -546,10 +549,13 @@ func defaultPartitionTable(imageOptions distro.ImageOptions, arch distro.Arch) d
|
|||
Type: "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
|
||||
UUID: "6264D520-3FB9-423F-8AB8-7A0A8E3D3562",
|
||||
Filesystem: &disk.Filesystem{
|
||||
Type: "xfs",
|
||||
UUID: "efe8afea-c0a8-45dc-8e6e-499279f6fa5d",
|
||||
Label: "root",
|
||||
Mountpoint: "/",
|
||||
Type: "xfs",
|
||||
UUID: "efe8afea-c0a8-45dc-8e6e-499279f6fa5d",
|
||||
Label: "root",
|
||||
Mountpoint: "/",
|
||||
FSTabOptions: "defaults",
|
||||
FSTabFreq: 0,
|
||||
FSTabPassNo: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -568,9 +574,12 @@ func defaultPartitionTable(imageOptions distro.ImageOptions, arch distro.Arch) d
|
|||
{
|
||||
Start: 10240,
|
||||
Filesystem: &disk.Filesystem{
|
||||
Type: "xfs",
|
||||
UUID: "efe8afea-c0a8-45dc-8e6e-499279f6fa5d",
|
||||
Mountpoint: "/",
|
||||
Type: "xfs",
|
||||
UUID: "efe8afea-c0a8-45dc-8e6e-499279f6fa5d",
|
||||
Mountpoint: "/",
|
||||
FSTabOptions: "defaults",
|
||||
FSTabFreq: 0,
|
||||
FSTabPassNo: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -585,9 +594,12 @@ func defaultPartitionTable(imageOptions distro.ImageOptions, arch distro.Arch) d
|
|||
Start: 2048,
|
||||
Bootable: true,
|
||||
Filesystem: &disk.Filesystem{
|
||||
Type: "xfs",
|
||||
UUID: "efe8afea-c0a8-45dc-8e6e-499279f6fa5d",
|
||||
Mountpoint: "/",
|
||||
Type: "xfs",
|
||||
UUID: "efe8afea-c0a8-45dc-8e6e-499279f6fa5d",
|
||||
Mountpoint: "/",
|
||||
FSTabOptions: "defaults",
|
||||
FSTabFreq: 0,
|
||||
FSTabPassNo: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue