From 0f348301d98c5e38567810ff17447e883bf6289b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 1 Apr 2025 12:15:00 +0200 Subject: [PATCH] main: add base partition table to `describe-image` This commit adds the (base) partition table to the `describe-image` command. It needs https://github.com/osbuild/images/pull/1376 It currently looks like: ```yaml $ image-builder describe-image qcow2 --distro fedora-41 @WARNING - the output format is not stable yet and may change distro: fedora-41 ... partition_table: uuid: D209C89E-EA5E-4FBD-B161-B461CCE297E0 type: gpt partitions: - size: 1048576 type: 21686148-6449-6E6F-744E-656564454649 bootable: true uuid: FAC7F1FB-3E8D-4137-A512-961DE09A5549 - size: 209715200 type: C12A7328-F81F-11D2-BA4B-00A0C93EC93B uuid: 68B2905B-DF3E-4FB3-80FA-49D1E773AA33 payload: type: vfat uuid: 7B77-95E7 label: EFI-SYSTEM mountpoint: /boot/efi fstab_options: defaults,uid=0,gid=0,umask=077,shortname=winnt fstab_passno: 2 - size: 524288000 type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 uuid: CB07C243-BC44-4717-853E-28852021225B payload: type: ext4 label: boot mountpoint: /boot fstab_options: defaults - size: 2147483648 type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 uuid: 6264D520-3FB9-423F-8AB8-7A0A8E3D3562 payload: type: ext4 label: root mountpoint: / fstab_options: defaults ``` --- cmd/image-builder/describeimg.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/image-builder/describeimg.go b/cmd/image-builder/describeimg.go index 29ba679..c9d10cd 100644 --- a/cmd/image-builder/describeimg.go +++ b/cmd/image-builder/describeimg.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "slices" @@ -8,7 +9,9 @@ import ( "gopkg.in/yaml.v3" "github.com/osbuild/images/pkg/blueprint" + "github.com/osbuild/images/pkg/disk" "github.com/osbuild/images/pkg/distro" + "github.com/osbuild/images/pkg/distro/defs" "github.com/osbuild/images/pkg/imagefilter" ) @@ -31,6 +34,8 @@ type describeImgYAML struct { BuildPipelines []string `yaml:"build_pipelines"` PayloadPipelines []string `yaml:"payload_pipelines"` Packages map[string]*packagesYAML `yaml:"packages"` + + PartitionTable *disk.PartitionTable `yaml:"partition_table,omitempty"` } type packagesYAML struct { @@ -86,6 +91,10 @@ func describeImage(img *imagefilter.Result, out io.Writer) error { if err != nil { return err } + partTable, err := img.ImgType.BasePartitionTable() + if err != nil && !errors.Is(err, defs.ErrNoPartitionTableForImgType) { + return err + } outYaml := &describeImgYAML{ Distro: img.Distro.Name(), @@ -98,6 +107,7 @@ func describeImage(img *imagefilter.Result, out io.Writer) error { BuildPipelines: img.ImgType.BuildPipelines(), PayloadPipelines: img.ImgType.PayloadPipelines(), Packages: pkgSets, + PartitionTable: partTable, } // deliberately break the yaml until the feature is stable fmt.Fprint(out, "@WARNING - the output format is not stable yet and may change\n")