@@ -32,6 +32,11 @@ const containerSizeToDiskSizeMultiplier = 2
32
32
const diskSizeMinimum = 10 * 1024 * 1024 * 1024 // 10GB
33
33
const imageMetaXattr = "user.bootc.meta"
34
34
35
+ // DiskImageConfig defines configuration for the
36
+ type DiskImageConfig struct {
37
+ Filesystem string
38
+ }
39
+
35
40
// diskFromContainerMeta is serialized to JSON in a user xattr on a disk image
36
41
type diskFromContainerMeta struct {
37
42
// 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 {
96
101
return p .CreatedAt
97
102
}
98
103
99
- func (p * BootcDisk ) Install (quiet bool ) (err error ) {
104
+ func (p * BootcDisk ) Install (quiet bool , config DiskImageConfig ) (err error ) {
100
105
p .CreatedAt = time .Now ()
101
106
102
107
err = p .pullImage ()
@@ -125,7 +130,7 @@ func (p *BootcDisk) Install(quiet bool) (err error) {
125
130
return fmt .Errorf ("error while making bootc disk directory: %w" , err )
126
131
}
127
132
128
- err = p .getOrInstallImageToDisk (quiet )
133
+ err = p .getOrInstallImageToDisk (quiet , config )
129
134
if err != nil {
130
135
return
131
136
}
@@ -149,15 +154,15 @@ func (p *BootcDisk) Cleanup() (err error) {
149
154
}
150
155
151
156
// 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 {
153
158
diskPath := filepath .Join (p .Directory , config .DiskImage )
154
159
f , err := os .Open (diskPath )
155
160
if err != nil {
156
161
if ! errors .Is (err , os .ErrNotExist ) {
157
162
return err
158
163
}
159
164
logrus .Debugf ("No existing disk image found" )
160
- return p .bootcInstallImageToDisk (quiet )
165
+ return p .bootcInstallImageToDisk (quiet , diskConfig )
161
166
}
162
167
logrus .Debug ("Found existing disk image, comparing digest" )
163
168
defer f .Close ()
@@ -167,21 +172,21 @@ func (p *BootcDisk) getOrInstallImageToDisk(quiet bool) error {
167
172
// If there's no xattr, just remove it
168
173
os .Remove (diskPath )
169
174
logrus .Debugf ("No %s xattr found" , imageMetaXattr )
170
- return p .bootcInstallImageToDisk (quiet )
175
+ return p .bootcInstallImageToDisk (quiet , diskConfig )
171
176
}
172
177
bufTrimmed := buf [:len ]
173
178
var serializedMeta diskFromContainerMeta
174
179
if err := json .Unmarshal (bufTrimmed , & serializedMeta ); err != nil {
175
180
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 )
177
182
}
178
183
179
184
logrus .Debugf ("previous disk digest: %s current digest: %s" , serializedMeta .ImageDigest , p .ImageId )
180
185
if serializedMeta .ImageDigest == p .ImageId {
181
186
return nil
182
187
}
183
188
184
- return p .bootcInstallImageToDisk (quiet )
189
+ return p .bootcInstallImageToDisk (quiet , diskConfig )
185
190
}
186
191
187
192
func align (size int64 , align int64 ) int64 {
@@ -193,7 +198,7 @@ func align(size int64, align int64) int64 {
193
198
}
194
199
195
200
// 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 ) {
197
202
fmt .Printf ("Executing `bootc install to-disk` from container image %s to create disk image\n " , p .RepoTag )
198
203
p .file , err = os .CreateTemp (p .Directory , "podman-bootc-tempdisk" )
199
204
if err != nil {
@@ -218,7 +223,7 @@ func (p *BootcDisk) bootcInstallImageToDisk(quiet bool) (err error) {
218
223
}
219
224
}()
220
225
221
- err = p .runInstallContainer (quiet )
226
+ err = p .runInstallContainer (quiet , diskConfig )
222
227
if err != nil {
223
228
return fmt .Errorf ("failed to create disk image: %w" , err )
224
229
}
@@ -272,8 +277,8 @@ func (p *BootcDisk) pullImage() (err error) {
272
277
}
273
278
274
279
// 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 )
277
282
if err != nil {
278
283
return fmt .Errorf ("failed to create container: %w" , err )
279
284
}
@@ -355,7 +360,7 @@ func (p *BootcDisk) runInstallContainer(quiet bool) (err error) {
355
360
}
356
361
357
362
// 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 ) {
359
364
privileged := true
360
365
autoRemove := true
361
366
labelNested := true
@@ -365,12 +370,18 @@ func (p *BootcDisk) createInstallContainer() (createResponse types.ContainerCrea
365
370
targetEnv ["RUST_LOG" ] = v
366
371
}
367
372
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
+
368
382
s := & specgen.SpecGenerator {
369
383
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 ,
374
385
PidNS : specgen.Namespace {NSMode : specgen .Host },
375
386
Remove : & autoRemove ,
376
387
Annotations : map [string ]string {"io.podman.annotations.label" : "type:unconfined_t" },
0 commit comments