Skip to content

Commit 5da347d

Browse files
committed
run: Add support for disk and rootfs controls
The goal is to be able to trivially replicate locally a "cloud-like" scenario where: - The rootfs is capped to some default size at disk image generation time - The infrastructure provides a larger block device at boot time Signed-off-by: Colin Walters <[email protected]>
1 parent cab6b87 commit 5da347d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

cmd/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func init() {
5656
runCmd.Flags().BoolVarP(&vmConfig.Background, "background", "B", false, "Do not spawn SSH, run in background")
5757
runCmd.Flags().BoolVar(&vmConfig.RemoveVm, "rm", false, "Remove the VM and it's disk when the SSH session exits. Cannot be used with --background")
5858
runCmd.Flags().BoolVar(&vmConfig.Quiet, "quiet", false, "Suppress output from bootc disk creation and VM boot console")
59+
runCmd.Flags().StringVar(&diskImageConfigInstance.RootSizeMax, "root-size-max", "", "Maximum size of root filesystem in bytes; optionally accepts M, G, T suffixes")
60+
runCmd.Flags().StringVar(&diskImageConfigInstance.DiskSize, "disk-size", "", "Allocate a disk image of this size in bytes; optionally accepts M, G, T suffixes")
5961
}
6062

6163
func doRun(flags *cobra.Command, args []string) error {

pkg/bootc/bootc_disk.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/containers/podman/v5/pkg/bindings/images"
2222
"github.com/containers/podman/v5/pkg/domain/entities/types"
2323
"github.com/containers/podman/v5/pkg/specgen"
24+
"github.com/docker/go-units"
2425
specs "github.com/opencontainers/runtime-spec/specs-go"
2526
"github.com/sirupsen/logrus"
2627
"golang.org/x/sys/unix"
@@ -49,7 +50,9 @@ exec /usr/sbin/losetup "$@" --direct-io=off
4950

5051
// DiskImageConfig defines configuration for the
5152
type DiskImageConfig struct {
52-
Filesystem string
53+
Filesystem string
54+
RootSizeMax string
55+
DiskSize string
5356
}
5457

5558
// 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
223226
if size < diskSizeMinimum {
224227
size = diskSizeMinimum
225228
}
229+
if diskConfig.DiskSize != "" {
230+
diskConfigSize, err := units.FromHumanSize(diskConfig.DiskSize)
231+
if err != nil {
232+
return err
233+
}
234+
if size < diskConfigSize {
235+
size = diskConfigSize
236+
}
237+
}
226238
// Round up to 4k; loopback wants at least 512b alignment
227239
size = align(size, 4096)
228-
logrus.Debugf("container size: %d, disk size: %d", p.imageData.Size, size)
240+
humanContainerSize := units.HumanSize(float64(p.imageData.Size))
241+
humanSize := units.HumanSize(float64(size))
242+
logrus.Infof("container size: %s, disk size: %s", humanContainerSize, humanSize)
229243

230244
if err := syscall.Ftruncate(int(p.file.Fd()), size); err != nil {
231245
return err
@@ -405,6 +419,9 @@ func (p *BootcDisk) createInstallContainer(config DiskImageConfig, tempLosetup s
405419
if config.Filesystem != "" {
406420
bootcInstallArgs = append(bootcInstallArgs, "--filesystem", config.Filesystem)
407421
}
422+
if config.RootSizeMax != "" {
423+
bootcInstallArgs = append(bootcInstallArgs, "--root-size="+config.RootSizeMax)
424+
}
408425
bootcInstallArgs = append(bootcInstallArgs, "/output/"+filepath.Base(p.file.Name()))
409426

410427
s := &specgen.SpecGenerator{

0 commit comments

Comments
 (0)