go.mod: update osbuild/images to v0.148.0

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

---
This commit is contained in:
Achilleas Koutsou 2025-05-27 16:35:51 +02:00
parent 12dd0b0be4
commit c77ca66191
88 changed files with 5093 additions and 4979 deletions

View file

@ -1,12 +1,57 @@
package disk
import (
"encoding/json"
"fmt"
"math/rand"
"reflect"
"github.com/google/uuid"
)
type MkfsOption int
const ( // MkfsOption type enum
MkfsVerity MkfsOption = iota // Enable fs-verity option if needed (typically for EXT4)
)
func getMkfsOptionMapping() []string {
return []string{"verity"}
}
// String converts MkfsOption into a human readable string
func (option MkfsOption) String() string {
return getMkfsOptionMapping()[int(option)]
}
func unmarshalHelper(data []byte, mapping []string) (int, error) {
var stringInput string
err := json.Unmarshal(data, &stringInput)
if err != nil {
return 0, err
}
for n, str := range mapping {
if str == stringInput {
return n, nil
}
}
return 0, fmt.Errorf("invalid mkfsoption: %s", stringInput)
}
// UnmarshalJSON converts a JSON string into an MkfsOption
func (option *MkfsOption) UnmarshalJSON(data []byte) error {
val, err := unmarshalHelper(data, getMkfsOptionMapping())
if err != nil {
return err
}
*option = MkfsOption(val)
return nil
}
func (option MkfsOption) MarshalJSON() ([]byte, error) {
return json.Marshal(getMkfsOptionMapping()[option])
}
// Filesystem related functions
type Filesystem struct {
Type string `json:"type" yaml:"type"`
@ -22,6 +67,8 @@ type Filesystem struct {
FSTabFreq uint64 `json:"fstab_freq,omitempty" yaml:"fstab_freq,omitempty"`
// The sixth field of fstab(5); fs_passno
FSTabPassNo uint64 `json:"fstab_passno,omitempty" yaml:"fstab_passno,omitempty"`
// Custom mkfs options
MkfsOptions []MkfsOption `json:"mkfs_options,omitempty" yaml:"mkfs_options,omitempty"`
}
func init() {
@ -46,6 +93,7 @@ func (fs *Filesystem) Clone() Entity {
FSTabOptions: fs.FSTabOptions,
FSTabFreq: fs.FSTabFreq,
FSTabPassNo: fs.FSTabPassNo,
MkfsOptions: fs.MkfsOptions,
}
}

View file

@ -21,6 +21,9 @@ type Partition struct {
// 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"`
}
@ -36,6 +39,7 @@ func (p *Partition) Clone() Entity {
Type: p.Type,
Bootable: p.Bootable,
UUID: p.UUID,
Label: p.Label,
}
if p.Payload != nil {

View file

@ -51,6 +51,11 @@ const (
DefaultPartitioningMode PartitioningMode = ""
)
// DefaultBootPartitionSize is the default size of the /boot partition if it
// needs to be auto-created. This happens if the custom partitioning don't
// specify one, but the image requires one to boot (/ is on btrfs, or an LV).
const DefaultBootPartitionSize = 1 * datasizes.GiB
// NewPartitionTable takes an existing base partition table and some parameters
// and returns a new version of the base table modified to satisfy the
// parameters.
@ -725,7 +730,7 @@ func (pt *PartitionTable) ensureLVM() error {
// we need a /boot partition to boot LVM, ensure one exists
bootPath := entityPath(pt, "/boot")
if bootPath == nil {
_, err := pt.CreateMountpoint("/boot", 512*datasizes.MiB)
_, err := pt.CreateMountpoint("/boot", DefaultBootPartitionSize)
if err != nil {
return err
@ -784,7 +789,7 @@ func (pt *PartitionTable) ensureBtrfs(architecture arch.Arch) error {
// we need a /boot partition to boot btrfs, ensure one exists
bootPath := entityPath(pt, "/boot")
if bootPath == nil {
_, err := pt.CreateMountpoint("/boot", 512*datasizes.MiB)
_, err := pt.CreateMountpoint("/boot", DefaultBootPartitionSize)
if err != nil {
return fmt.Errorf("failed to create /boot partition when ensuring btrfs: %w", err)
}
@ -1066,7 +1071,7 @@ func addBootPartition(pt *PartitionTable, bootFsType FSType) error {
}
bootPart := Partition{
Type: partType,
Size: 512 * datasizes.MiB,
Size: DefaultBootPartitionSize,
Payload: &Filesystem{
Type: bootFsType.String(),
Label: bootLabel,
@ -1078,6 +1083,20 @@ func addBootPartition(pt *PartitionTable, bootFsType FSType) error {
return nil
}
func hasESP(disk *blueprint.DiskCustomization) bool {
if disk == nil {
return false
}
for _, part := range disk.Partitions {
if part.Type == "plain" && part.Mountpoint == "/boot/efi" {
return true
}
}
return false
}
// addPartitionsForBootMode creates partitions to satisfy the boot mode requirements:
// - BIOS/legacy: adds a 1 MiB BIOS boot partition.
// - UEFI: adds a 200 MiB EFI system partition.
@ -1086,7 +1105,7 @@ func addBootPartition(pt *PartitionTable, bootFsType FSType) error {
// The function will append the new partitions to the end of the existing
// partition table therefore it is best to call this function early to put them
// near the front (as is conventional).
func addPartitionsForBootMode(pt *PartitionTable, bootMode platform.BootMode) error {
func addPartitionsForBootMode(pt *PartitionTable, disk *blueprint.DiskCustomization, bootMode platform.BootMode) error {
switch bootMode {
case platform.BOOT_LEGACY:
// add BIOS boot partition
@ -1097,12 +1116,14 @@ func addPartitionsForBootMode(pt *PartitionTable, bootMode platform.BootMode) er
pt.Partitions = append(pt.Partitions, part)
return nil
case platform.BOOT_UEFI:
// add ESP
part, err := mkESP(200*datasizes.MiB, pt.Type)
if err != nil {
return err
// add ESP if needed
if !hasESP(disk) {
part, err := mkESP(200*datasizes.MiB, pt.Type)
if err != nil {
return err
}
pt.Partitions = append(pt.Partitions, part)
}
pt.Partitions = append(pt.Partitions, part)
return nil
case platform.BOOT_HYBRID:
// add both
@ -1110,11 +1131,14 @@ func addPartitionsForBootMode(pt *PartitionTable, bootMode platform.BootMode) er
if err != nil {
return err
}
esp, err := mkESP(200*datasizes.MiB, pt.Type)
if err != nil {
return err
pt.Partitions = append(pt.Partitions, bios)
if !hasESP(disk) {
esp, err := mkESP(200*datasizes.MiB, pt.Type)
if err != nil {
return err
}
pt.Partitions = append(pt.Partitions, esp)
}
pt.Partitions = append(pt.Partitions, bios, esp)
return nil
case platform.BOOT_NONE:
return nil
@ -1149,7 +1173,7 @@ func mkESP(size uint64, ptType PartitionTableType) (Partition, error) {
Type: "vfat",
UUID: EFIFilesystemUUID,
Mountpoint: "/boot/efi",
Label: "EFI-SYSTEM",
Label: "ESP",
FSTabOptions: "defaults,uid=0,gid=0,umask=077,shortname=winnt",
FSTabFreq: 0,
FSTabPassNo: 2,
@ -1268,8 +1292,7 @@ func NewCustomPartitionTable(customizations *blueprint.DiskCustomization, option
// add any partition(s) that are needed for booting (like /boot/efi)
// if needed
//
// TODO: switch to ensure ESP in case customizations already include it
if err := addPartitionsForBootMode(pt, options.BootMode); err != nil {
if err := addPartitionsForBootMode(pt, customizations, options.BootMode); err != nil {
return nil, fmt.Errorf("%s %w", errPrefix, err)
}
// add the /boot partition (if it is needed)
@ -1279,10 +1302,16 @@ func NewCustomPartitionTable(customizations *blueprint.DiskCustomization, option
// add user customized partitions
for _, part := range customizations.Partitions {
if part.PartType != "" {
// check the partition type now that we also know the partition table type
// check the partition details now that we also know the partition table type
if err := part.ValidatePartitionTypeID(pt.Type.String()); err != nil {
return nil, fmt.Errorf("%s error validating partition type ID for %q: %w", errPrefix, part.Mountpoint, err)
}
if err := part.ValidatePartitionID(pt.Type.String()); err != nil {
return nil, fmt.Errorf("%s error validating partition ID for %q: %w", errPrefix, part.Mountpoint, err)
}
if err := part.ValidatePartitionLabel(pt.Type.String()); err != nil {
return nil, fmt.Errorf("%s error validating partition label for %q: %w", errPrefix, part.Mountpoint, err)
}
}
switch part.Type {
@ -1377,6 +1406,8 @@ func addPlainPartition(pt *PartitionTable, partition blueprint.PartitionCustomiz
newpart := Partition{
Type: partType,
UUID: partition.PartUUID,
Label: partition.PartLabel,
Size: partition.MinSize,
Payload: payload,
}
@ -1449,6 +1480,8 @@ func addLVMPartition(pt *PartitionTable, partition blueprint.PartitionCustomizat
newpart := Partition{
Type: partType,
UUID: partition.PartUUID,
Label: partition.PartLabel,
Size: partition.MinSize,
Bootable: false,
Payload: newvg,
@ -1482,6 +1515,8 @@ func addBtrfsPartition(pt *PartitionTable, partition blueprint.PartitionCustomiz
}
newpart := Partition{
Type: partType,
UUID: partition.PartUUID,
Label: partition.PartLabel,
Bootable: false,
Payload: newvol,
Size: partition.MinSize,