diff --git a/cmd/run.go b/cmd/run.go index 51bc7d20..fbc83740 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -56,6 +56,8 @@ func init() { runCmd.Flags().BoolVarP(&vmConfig.Background, "background", "B", false, "Do not spawn SSH, run in background") runCmd.Flags().BoolVar(&vmConfig.RemoveVm, "rm", false, "Remove the VM and it's disk when the SSH session exits. Cannot be used with --background") runCmd.Flags().BoolVar(&vmConfig.Quiet, "quiet", false, "Suppress output from bootc disk creation and VM boot console") + runCmd.Flags().StringVar(&diskImageConfigInstance.RootSizeMax, "root-size-max", "", "Maximum size of root filesystem in bytes; optionally accepts M, G, T suffixes") + runCmd.Flags().StringVar(&diskImageConfigInstance.DiskSize, "disk-size", "", "Allocate a disk image of this size in bytes; optionally accepts M, G, T suffixes") } func doRun(flags *cobra.Command, args []string) error { diff --git a/pkg/bootc/bootc_disk.go b/pkg/bootc/bootc_disk.go index 2839384b..9f38a75a 100644 --- a/pkg/bootc/bootc_disk.go +++ b/pkg/bootc/bootc_disk.go @@ -21,6 +21,7 @@ import ( "github.com/containers/podman/v5/pkg/bindings/images" "github.com/containers/podman/v5/pkg/domain/entities/types" "github.com/containers/podman/v5/pkg/specgen" + "github.com/docker/go-units" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" "golang.org/x/sys/unix" @@ -49,7 +50,9 @@ exec /usr/sbin/losetup "$@" --direct-io=off // DiskImageConfig defines configuration for the type DiskImageConfig struct { - Filesystem string + Filesystem string + RootSizeMax string + DiskSize string } // diskFromContainerMeta is serialized to JSON in a user xattr on a disk image @@ -223,9 +226,20 @@ func (p *BootcDisk) bootcInstallImageToDisk(quiet bool, diskConfig DiskImageConf if size < diskSizeMinimum { size = diskSizeMinimum } + if diskConfig.DiskSize != "" { + diskConfigSize, err := units.FromHumanSize(diskConfig.DiskSize) + if err != nil { + return err + } + if size < diskConfigSize { + size = diskConfigSize + } + } // Round up to 4k; loopback wants at least 512b alignment size = align(size, 4096) - logrus.Debugf("container size: %d, disk size: %d", p.imageData.Size, size) + humanContainerSize := units.HumanSize(float64(p.imageData.Size)) + humanSize := units.HumanSize(float64(size)) + logrus.Infof("container size: %s, disk size: %s", humanContainerSize, humanSize) if err := syscall.Ftruncate(int(p.file.Fd()), size); err != nil { return err @@ -405,6 +419,9 @@ func (p *BootcDisk) createInstallContainer(config DiskImageConfig, tempLosetup s if config.Filesystem != "" { bootcInstallArgs = append(bootcInstallArgs, "--filesystem", config.Filesystem) } + if config.RootSizeMax != "" { + bootcInstallArgs = append(bootcInstallArgs, "--root-size="+config.RootSizeMax) + } bootcInstallArgs = append(bootcInstallArgs, "/output/"+filepath.Base(p.file.Name())) s := &specgen.SpecGenerator{