Skip to content

Commit

Permalink
otk-gen-partition-table: support "raw" partitions without payload
Browse files Browse the repository at this point in the history
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 <florian.schueller@redhat.com>
  • Loading branch information
2 people authored and supakeen committed Oct 4, 2024
1 parent 0f227e7 commit 232cfd1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cmd/otk-gen-partition-table/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,25 @@ 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,
UUID: part.FsUUID,
FSTabOptions: part.FSMntOps,
FSTabFreq: part.FSFreq,
FSTabPassNo: part.FSPassNo,
},
})
}
}
pt.Partitions = append(pt.Partitions, newPart)
}

return pt, nil
Expand Down
63 changes: 63 additions & 0 deletions cmd/otk-gen-partition-table/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 232cfd1

Please sign in to comment.