Skip to content

Commit

Permalink
partitioning: Add partattrs property to partition
Browse files Browse the repository at this point in the history
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 <nfraprado@collabora.com>
  • Loading branch information
nfraprado committed May 31, 2024
1 parent 3a3ad05 commit 55a3e2d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions actions/image_partition_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ a 32 bits hexadecimal number (e.g. '1234ABCD' without any dash separator).
fsck: bool
fsuuid: string
partuuid: string
partattrs: list of partition attribute bits to set
Mandatory properties:
Expand Down Expand Up @@ -95,6 +96,16 @@ for partition.
- flags -- list of additional flags for partition compatible with parted(8)
'set' command.
- partattrs -- list of GPT partition attribute bits to set, as defined in
https://uefi.org/specs/UEFI/2.10/05_GUID_Partition_Table_Format.html#defined-gpt-partition-entry-attributes.
Bit 0: "Required Partition", bit 1: "No Block IO Protocol", bit 2: "Legacy BIOS
Bootable". Bits 3-47 are reserved. Bits 48 - 63 are GUID specific. For example,
ChromeOS Kernel partitions (GUID=fe3a2a5d-4f32-41a7-b725-accc3285a309) use bit
56 for "successful boot" and bits 48-51 for "priority", where 0 means not
bootable, thus bits 56 and 48 need to be set through this property in order to
be able to boot a ChromeOS Kernel partition on a Chromebook, like so:
'partattrs: [56, 48]'.
- fsck -- if set to `false` -- then set fs_passno (man fstab) to 0 meaning no filesystem
checks in boot time. By default is set to `true` allowing checks on boot.
Expand Down Expand Up @@ -175,6 +186,7 @@ import (
"path/filepath"
"sort"
"strings"
"strconv"
"syscall"
"time"
"regexp"
Expand All @@ -187,6 +199,7 @@ type Partition struct {
Name string
PartLabel string
PartType string
PartAttrs []string
PartUUID string
Start string
End string
Expand Down Expand Up @@ -531,6 +544,13 @@ func (i ImagePartitionAction) Run(context *debos.DebosContext) error {
}
}

if p.PartAttrs != nil && len(p.PartAttrs) > 0 {
err = debos.Command{}.Run("sfdisk", "sfdisk", "--part-attrs", context.Image, fmt.Sprintf("%d", p.number), strings.Join(p.PartAttrs, ","))
if err != nil {
return err
}
}

/* PartUUID will only be set for gpt partitions */
if len(p.PartUUID) > 0 {
err = debos.Command{}.Run("sfdisk", "sfdisk", "--part-uuid", context.Image, fmt.Sprintf("%d", p.number), p.PartUUID)
Expand Down Expand Up @@ -792,6 +812,13 @@ func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error {
}
}

for _, bitStr := range p.PartAttrs {
bit, err := strconv.ParseInt(bitStr, 0, 0)
if err != nil || bit < 0 || bit > 2 && bit < 48 || bit > 63 {
return fmt.Errorf("Partition attribute bit '%s' outside of valid range (0-2, 48-63)", bitStr)
}
}

if p.Start == "" {
return fmt.Errorf("Partition %s missing start", p.Name)
}
Expand Down

0 comments on commit 55a3e2d

Please sign in to comment.