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 08a7802
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion partitioning/gpt/gpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ func (t *Table) writePMBR() error {

// boot signature
protectiveMBR[510], protectiveMBR[511] = 0x55, 0xAA
protectiveMBR[511] = 0xAA

// PMBR protective entry.
b := protectiveMBR[446 : 446+16]
Expand Down
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 08a7802

Please sign in to comment.