Skip to content

Commit

Permalink
fix: add support for 'legacy bios bootable' attribute
Browse files Browse the repository at this point in the history
Used in GRUB/BIOS boot scheme.

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Aug 26, 2024
1 parent fa9291f commit a3250a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions partitioning/gpt/gpt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func TestGPT(t *testing.T) {
)))
require.NoError(t, allocateError(table.AllocatePartition(100*MiB, "100M", partType1,
gpt.WithUniqueGUID(uuid.MustParse("3D0FE86B-7791-4659-B564-FC49A542866D")),
gpt.WithLegacyBIOSBootableAttribute(true),
)))
require.NoError(t, allocateError(table.AllocatePartition(2.5*GiB, "2.5G", partType2,
gpt.WithUniqueGUID(uuid.MustParse("EE1A711E-DE12-4D9F-98FF-672F7AD638F8")),
Expand Down
9 changes: 9 additions & 0 deletions partitioning/gpt/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,12 @@ func WithUniqueGUID(guid uuid.UUID) PartitionOption {
o.UniqueGUID = guid
}
}

// WithLegacyBIOSBootableAttribute marks the partition as bootable.
func WithLegacyBIOSBootableAttribute(val bool) PartitionOption {
return func(args *PartitionOptions) {
if val {
args.Flags |= (1 << 2)
}
}
}
2 changes: 1 addition & 1 deletion partitioning/gpt/testdata/allocate.sfdisk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ last-lba: 12582878
sector-size: 512

start= 2048, size= 2097152, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=DA66737E-1ED4-4DDF-B98C-70CEBFE3ADA0, name="1G"
start= 2099200, size= 204800, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=3D0FE86B-7791-4659-B564-FC49A542866D, name="100M"
start= 2099200, size= 204800, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=3D0FE86B-7791-4659-B564-FC49A542866D, name="100M", attrs="LegacyBIOSBootable"
start= 2304000, size= 5242880, type=E6D6D379-F507-44C2-A23C-238F2A3DF928, uuid=EE1A711E-DE12-4D9F-98FF-672F7AD638F8, name="2.5G"
start= 7546880, size= 2097152, type=E6D6D379-F507-44C2-A23C-238F2A3DF928, uuid=15E609C8-9775-4E86-AF59-8A87E7C03FAB, name="1G"

0 comments on commit a3250a2

Please sign in to comment.