tag v0.145.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.145.0 ---------------- * github: run dependabot gomod action weekly (osbuild/images#1476) * Author: Achilleas Koutsou, Reviewers: Lukáš Zapletal — Somewhere on the Internet, 2025-05-12 --- tag v0.146.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.146.0 ---------------- * Fixes for ESP partition: Make optional, set label (osbuild/images#1525) * Author: Alexander Larsson, Reviewers: Achilleas Koutsou, Brian C. Lane * Initial automotive work: custom selinux policy, separate build container for bootc, and ext4 verity (osbuild/images#1519) * Author: Alexander Larsson, Reviewers: Achilleas Koutsou, Simon de Vlieger * Update snapshots to 20250512 (osbuild/images#1515) * Author: SchutzBot, Reviewers: Achilleas Koutsou, Simon de Vlieger * disk: make auto-generated /boot 1 GiB big (osbuild/images#1499) * Author: Ondřej Budai, Reviewers: Achilleas Koutsou, Michael Vogt * distro.yaml: Clean up yamllint errors and warnings (osbuild/images#1523) * Author: Brian C. Lane, Reviewers: Michael Vogt, Simon de Vlieger * distro/rhel9: make /boot 1 GiB everywhere (osbuild/images#1498) * Author: Ondřej Budai, Reviewers: Michael Vogt, Simon de Vlieger * distro: move disk/container image types into pure YAML (COMPOSER-2533) (osbuild/images#1508) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Simon de Vlieger * fedora: move all image types into pure YAML (osbuild/images#1514) * Author: Michael Vogt, Reviewers: Brian C. Lane, Simon de Vlieger * fsnode: fix go-1.24 errors (osbuild/images#1521) * Author: Michael Vogt, Reviewers: Ondřej Budai, Tomáš Hozza * osbuild: add JSON/YAML unmarshal to UdevRulesStageOptions (osbuild/images#1489) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Simon de Vlieger * test: Run more distro tests in parallel (osbuild/images#1483) * Author: Brian C. Lane, Reviewers: Michael Vogt, Simon de Vlieger — Somewhere on the Internet, 2025-05-19 --- tag v0.147.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.147.0 ---------------- * Add support for setting partition uuid and label (osbuild/images#1543) * Author: Alexander Larsson, Reviewers: Achilleas Koutsou, Simon de Vlieger * Cleanup of new APIs (mkfs options and build container) (osbuild/images#1526) * Author: Alexander Larsson, Reviewers: Achilleas Koutsou, Simon de Vlieger * distro/rhel: remove the user/group warnings for edge-commits (osbuild/images#1538) * Author: Achilleas Koutsou, Reviewers: Brian C. Lane, Simon de Vlieger — Somewhere on the Internet, 2025-05-20 --- tag v0.148.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.148.0 ---------------- * Makefile: add vet command to check for consistent struct tags (osbuild/images#1554) * Author: Michael Vogt, Reviewers: Lukáš Zapletal, Simon de Vlieger * disk: tiny tweaks for the new MkfsOptions support (osbuild/images#1545) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Alexander Larsson, Lukáš Zapletal * fedora/many: increase `/boot` to 1 GiB (HMS-8604) (osbuild/images#1557) * Author: Simon de Vlieger, Reviewers: Achilleas Koutsou, Ondřej Budai * fedora/wsl: include `wsl-setup` (HMS-8573) (osbuild/images#1550) * Author: Simon de Vlieger, Reviewers: Brian C. Lane, Michael Vogt * fedora: add `anaconda.ModuleUsers` to ImageInstallerImage (osbuild/images#1558) * Author: Michael Vogt, Reviewers: Brian C. Lane, Simon de Vlieger * fedora: implement setting of the RootfsType via YAML (osbuild/images#1544) * Author: Michael Vogt, Reviewers: Brian C. Lane, Simon de Vlieger * rhel10: move ImageConfig into pure YAML (osbuild/images#1542) * Author: Michael Vogt, Reviewers: Brian C. Lane, Simon de Vlieger — Somewhere on the Internet, 2025-05-26 ---
147 lines
3.5 KiB
Go
147 lines
3.5 KiB
Go
package disk
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/osbuild/images/internal/common"
|
|
)
|
|
|
|
type Partition struct {
|
|
// Start of the partition in bytes
|
|
Start uint64 `json:"start,omitempty" yaml:"start,omitempty"`
|
|
// Size of the partition in bytes
|
|
Size uint64 `json:"size" yaml:"size"`
|
|
// Partition type, e.g. 0x83 for MBR or a UUID for gpt
|
|
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
|
// `Legacy BIOS bootable` (GPT) or `active` (DOS) flag
|
|
Bootable bool `json:"bootable,omitempty" yaml:"bootable,omitempty"`
|
|
|
|
// ID of the partition, dos doesn't use traditional UUIDs, therefore this
|
|
// is just a string.
|
|
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
|
|
|
|
// Partition name (not filesystem label), only supported for GPT
|
|
Label string `json:"label,omitempty" yaml:"label,omitempty"`
|
|
|
|
// If nil, the partition is raw; It doesn't contain a payload.
|
|
Payload PayloadEntity `json:"payload,omitempty" yaml:"payload,omitempty"`
|
|
}
|
|
|
|
func (p *Partition) Clone() Entity {
|
|
if p == nil {
|
|
return nil
|
|
}
|
|
|
|
partition := &Partition{
|
|
Start: p.Start,
|
|
Size: p.Size,
|
|
Type: p.Type,
|
|
Bootable: p.Bootable,
|
|
UUID: p.UUID,
|
|
Label: p.Label,
|
|
}
|
|
|
|
if p.Payload != nil {
|
|
partition.Payload = p.Payload.Clone().(PayloadEntity)
|
|
}
|
|
|
|
return partition
|
|
}
|
|
|
|
func (pt *Partition) GetItemCount() uint {
|
|
if pt == nil || pt.Payload == nil {
|
|
return 0
|
|
}
|
|
return 1
|
|
}
|
|
|
|
func (p *Partition) GetChild(n uint) Entity {
|
|
if n != 0 {
|
|
panic(fmt.Sprintf("invalid child index for Partition: %d != 0", n))
|
|
}
|
|
return p.Payload
|
|
}
|
|
|
|
// fitTo resizes a partition to be either the given the size or the size of its
|
|
// payload if that is larger. The payload can be larger if it is a container
|
|
// with sized children.
|
|
func (p *Partition) fitTo(size uint64) {
|
|
payload, isVC := p.Payload.(VolumeContainer)
|
|
if isVC {
|
|
if payloadMinSize := payload.minSize(size); payloadMinSize > size {
|
|
size = payloadMinSize
|
|
}
|
|
}
|
|
p.Size = size
|
|
}
|
|
|
|
func (p *Partition) GetSize() uint64 {
|
|
return p.Size
|
|
}
|
|
|
|
// Ensure the partition has at least the given size. Will do nothing
|
|
// if the partition is already larger. Returns if the size changed.
|
|
func (p *Partition) EnsureSize(s uint64) bool {
|
|
if s > p.Size {
|
|
p.Size = s
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (p *Partition) IsBIOSBoot() bool {
|
|
if p == nil {
|
|
return false
|
|
}
|
|
|
|
return p.Type == BIOSBootPartitionGUID || p.Type == BIOSBootPartitionDOSID
|
|
}
|
|
|
|
func (p *Partition) IsPReP() bool {
|
|
if p == nil {
|
|
return false
|
|
}
|
|
|
|
return p.Type == PRepPartitionDOSID || p.Type == PRePartitionGUID
|
|
}
|
|
|
|
func (p *Partition) MarshalJSON() ([]byte, error) {
|
|
type partAlias Partition
|
|
|
|
var entityName string
|
|
if p.Payload != nil {
|
|
entityName = p.Payload.EntityName()
|
|
}
|
|
|
|
partWithPayloadType := struct {
|
|
partAlias
|
|
PayloadType string `json:"payload_type,omitempty" yaml:"payload_type,omitempty"`
|
|
}{
|
|
partAlias(*p),
|
|
entityName,
|
|
}
|
|
|
|
return json.Marshal(partWithPayloadType)
|
|
}
|
|
|
|
func (p *Partition) UnmarshalJSON(data []byte) (err error) {
|
|
// keep in sync with lvm.go,partition.go,luks.go
|
|
type alias Partition
|
|
var withoutPayload struct {
|
|
alias
|
|
Payload json.RawMessage `json:"payload" yaml:"payload"`
|
|
PayloadType string `json:"payload_type" yaml:"payload_type"`
|
|
}
|
|
if err := jsonUnmarshalStrict(data, &withoutPayload); err != nil {
|
|
return fmt.Errorf("cannot unmarshal %q: %w", data, err)
|
|
}
|
|
*p = Partition(withoutPayload.alias)
|
|
|
|
p.Payload, err = unmarshalJSONPayload(data)
|
|
return err
|
|
}
|
|
|
|
func (t *Partition) UnmarshalYAML(unmarshal func(any) error) error {
|
|
return common.UnmarshalYAMLviaJSON(t, unmarshal)
|
|
}
|