From 232cfd1ac96924dbcc2fb375495bb0ba7da24a77 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 1 Oct 2024 10:50:59 +0200 Subject: [PATCH] otk-gen-partition-table: support "raw" partitions without payload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds support for "raw" partitions without a "payload", i.e. no filesystem or LVM volume or similar. This is used for the PPC64/s390x partition table that looks like this: ``` otk.define: filesystem: modifications: # empty otk.external.otk-gen-partition-table: modifications: ${filesystem.modifications} properties: type: dos default_size: "10 GiB" uuid: "0x14fc63d2" partitions: - name: ppc-boot bootable: true size: "4 MiB" part_uuid: "" part_type: "41" - name: boot mountpoint: /boot label: boot size: "1 GiB" type: "xfs" fs_mntops: defaults part_uuid: "" - name: root mountpoint: / type: "xfs" size: "2 GiB" fs_mntops: defaults part_uuid: "" ``` Thanks to Florian Schüller for the initial implementation/research here. Co-authored-by: Florian Schüller --- cmd/otk-gen-partition-table/main.go | 13 +++-- cmd/otk-gen-partition-table/main_test.go | 63 ++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/cmd/otk-gen-partition-table/main.go b/cmd/otk-gen-partition-table/main.go index d26f5b859e..775c5cd81f 100644 --- a/cmd/otk-gen-partition-table/main.go +++ b/cmd/otk-gen-partition-table/main.go @@ -184,13 +184,15 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error) if err != nil { return nil, err } - pt.Partitions = append(pt.Partitions, disk.Partition{ + // XXX: support lvm,luks here + newPart := disk.Partition{ Size: uintSize, UUID: part.PartUUID, Type: part.PartType, Bootable: part.Bootable, - // XXX: support lvm,luks here - Payload: &disk.Filesystem{ + } + if part.Type != "" { + newPart.Payload = &disk.Filesystem{ Label: part.Label, Type: part.Type, Mountpoint: part.Mountpoint, @@ -198,8 +200,9 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error) FSTabOptions: part.FSMntOps, FSTabFreq: part.FSFreq, FSTabPassNo: part.FSPassNo, - }, - }) + } + } + pt.Partitions = append(pt.Partitions, newPart) } return pt, nil diff --git a/cmd/otk-gen-partition-table/main_test.go b/cmd/otk-gen-partition-table/main_test.go index 830a1a5b48..3d5dedb94d 100644 --- a/cmd/otk-gen-partition-table/main_test.go +++ b/cmd/otk-gen-partition-table/main_test.go @@ -331,6 +331,69 @@ func TestGenPartitionTableBootable(t *testing.T) { assert.Equal(t, true, output.Const.Internal.PartitionTable.Partitions[0].Bootable) } +func TestGenPartitionTableIntegrationPPC(t *testing.T) { + inp := &genpart.Input{ + Properties: genpart.InputProperties{ + Type: "dos", + DefaultSize: "10 GiB", + UUID: "0x14fc63d2", + }, + Partitions: []*genpart.InputPartition{ + { + Name: "ppc-boot", + Bootable: true, + Size: "4 MiB", + PartType: "41", + PartUUID: "", + }, + { + Name: "root", + Size: "10 GiB", + Type: "xfs", + Mountpoint: "/", + }, + }, + } + expectedOutput := &otkdisk.Data{ + Const: otkdisk.Const{ + KernelOptsList: []string{}, + PartitionMap: map[string]otkdisk.Partition{ + "root": { + UUID: "0194fdc2-fa2f-4cc0-81d3-ff12045b73c8", + }, + }, + Filename: "disk.img", + Internal: otkdisk.Internal{ + PartitionTable: &disk.PartitionTable{ + Size: 10742661120, + UUID: "0x14fc63d2", + Type: "dos", + Partitions: []disk.Partition{ + { + Bootable: true, + Start: 1048576, + Size: 4194304, + Type: "41", + }, + { + Start: 5242880, + Size: 10737418240, + Payload: &disk.Filesystem{ + Type: "xfs", + UUID: "0194fdc2-fa2f-4cc0-81d3-ff12045b73c8", + Mountpoint: "/", + }, + }, + }, + }, + }, + }, + } + output, err := genpart.GenPartitionTable(inp, rand.New(rand.NewSource(0))) /* #nosec G404 */ + assert.NoError(t, err) + assert.Equal(t, expectedOutput, output) +} + func TestGenPartitionTableMinimal(t *testing.T) { // XXX: think about what the smalltest inputs can be and validate // that it's complete and/or provide defaults (e.g. for "type" for