Skip to content

Commit bad5296

Browse files
committed
run: Add --filesystem
In general, we should expose all available arguments for `bootc install`, including e.g. `--karg` etc. This reveals a general issue in that longer term, we are going to also need the ability to decouple the "container image <-> VM" binding; I should be able to create multiple different VMs in different configuration from the same container image.
1 parent bddf552 commit bad5296

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

cmd/run.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ var (
4141
SilenceUsage: true,
4242
}
4343

44-
vmConfig = osVmConfig{}
44+
vmConfig = osVmConfig{}
45+
diskImageConfigInstance = bootc.DiskImageConfig{}
4546
)
4647

4748
func init() {
@@ -50,6 +51,7 @@ func init() {
5051

5152
runCmd.Flags().StringVar(&vmConfig.CloudInitDir, "cloudinit", "", "--cloudinit <cloud-init data directory>")
5253

54+
runCmd.Flags().StringVar(&diskImageConfigInstance.Filesystem, "filesystem", "", "Override the root filesystem (e.g. xfs, btrfs, ext4)")
5355
runCmd.Flags().BoolVar(&vmConfig.NoCredentials, "no-creds", false, "Do not inject default SSH key via credentials; also implies --background")
5456
runCmd.Flags().BoolVarP(&vmConfig.Background, "background", "B", false, "Do not spawn SSH, run in background")
5557
runCmd.Flags().BoolVar(&vmConfig.RemoveVm, "rm", false, "Remove the VM and it's disk when the SSH session exits. Cannot be used with --background")
@@ -99,7 +101,7 @@ func doRun(flags *cobra.Command, args []string) error {
99101
// create the disk image
100102
idOrName := args[0]
101103
bootcDisk := bootc.NewBootcDisk(idOrName, ctx, user)
102-
err = bootcDisk.Install(vmConfig.Quiet)
104+
err = bootcDisk.Install(vmConfig.Quiet, diskImageConfigInstance)
103105

104106
if err != nil {
105107
return fmt.Errorf("unable to install bootc image: %w", err)

pkg/bootc/bootc_disk.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ const containerSizeToDiskSizeMultiplier = 2
3232
const diskSizeMinimum = 10 * 1024 * 1024 * 1024 // 10GB
3333
const imageMetaXattr = "user.bootc.meta"
3434

35+
// DiskImageConfig defines configuration for the
36+
type DiskImageConfig struct {
37+
Filesystem string
38+
}
39+
3540
// diskFromContainerMeta is serialized to JSON in a user xattr on a disk image
3641
type diskFromContainerMeta struct {
3742
// imageDigest is the digested sha256 of the container that was used to build this disk
@@ -96,7 +101,7 @@ func (p *BootcDisk) GetCreatedAt() time.Time {
96101
return p.CreatedAt
97102
}
98103

99-
func (p *BootcDisk) Install(quiet bool) (err error) {
104+
func (p *BootcDisk) Install(quiet bool, config DiskImageConfig) (err error) {
100105
p.CreatedAt = time.Now()
101106

102107
err = p.pullImage()
@@ -125,7 +130,7 @@ func (p *BootcDisk) Install(quiet bool) (err error) {
125130
return fmt.Errorf("error while making bootc disk directory: %w", err)
126131
}
127132

128-
err = p.getOrInstallImageToDisk(quiet)
133+
err = p.getOrInstallImageToDisk(quiet, config)
129134
if err != nil {
130135
return
131136
}
@@ -149,15 +154,15 @@ func (p *BootcDisk) Cleanup() (err error) {
149154
}
150155

151156
// getOrInstallImageToDisk checks if the disk is present and if not, installs the image to a new disk
152-
func (p *BootcDisk) getOrInstallImageToDisk(quiet bool) error {
157+
func (p *BootcDisk) getOrInstallImageToDisk(quiet bool, diskConfig DiskImageConfig) error {
153158
diskPath := filepath.Join(p.Directory, config.DiskImage)
154159
f, err := os.Open(diskPath)
155160
if err != nil {
156161
if !errors.Is(err, os.ErrNotExist) {
157162
return err
158163
}
159164
logrus.Debugf("No existing disk image found")
160-
return p.bootcInstallImageToDisk(quiet)
165+
return p.bootcInstallImageToDisk(quiet, diskConfig)
161166
}
162167
logrus.Debug("Found existing disk image, comparing digest")
163168
defer f.Close()
@@ -167,21 +172,21 @@ func (p *BootcDisk) getOrInstallImageToDisk(quiet bool) error {
167172
// If there's no xattr, just remove it
168173
os.Remove(diskPath)
169174
logrus.Debugf("No %s xattr found", imageMetaXattr)
170-
return p.bootcInstallImageToDisk(quiet)
175+
return p.bootcInstallImageToDisk(quiet, diskConfig)
171176
}
172177
bufTrimmed := buf[:len]
173178
var serializedMeta diskFromContainerMeta
174179
if err := json.Unmarshal(bufTrimmed, &serializedMeta); err != nil {
175180
logrus.Warnf("failed to parse serialized meta from %s (%v) %v", diskPath, buf, err)
176-
return p.bootcInstallImageToDisk(quiet)
181+
return p.bootcInstallImageToDisk(quiet, diskConfig)
177182
}
178183

179184
logrus.Debugf("previous disk digest: %s current digest: %s", serializedMeta.ImageDigest, p.ImageId)
180185
if serializedMeta.ImageDigest == p.ImageId {
181186
return nil
182187
}
183188

184-
return p.bootcInstallImageToDisk(quiet)
189+
return p.bootcInstallImageToDisk(quiet, diskConfig)
185190
}
186191

187192
func align(size int64, align int64) int64 {
@@ -193,7 +198,7 @@ func align(size int64, align int64) int64 {
193198
}
194199

195200
// bootcInstallImageToDisk creates a disk image from a bootc container
196-
func (p *BootcDisk) bootcInstallImageToDisk(quiet bool) (err error) {
201+
func (p *BootcDisk) bootcInstallImageToDisk(quiet bool, diskConfig DiskImageConfig) (err error) {
197202
fmt.Printf("Executing `bootc install to-disk` from container image %s to create disk image\n", p.RepoTag)
198203
p.file, err = os.CreateTemp(p.Directory, "podman-bootc-tempdisk")
199204
if err != nil {
@@ -218,7 +223,7 @@ func (p *BootcDisk) bootcInstallImageToDisk(quiet bool) (err error) {
218223
}
219224
}()
220225

221-
err = p.runInstallContainer(quiet)
226+
err = p.runInstallContainer(quiet, diskConfig)
222227
if err != nil {
223228
return fmt.Errorf("failed to create disk image: %w", err)
224229
}
@@ -272,8 +277,8 @@ func (p *BootcDisk) pullImage() (err error) {
272277
}
273278

274279
// runInstallContainer runs the bootc installer in a container to create a disk image
275-
func (p *BootcDisk) runInstallContainer(quiet bool) (err error) {
276-
createResponse, err := p.createInstallContainer()
280+
func (p *BootcDisk) runInstallContainer(quiet bool, config DiskImageConfig) (err error) {
281+
createResponse, err := p.createInstallContainer(config)
277282
if err != nil {
278283
return fmt.Errorf("failed to create container: %w", err)
279284
}
@@ -355,7 +360,7 @@ func (p *BootcDisk) runInstallContainer(quiet bool) (err error) {
355360
}
356361

357362
// createInstallContainer creates a container to run the bootc installer
358-
func (p *BootcDisk) createInstallContainer() (createResponse types.ContainerCreateResponse, err error) {
363+
func (p *BootcDisk) createInstallContainer(config DiskImageConfig) (createResponse types.ContainerCreateResponse, err error) {
359364
privileged := true
360365
autoRemove := true
361366
labelNested := true
@@ -365,12 +370,18 @@ func (p *BootcDisk) createInstallContainer() (createResponse types.ContainerCrea
365370
targetEnv["RUST_LOG"] = v
366371
}
367372

373+
bootcInstallArgs := []string{
374+
"bootc", "install", "to-disk", "--via-loopback", "--generic-image",
375+
"--skip-fetch-check",
376+
}
377+
if config.Filesystem != "" {
378+
bootcInstallArgs = append(bootcInstallArgs, "--filesystem", config.Filesystem)
379+
}
380+
bootcInstallArgs = append(bootcInstallArgs, "/output/"+filepath.Base(p.file.Name()))
381+
368382
s := &specgen.SpecGenerator{
369383
ContainerBasicConfig: specgen.ContainerBasicConfig{
370-
Command: []string{
371-
"bootc", "install", "to-disk", "--via-loopback", "--generic-image",
372-
"--skip-fetch-check", "/output/" + filepath.Base(p.file.Name()),
373-
},
384+
Command: bootcInstallArgs,
374385
PidNS: specgen.Namespace{NSMode: specgen.Host},
375386
Remove: &autoRemove,
376387
Annotations: map[string]string{"io.podman.annotations.label": "type:unconfined_t"},

0 commit comments

Comments
 (0)