diff --git a/cmd/otk-gen-partition-table/main.go b/cmd/otk-gen-partition-table/main.go index 3503f7cdc0..d26f5b859e 100644 --- a/cmd/otk-gen-partition-table/main.go +++ b/cmd/otk-gen-partition-table/main.go @@ -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"` @@ -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, diff --git a/cmd/otk-gen-partition-table/main_test.go b/cmd/otk-gen-partition-table/main_test.go index e1b8aaa605..830a1a5b48 100644 --- a/cmd/otk-gen-partition-table/main_test.go +++ b/cmd/otk-gen-partition-table/main_test.go @@ -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": { @@ -32,6 +34,7 @@ var partInputsComplete = ` "partitions": [ { "name": "root", + "bootable": true, "mountpoint": "/", "label": "root", "size": "7 GiB", @@ -69,6 +72,7 @@ var expectedInput = &genpart.Input{ Partitions: []*genpart.InputPartition{ { Name: "root", + Bootable: true, Mountpoint: "/", Label: "root", Size: "7 GiB", @@ -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