Skip to content

Commit

Permalink
otk-gen-partition-table: add bootable flag support
Browse files Browse the repository at this point in the history
This commit adds support to mark partitions as bootable from
an `otk-gen-partition-table` input. E.g.:
```yaml
{
...
  "partitions": [
    {
...
      "bootable": true,
...
    },
```
  • Loading branch information
mvo5 authored and supakeen committed Oct 4, 2024
1 parent cd903c0 commit 0f227e7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/otk-gen-partition-table/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type InputCreate struct {
// InputPartition represents a single user provided partition input
type InputPartition struct {
Name string `json:"name"`
Bootable bool `json:"bootable"`
Mountpoint string `json:"mountpoint"`
Label string `json:"label"`
Size string `json:"size"`
Expand Down Expand Up @@ -184,9 +185,10 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error)
return nil, err
}
pt.Partitions = append(pt.Partitions, disk.Partition{
Size: uintSize,
UUID: part.PartUUID,
Type: part.PartType,
Size: uintSize,
UUID: part.PartUUID,
Type: part.PartType,
Bootable: part.Bootable,
// XXX: support lvm,luks here
Payload: &disk.Filesystem{
Label: part.Label,
Expand Down
24 changes: 24 additions & 0 deletions cmd/otk-gen-partition-table/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
)

// see https://github.com/achilleas-k/images/pull/2#issuecomment-2136025471
// Note that this partition table contains all json keys for testing, some may
// contradict each other
var partInputsComplete = `
{
"properties": {
Expand All @@ -32,6 +34,7 @@ var partInputsComplete = `
"partitions": [
{
"name": "root",
"bootable": true,
"mountpoint": "/",
"label": "root",
"size": "7 GiB",
Expand Down Expand Up @@ -69,6 +72,7 @@ var expectedInput = &genpart.Input{
Partitions: []*genpart.InputPartition{
{
Name: "root",
Bootable: true,
Mountpoint: "/",
Label: "root",
Size: "7 GiB",
Expand Down Expand Up @@ -307,6 +311,26 @@ func TestIntegrationRealistic(t *testing.T) {
assert.Equal(t, expectedSimplePartOutput, outp.String())
}

func TestGenPartitionTableBootable(t *testing.T) {
inp := &genpart.Input{
Properties: genpart.InputProperties{
Type: "dos",
},
Partitions: []*genpart.InputPartition{
{
Bootable: true,
Mountpoint: "/",
Size: "10 GiB",
Type: "ext4",
},
},
}

output, err := genpart.GenPartitionTable(inp, rand.New(rand.NewSource(0))) /* #nosec G404 */
assert.NoError(t, err)
assert.Equal(t, true, output.Const.Internal.PartitionTable.Partitions[0].Bootable)
}

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 0f227e7

Please sign in to comment.