Skip to content

Commit

Permalink
otk-gen-partition-table: support EFI system on DOS partitions
Browse files Browse the repository at this point in the history
The existing code to create EFI system partitions was making
assumptions about running on a GPT partition. This is no longer
true with osbuild/otk#199 so this commit
fixes the code to create a valid ESP system partition on a DOS
partition table.
  • Loading branch information
mvo5 authored and achilleas-k committed Sep 16, 2024
1 parent b1e7fee commit 8a59516
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cmd/otk-gen-partition-table/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,8 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error)
return nil, err
}
if uintSize > 0 {
pt.Partitions = append(pt.Partitions, disk.Partition{
part := disk.Partition{
Size: uintSize,
Type: disk.EFISystemPartitionGUID,
UUID: disk.EFISystemPartitionUUID,
Payload: &disk.Filesystem{
Type: "vfat",
UUID: disk.EFIFilesystemUUID,
Expand All @@ -165,7 +163,18 @@ func makePartitionTableFromOtkInput(input *Input) (*disk.PartitionTable, error)
FSTabFreq: 0,
FSTabPassNo: 2,
},
})
}
switch input.Properties.Type {
case otkdisk.PartTypeGPT:
part.Type = disk.EFISystemPartitionGUID
part.UUID = disk.EFISystemPartitionUUID
case otkdisk.PartTypeDOS:
part.Bootable = true
part.Type = disk.DosFat16B
default:
return nil, fmt.Errorf("unsupported partition type: %v", input)
}
pt.Partitions = append(pt.Partitions, part)
}
}

Expand Down
65 changes: 65 additions & 0 deletions cmd/otk-gen-partition-table/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,3 +674,68 @@ func TestGenPartitionTableValidates(t *testing.T) {
_, err := genpart.GenPartitionTable(inp, rand.New(rand.NewSource(0))) /* #nosec G404 */
assert.EqualError(t, err, `cannot validate inputs: unsupported partition type "invalid-type"`)
}

func TestGenPartitionCreateESPDos(t *testing.T) {
inp := &genpart.Input{
Properties: genpart.InputProperties{
Type: "dos",
Create: genpart.InputCreate{
EspPartition: true,
EspPartitionSize: "2 GiB",
},
},
Partitions: []*genpart.InputPartition{
{
Mountpoint: "/",
Size: "10 GiB",
Type: "ext4",
},
},
}
expectedOutput := &otkdisk.Data{
Const: otkdisk.Const{
KernelOptsList: []string{},
PartitionMap: map[string]otkdisk.Partition{
"root": {
UUID: "6e4ff95f-f662-45ee-a82a-bdf44a2d0b75",
},
},
Filename: "disk.img",
Internal: otkdisk.Internal{
PartitionTable: &disk.PartitionTable{
Size: 12885950464,
Type: "dos",
UUID: "0194fdc2-fa2f-4cc0-81d3-ff12045b73c8",
Partitions: []disk.Partition{
{
Start: 1048576,
Size: 2147483648,
Bootable: true,
Type: "06",
Payload: &disk.Filesystem{
Type: "vfat",
UUID: "7B77-95E7",
Label: "EFI-SYSTEM",
Mountpoint: "/boot/efi",
FSTabOptions: "defaults,uid=0,gid=0,umask=077,shortname=winnt",
FSTabPassNo: 2,
},
},
{
Start: 2148532224,
Size: 10737418240,
Payload: &disk.Filesystem{
Type: "ext4",
UUID: "6e4ff95f-f662-45ee-a82a-bdf44a2d0b75",
Mountpoint: "/",
},
},
},
},
},
},
}
output, err := genpart.GenPartitionTable(inp, rand.New(rand.NewSource(0))) /* #nosec G404 */
assert.NoError(t, err)
assert.Equal(t, expectedOutput, output)
}

0 comments on commit 8a59516

Please sign in to comment.