Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 19 additions & 2 deletions pkg/bootc/bootc_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down