osbuild2: specify mounts as an array
osbuild has recently got support for specifying mounts as an array. This commit takes advantage of it and uses this new format. This allows us to specify the order of mounts which is important because we cannot mount /boot/efi before / is mounted. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
parent
3a2415d970
commit
c656972f25
9 changed files with 32 additions and 22 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/crypt"
|
||||
"github.com/osbuild/osbuild-composer/internal/disk"
|
||||
|
|
@ -383,7 +384,7 @@ func sfdiskStageOptions(pt *disk.PartitionTable, device *osbuild.Device) (*osbui
|
|||
func copyFSTreeOptions(inputName, inputPipeline string, pt *disk.PartitionTable, device *osbuild.Device) (
|
||||
*osbuild.CopyStageOptions,
|
||||
*osbuild.CopyStageDevices,
|
||||
*osbuild.CopyStageMounts,
|
||||
osbuild.CopyStageMounts,
|
||||
) {
|
||||
// assume loopback device for simplicity since it's the only one currently supported
|
||||
// panic if the conversion fails
|
||||
|
|
@ -393,8 +394,8 @@ func copyFSTreeOptions(inputName, inputPipeline string, pt *disk.PartitionTable,
|
|||
}
|
||||
|
||||
devices := make(map[string]osbuild.Device, len(pt.Partitions))
|
||||
mounts := make(map[string]osbuild.Mount, len(pt.Partitions))
|
||||
for _, p := range pt.Partitions {
|
||||
mounts := make([]osbuild.Mount, len(pt.Partitions))
|
||||
for i, p := range pt.Partitions {
|
||||
if p.Filesystem == nil {
|
||||
// no filesystem for partition (e.g., BIOS boot)
|
||||
continue
|
||||
|
|
@ -413,17 +414,17 @@ func copyFSTreeOptions(inputName, inputPipeline string, pt *disk.PartitionTable,
|
|||
var mount *osbuild.Mount
|
||||
switch p.Filesystem.Type {
|
||||
case "xfs":
|
||||
mount = osbuild.NewXfsMount(name, p.Filesystem.Mountpoint)
|
||||
mount = osbuild.NewXfsMount(name, name, p.Filesystem.Mountpoint)
|
||||
case "vfat":
|
||||
mount = osbuild.NewFATMount(name, p.Filesystem.Mountpoint)
|
||||
mount = osbuild.NewFATMount(name, name, p.Filesystem.Mountpoint)
|
||||
case "ext4":
|
||||
mount = osbuild.NewExt4Mount(name, p.Filesystem.Mountpoint)
|
||||
mount = osbuild.NewExt4Mount(name, name, p.Filesystem.Mountpoint)
|
||||
case "btrfs":
|
||||
mount = osbuild.NewBtrfsMount(name, p.Filesystem.Mountpoint)
|
||||
mount = osbuild.NewBtrfsMount(name, name, p.Filesystem.Mountpoint)
|
||||
default:
|
||||
panic("unknown fs type " + p.Type)
|
||||
}
|
||||
mounts[name] = *mount
|
||||
mounts[i] = *mount
|
||||
}
|
||||
|
||||
stageMounts := osbuild.CopyStageMounts(mounts)
|
||||
|
|
@ -438,7 +439,7 @@ func copyFSTreeOptions(inputName, inputPipeline string, pt *disk.PartitionTable,
|
|||
},
|
||||
}
|
||||
|
||||
return &options, &stageDevices, &stageMounts
|
||||
return &options, &stageDevices, stageMounts
|
||||
}
|
||||
|
||||
func grub2InstStageOptions(filename string, pt *disk.PartitionTable, platform string) *osbuild.Grub2InstStageOptions {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package osbuild2
|
||||
|
||||
func NewBtrfsMount(source, target string) *Mount {
|
||||
func NewBtrfsMount(name, source, target string) *Mount {
|
||||
return &Mount{
|
||||
Type: "org.osbuild.btrfs",
|
||||
Name: name,
|
||||
Source: source,
|
||||
Target: target,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@ type CopyStageDevices map[string]Device
|
|||
|
||||
func (CopyStageDevices) isStageDevices() {}
|
||||
|
||||
type CopyStageMounts map[string]Mount
|
||||
type CopyStageMounts []Mount
|
||||
|
||||
func (CopyStageMounts) isStageMounts() {}
|
||||
|
||||
func NewCopyStage(options *CopyStageOptions, inputs *CopyStageInputs, devices *CopyStageDevices, mounts *CopyStageMounts) *Stage {
|
||||
func NewCopyStage(options *CopyStageOptions, inputs *CopyStageInputs, devices *CopyStageDevices, mounts CopyStageMounts) *Stage {
|
||||
return &Stage{
|
||||
Type: "org.osbuild.copy",
|
||||
Options: options,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ func TestNewCopyStage(t *testing.T) {
|
|||
},
|
||||
}
|
||||
devices := make(map[string]Device)
|
||||
mounts := make(map[string]Mount)
|
||||
var mounts []Mount
|
||||
devices["root"] = Device{
|
||||
Type: "org.osbuild.loopback",
|
||||
Options: LoopbackDeviceOptions{
|
||||
|
|
@ -35,8 +35,8 @@ func TestNewCopyStage(t *testing.T) {
|
|||
Options: &CopyStageOptions{paths},
|
||||
Inputs: &CopyStageInputs{"tree-input": treeInput},
|
||||
Devices: ©StageDevices,
|
||||
Mounts: ©StageMounts,
|
||||
Mounts: copyStageMounts,
|
||||
}
|
||||
actualStage := NewCopyStage(&CopyStageOptions{paths}, &CopyStageInputs{"tree-input": treeInput}, ©StageDevices, ©StageMounts)
|
||||
actualStage := NewCopyStage(&CopyStageOptions{paths}, &CopyStageInputs{"tree-input": treeInput}, ©StageDevices, copyStageMounts)
|
||||
assert.Equal(t, expectedStage, actualStage)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package osbuild2
|
||||
|
||||
func NewExt4Mount(source, target string) *Mount {
|
||||
func NewExt4Mount(name, source, target string) *Mount {
|
||||
return &Mount{
|
||||
Type: "org.osbuild.ext4",
|
||||
Name: name,
|
||||
Source: source,
|
||||
Target: target,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package osbuild2
|
||||
|
||||
func NewFATMount(source, target string) *Mount {
|
||||
func NewFATMount(name, source, target string) *Mount {
|
||||
return &Mount{
|
||||
Type: "org.osbuild.fat",
|
||||
Name: name,
|
||||
Source: source,
|
||||
Target: target,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ type Mounts interface {
|
|||
}
|
||||
|
||||
type Mount struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Source string `json:"source"`
|
||||
Target string `json:"target"`
|
||||
|
|
|
|||
|
|
@ -10,8 +10,9 @@ func TestNewMounts(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
|
||||
{ // btrfs
|
||||
actual := NewBtrfsMount("/dev/sda1", "/mnt/btrfs")
|
||||
actual := NewBtrfsMount("btrfs", "/dev/sda1", "/mnt/btrfs")
|
||||
expected := &Mount{
|
||||
Name: "btrfs",
|
||||
Type: "org.osbuild.btrfs",
|
||||
Source: "/dev/sda1",
|
||||
Target: "/mnt/btrfs",
|
||||
|
|
@ -20,8 +21,9 @@ func TestNewMounts(t *testing.T) {
|
|||
}
|
||||
|
||||
{ // ext4
|
||||
actual := NewExt4Mount("/dev/sda2", "/mnt/ext4")
|
||||
actual := NewExt4Mount("ext4", "/dev/sda2", "/mnt/ext4")
|
||||
expected := &Mount{
|
||||
Name: "ext4",
|
||||
Type: "org.osbuild.ext4",
|
||||
Source: "/dev/sda2",
|
||||
Target: "/mnt/ext4",
|
||||
|
|
@ -30,8 +32,9 @@ func TestNewMounts(t *testing.T) {
|
|||
}
|
||||
|
||||
{ // fat
|
||||
actual := NewFATMount("/dev/sda3", "/mnt/fat")
|
||||
actual := NewFATMount("fat", "/dev/sda3", "/mnt/fat")
|
||||
expected := &Mount{
|
||||
Name: "fat",
|
||||
Type: "org.osbuild.fat",
|
||||
Source: "/dev/sda3",
|
||||
Target: "/mnt/fat",
|
||||
|
|
@ -40,8 +43,9 @@ func TestNewMounts(t *testing.T) {
|
|||
}
|
||||
|
||||
{ // xfs
|
||||
actual := NewXfsMount("/dev/sda4", "/mnt/xfs")
|
||||
actual := NewXfsMount("xfs", "/dev/sda4", "/mnt/xfs")
|
||||
expected := &Mount{
|
||||
Name: "xfs",
|
||||
Type: "org.osbuild.xfs",
|
||||
Source: "/dev/sda4",
|
||||
Target: "/mnt/xfs",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package osbuild2
|
||||
|
||||
func NewXfsMount(source, target string) *Mount {
|
||||
func NewXfsMount(name, source, target string) *Mount {
|
||||
return &Mount{
|
||||
Type: "org.osbuild.xfs",
|
||||
Name: name,
|
||||
Source: source,
|
||||
Target: target,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue