Skip to content

Commit 9b209f0

Browse files
committed
partitioning: Add partattrs property to partition
Add a 'partattrs' property to partitions. It allows the GPT partition attribute bits to be set for a partition. Notably this is needed to set bits 48 and 56, which are part of the GUID specific range, to allow a ChromeOS Kernel partition to be booted on Chromebooks. Signed-off-by: Nícolas F. R. A. Prado <[email protected]>
1 parent 227cf70 commit 9b209f0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

actions/image_partition_action.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ a 32 bits hexadecimal number (e.g. '1234ABCD' without any dash separator).
5858
fsck: bool
5959
fsuuid: string
6060
partuuid: string
61+
partattrs: list of partition attribute bits to set
6162
6263
Mandatory properties:
6364
@@ -95,6 +96,16 @@ for partition.
9596
- flags -- list of additional flags for partition compatible with parted(8)
9697
'set' command.
9798
99+
- partattrs -- list of GPT partition attribute bits to set, as defined in
100+
https://uefi.org/specs/UEFI/2.10/05_GUID_Partition_Table_Format.html#defined-gpt-partition-entry-attributes.
101+
Bit 0: "Required Partition", bit 1: "No Block IO Protocol", bit 2: "Legacy BIOS
102+
Bootable". Bits 3-47 are reserved. Bits 48 - 63 are GUID specific. For example,
103+
ChromeOS Kernel partitions (GUID=fe3a2a5d-4f32-41a7-b725-accc3285a309) use bit
104+
56 for "successful boot" and bits 48-51 for "priority", where 0 means not
105+
bootable, thus bits 56 and 48 need to be set through this property in order to
106+
be able to boot a ChromeOS Kernel partition on a Chromebook, like so:
107+
'partattrs: [56, 48]'.
108+
98109
- fsck -- if set to `false` -- then set fs_passno (man fstab) to 0 meaning no filesystem
99110
checks in boot time. By default is set to `true` allowing checks on boot.
100111
@@ -175,6 +186,7 @@ import (
175186
"path/filepath"
176187
"sort"
177188
"strings"
189+
"strconv"
178190
"syscall"
179191
"time"
180192
"regexp"
@@ -187,6 +199,7 @@ type Partition struct {
187199
Name string
188200
PartLabel string
189201
PartType string
202+
PartAttrs []string
190203
PartUUID string
191204
Start string
192205
End string
@@ -557,6 +570,13 @@ func (i ImagePartitionAction) Run(context *debos.DebosContext) error {
557570
}
558571
}
559572

573+
if p.PartAttrs != nil && len(p.PartAttrs) > 0 {
574+
err = debos.Command{}.Run("sfdisk", "sfdisk", "--part-attrs", context.Image, fmt.Sprintf("%d", p.number), strings.Join(p.PartAttrs, ","))
575+
if err != nil {
576+
return err
577+
}
578+
}
579+
560580
/* PartUUID will only be set for gpt partitions */
561581
if len(p.PartUUID) > 0 {
562582
err = debos.Command{}.Run("sfdisk", "sfdisk", "--part-uuid", context.Image, fmt.Sprintf("%d", p.number), p.PartUUID)
@@ -825,6 +845,13 @@ func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error {
825845
}
826846
}
827847

848+
for _, bitStr := range p.PartAttrs {
849+
bit, err := strconv.ParseInt(bitStr, 0, 0)
850+
if err != nil || bit < 0 || bit > 2 && bit < 48 || bit > 63 {
851+
return fmt.Errorf("Partition attribute bit '%s' outside of valid range (0-2, 48-63)", bitStr)
852+
}
853+
}
854+
828855
if p.Start == "" {
829856
return fmt.Errorf("Partition %s missing start", p.Name)
830857
}

0 commit comments

Comments
 (0)