tag v0.149.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.149.0 ---------------- * Update dependencies 2025-05-25 (osbuild/images#1560) * Author: SchutzBot, Reviewers: Simon de Vlieger, Tomáš Hozza * Update osbuild dependency commit ID to latest (osbuild/images#1522) * Author: SchutzBot, Reviewers: Simon de Vlieger, Tomáš Hozza * Update snapshots to 20250515 (osbuild/images#1524) * Author: SchutzBot, Reviewers: Simon de Vlieger, Tomáš Hozza * `vagrant-libvirt` implementation (HMS-6116) (osbuild/images#1548) * Author: Simon de Vlieger, Reviewers: Achilleas Koutsou, Tomáš Hozza * fedora: tweaks after all imageTypes are YAML (osbuild/images#1518) * Author: Michael Vogt, Reviewers: Simon de Vlieger, Tomáš Hozza * gha: do not break gobump output (osbuild/images#1561) * Author: Lukáš Zapletal, Reviewers: Simon de Vlieger, Tomáš Hozza * repositories: AlmaLinux 10 (osbuild/images#1567) * Author: Simon de Vlieger, Reviewers: Achilleas Koutsou, Lukáš Zapletal, Neal Gompa (ニール・ゴンパ) * vagrant: image config for default vagrant user (HMS-6116) (osbuild/images#1565) * Author: Simon de Vlieger, Reviewers: Achilleas Koutsou, Michael Vogt — Somewhere on the Internet, 2025-05-27 --- tag v0.150.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.150.0 ---------------- * Replace hardcoded kickstart %post scripts with new stage options and bootc switch with custom kickstart content (HMS-6051) (osbuild/images#1527) * Author: Achilleas Koutsou, Reviewers: Simon de Vlieger, Tomáš Hozza * test: install yamllint for tests (osbuild/images#1572) * Author: Achilleas Koutsou, Reviewers: Lukáš Zapletal, Simon de Vlieger, Tomáš Hozza — Somewhere on the Internet, 2025-06-02 --- tag v0.151.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.151.0 ---------------- * Introduce new Azure CVM image type (HMS-5636) (osbuild/images#1318) * Author: Achilleas Koutsou, Reviewers: Nobody * Many: support using string with unit for byte-sized partitioning fields in YAML distro definitions (osbuild/images#1579) * Author: Tomáš Hozza, Reviewers: Achilleas Koutsou, Brian C. Lane * Update osbuild dependency commit ID to latest (osbuild/images#1587) * Author: SchutzBot, Reviewers: Achilleas Koutsou, Tomáš Hozza * Update snapshots to 20250601 (osbuild/images#1573) * Author: SchutzBot, Reviewers: Achilleas Koutsou, Lukáš Zapletal * bootc: Make installed rootfs configurable (osbuild/images#1555) * Author: Mbarak Bujra, Reviewers: Michael Vogt, Tomáš Hozza * distro: create new ImageConfig.DNFConfig (osbuild/images#1583) * Author: Michael Vogt, Reviewers: Simon de Vlieger, Tomáš Hozza * distro: make "fedora" a "generic" distro (osbuild/images#1563) * Author: Michael Vogt, Reviewers: Nobody * image: If using a separate build container, copy bootc customization to it (osbuild/images#1571) * Author: Alexander Larsson, Reviewers: Achilleas Koutsou, Tomáš Hozza * manifest/ostree: explicitly include shadow-utils (osbuild/images#1585) * Author: Simon de Vlieger, Reviewers: Achilleas Koutsou, Michael Vogt * osbuild/tar: explicit compression (HMS-8573, HMS-6116) (osbuild/images#1581) * Author: Simon de Vlieger, Reviewers: Achilleas Koutsou, Tomáš Hozza * tests: bump fedora versions to 41 (osbuild/images#1438) * Author: Lukáš Zapletal, Reviewers: Brian C. Lane, Michael Vogt — Somewhere on the Internet, 2025-06-09 ---
217 lines
4.7 KiB
Go
217 lines
4.7 KiB
Go
package disk
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
"reflect"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/osbuild/images/internal/common"
|
|
"github.com/osbuild/images/pkg/datasizes"
|
|
)
|
|
|
|
const DefaultBtrfsCompression = "zstd:1"
|
|
|
|
type Btrfs struct {
|
|
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
|
|
Label string `json:"label,omitempty" yaml:"label,omitempty"`
|
|
Mountpoint string `json:"mountpoint,omitempty" yaml:"mountpoint,omitempty"`
|
|
Subvolumes []BtrfsSubvolume `json:"subvolumes,omitempty" yaml:"subvolumes,omitempty"`
|
|
}
|
|
|
|
func init() {
|
|
payloadEntityMap["btrfs"] = reflect.TypeOf(Btrfs{})
|
|
}
|
|
|
|
func (b *Btrfs) EntityName() string {
|
|
return "btrfs"
|
|
}
|
|
|
|
func (b *Btrfs) Clone() Entity {
|
|
if b == nil {
|
|
return nil
|
|
}
|
|
|
|
clone := &Btrfs{
|
|
UUID: b.UUID,
|
|
Label: b.Label,
|
|
Mountpoint: b.Mountpoint,
|
|
Subvolumes: make([]BtrfsSubvolume, len(b.Subvolumes)),
|
|
}
|
|
|
|
for idx, subvol := range b.Subvolumes {
|
|
entClone := subvol.Clone()
|
|
svClone, cloneOk := entClone.(*BtrfsSubvolume)
|
|
if !cloneOk {
|
|
panic("BtrfsSubvolume.Clone() returned an Entity that cannot be converted to *BtrfsSubvolume; this is a programming error")
|
|
}
|
|
clone.Subvolumes[idx] = *svClone
|
|
}
|
|
|
|
return clone
|
|
}
|
|
|
|
func (b *Btrfs) GetItemCount() uint {
|
|
return uint(len(b.Subvolumes))
|
|
}
|
|
|
|
func (b *Btrfs) GetChild(n uint) Entity {
|
|
return &b.Subvolumes[n]
|
|
}
|
|
func (b *Btrfs) CreateMountpoint(mountpoint string, size uint64) (Entity, error) {
|
|
name := mountpoint
|
|
if name == "/" {
|
|
name = "root"
|
|
}
|
|
subvolume := BtrfsSubvolume{
|
|
Size: size,
|
|
Mountpoint: mountpoint,
|
|
GroupID: 0,
|
|
UUID: b.UUID, // subvolumes inherit UUID of main volume
|
|
Name: name,
|
|
Compress: DefaultBtrfsCompression,
|
|
}
|
|
|
|
b.Subvolumes = append(b.Subvolumes, subvolume)
|
|
return &b.Subvolumes[len(b.Subvolumes)-1], nil
|
|
}
|
|
|
|
func (b *Btrfs) AlignUp(size uint64) uint64 {
|
|
return size // No extra alignment necessary for subvolumes
|
|
}
|
|
|
|
func (b *Btrfs) GenUUID(rng *rand.Rand) {
|
|
if b.UUID == "" {
|
|
b.UUID = uuid.Must(newRandomUUIDFromReader(rng)).String()
|
|
}
|
|
|
|
for i := range b.Subvolumes {
|
|
b.Subvolumes[i].UUID = b.UUID
|
|
}
|
|
}
|
|
|
|
func (b *Btrfs) MetadataSize() uint64 {
|
|
return 0
|
|
}
|
|
|
|
func (b *Btrfs) minSize(size uint64) uint64 {
|
|
var subvolsum uint64
|
|
for _, sv := range b.Subvolumes {
|
|
subvolsum += sv.Size
|
|
}
|
|
minSize := subvolsum + b.MetadataSize()
|
|
|
|
if minSize > size {
|
|
size = minSize
|
|
}
|
|
|
|
return b.AlignUp(size)
|
|
}
|
|
|
|
type BtrfsSubvolume struct {
|
|
Name string `json:"name" yaml:"name"`
|
|
Size uint64 `json:"size" yaml:"size"`
|
|
Mountpoint string `json:"mountpoint,omitempty" yaml:"mountpoint,omitempty"`
|
|
GroupID uint64 `json:"group_id,omitempty" yaml:"group_id,omitempty"`
|
|
Compress string `json:"compress,omitempty" yaml:"compress,omitempty"`
|
|
ReadOnly bool `json:"read_only,omitempty" yaml:"read_only,omitempty"`
|
|
|
|
// UUID of the parent volume
|
|
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
|
|
}
|
|
|
|
func (sv *BtrfsSubvolume) UnmarshalJSON(data []byte) (err error) {
|
|
data, err = datasizes.ParseSizeInJSONMapping("size", data)
|
|
if err != nil {
|
|
return fmt.Errorf("error parsing size in btrfs subvolume: %w", err)
|
|
}
|
|
|
|
type aliasStruct BtrfsSubvolume
|
|
var alias aliasStruct
|
|
if err := jsonUnmarshalStrict(data, &alias); err != nil {
|
|
return fmt.Errorf("cannot unmarshal %q: %w", data, err)
|
|
}
|
|
*sv = BtrfsSubvolume(alias)
|
|
return err
|
|
}
|
|
|
|
func (sv *BtrfsSubvolume) UnmarshalYAML(unmarshal func(any) error) error {
|
|
return common.UnmarshalYAMLviaJSON(sv, unmarshal)
|
|
}
|
|
|
|
func (bs *BtrfsSubvolume) Clone() Entity {
|
|
if bs == nil {
|
|
return nil
|
|
}
|
|
|
|
return &BtrfsSubvolume{
|
|
Name: bs.Name,
|
|
Size: bs.Size,
|
|
Mountpoint: bs.Mountpoint,
|
|
GroupID: bs.GroupID,
|
|
Compress: bs.Compress,
|
|
UUID: bs.UUID,
|
|
}
|
|
}
|
|
|
|
func (bs *BtrfsSubvolume) GetSize() uint64 {
|
|
if bs == nil {
|
|
return 0
|
|
}
|
|
return bs.Size
|
|
}
|
|
|
|
func (bs *BtrfsSubvolume) EnsureSize(s uint64) bool {
|
|
if s > bs.Size {
|
|
bs.Size = s
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (bs *BtrfsSubvolume) GetMountpoint() string {
|
|
if bs == nil {
|
|
return ""
|
|
}
|
|
return bs.Mountpoint
|
|
}
|
|
|
|
func (bs *BtrfsSubvolume) GetFSFile() string {
|
|
return bs.GetMountpoint()
|
|
}
|
|
|
|
func (bs *BtrfsSubvolume) GetFSType() string {
|
|
return "btrfs"
|
|
}
|
|
|
|
func (bs *BtrfsSubvolume) GetFSSpec() FSSpec {
|
|
if bs == nil {
|
|
return FSSpec{}
|
|
}
|
|
return FSSpec{
|
|
UUID: bs.UUID,
|
|
Label: bs.Name,
|
|
}
|
|
}
|
|
|
|
func (bs *BtrfsSubvolume) GetFSTabOptions() (FSTabOptions, error) {
|
|
if bs == nil {
|
|
return FSTabOptions{}, nil
|
|
}
|
|
|
|
if bs.Name == "" {
|
|
return FSTabOptions{}, fmt.Errorf("internal error: BtrfsSubvolume.GetFSTabOptions() for %+v called without a name", bs)
|
|
}
|
|
ops := fmt.Sprintf("subvol=%s", bs.Name)
|
|
if bs.Compress != "" {
|
|
ops += fmt.Sprintf(",compress=%s", bs.Compress)
|
|
}
|
|
if bs.ReadOnly {
|
|
ops += ",ro"
|
|
}
|
|
return FSTabOptions{
|
|
MntOps: ops,
|
|
Freq: 0,
|
|
PassNo: 0,
|
|
}, nil
|
|
}
|