Skip to content

gce image type: disk.raw not guaranteed to be GiB-aligned, causing GCP import failures #2413

Description

@peteditmars

Problem

GCP requires that disk.raw files are aligned to a GiB boundary (a multiple of 1,073,741,824 bytes). The gce image type currently produces a disk.raw that may not satisfy this requirement, depending on the requested image size and filesystem layout. This causes GCP import to fail.

Root cause

In pkg/distro/generic/bootc_imagetype.go, genPartitionTableFsCust() uses imageSize derived from ImageTypeYAML.DefaultSize (or basept.Size) directly, without rounding up to the nearest GiB:

  // pkg/distro/generic/bootc_imagetype.go:918
  imageSize := t.ImageTypeYAML.DefaultSize
  if basept.Size != 0 {
      imageSize = basept.Size
  }
  return disk.NewPartitionTable(basept, fsCustomizations, imageSize, ...)

The gce entry in data/distrodefs/bootc-generic/imagetypes.yaml (lines 148–152) has no alignment constraint:

  "gce":
    <<: *raw_image_type
    filename: "image.tar.gz"
    mime_type: "application/gzip"
    exports: ["gce"]

Proposed fix

Option A (recommended) — align at partition table generation time

  1. Add a GiBAlignedDisk bool field to ImageTypeYAML in pkg/distro/defs/loader.go:
    GiBAlignedDisk bool yaml:"gib_aligned_disk"
  2. Set it in data/distrodefs/bootc-generic/imagetypes.yaml:
    "gce":
    <<: *raw_image_type
    filename: "image.tar.gz"
    mime_type: "application/gzip"
    exports: ["gce"]
    gib_aligned_disk: true
  3. In genPartitionTableFsCust(), round imageSize up before calling NewPartitionTable:
    if t.ImageTypeYAML.GiBAlignedDisk {
    imageSize = (imageSize + datasizes.GiB - 1) &^ (datasizes.GiB - 1)
    }

Option B — resize in the GCE pipeline

Add a truncate/pad stage in pkg/image/gce.go after the disk image is built and before the tar step. More invasive and happens after the fact rather than sizing correctly up front.

Why Option A

It ensures disk.raw is sized correctly from the start — no post-processing or repackaging needed. The datasizes.GiB constant (1 << 30) is already available in pkg/datasizes/constants.go.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions