@@ -125,6 +125,41 @@ func parseBindOpt(s string) (string, string, error) {
125
125
return parts [0 ], parts [1 ], nil
126
126
}
127
127
128
+ // buildDiskFromOptions generates a disk image template using the process-global
129
+ // defaults that were parsed from command line arguments.
130
+ func buildDiskFromOptions () * platform.Disk {
131
+ channel := "virtio"
132
+ if kola .QEMUOptions .Nvme {
133
+ channel = "nvme"
134
+ }
135
+ sectorSize := 0
136
+ if kola .QEMUOptions .Native4k {
137
+ sectorSize = 4096
138
+ }
139
+ options := []string {}
140
+ if kola .QEMUOptions .DriveOpts != "" {
141
+ options = append (options , strings .Split (kola .QEMUOptions .DriveOpts , "," )... )
142
+ }
143
+ // If there was no disk image specified and no size then just
144
+ // default to an arbitrary value of 12G for the blank disk image.
145
+ size := kola .QEMUOptions .DiskSize
146
+ if kola .QEMUOptions .DiskImage == "" && kola .QEMUOptions .DiskSize == "" {
147
+ size = "12G"
148
+ }
149
+ // Build the disk definition. Note that if kola.QEMUOptions.DiskImage is
150
+ // "" we'll just end up with a blank disk image, which is what we want.
151
+ disk := & platform.Disk {
152
+ BackingFile : kola .QEMUOptions .DiskImage ,
153
+ Channel : channel ,
154
+ Size : size ,
155
+ SectorSize : sectorSize ,
156
+ DriveOpts : options ,
157
+ MultiPathDisk : kola .QEMUOptions .MultiPathDisk ,
158
+ NbdDisk : kola .QEMUOptions .NbdDisk ,
159
+ }
160
+ return disk
161
+ }
162
+
128
163
func runQemuExec (cmd * cobra.Command , args []string ) error {
129
164
var err error
130
165
@@ -283,36 +318,22 @@ func runQemuExec(cmd *cobra.Command, args []string) error {
283
318
builder .Firmware = kola .QEMUOptions .Firmware
284
319
}
285
320
if kola .QEMUOptions .DiskImage != "" {
286
- channel := "virtio"
287
- if kola .QEMUOptions .Nvme {
288
- channel = "nvme"
289
- }
290
- sectorSize := 0
291
- if kola .QEMUOptions .Native4k {
292
- sectorSize = 4096
293
- }
294
- options := []string {}
295
- if kola .QEMUOptions .DriveOpts != "" {
296
- options = append (options , strings .Split (kola .QEMUOptions .DriveOpts , "," )... )
321
+ if err := builder .AddBootDisk (buildDiskFromOptions ()); err != nil {
322
+ return err
297
323
}
298
- err = builder .AddBootDisk (& platform.Disk {
299
- BackingFile : kola .QEMUOptions .DiskImage ,
300
- Channel : channel ,
301
- Size : kola .QEMUOptions .DiskSize ,
302
- SectorSize : sectorSize ,
303
- DriveOpts : options ,
304
- MultiPathDisk : kola .QEMUOptions .MultiPathDisk ,
305
- NbdDisk : kola .QEMUOptions .NbdDisk ,
306
- })
307
324
if err != nil {
308
325
return err
309
326
}
310
327
}
311
328
if kola .QEMUIsoOptions .IsoPath != "" {
312
- err := builder .AddIso (kola .QEMUIsoOptions .IsoPath , "" , kola .QEMUIsoOptions .AsDisk )
329
+ err := builder .AddIso (kola .QEMUIsoOptions .IsoPath , "bootindex=3 " , kola .QEMUIsoOptions .AsDisk )
313
330
if err != nil {
314
331
return err
315
332
}
333
+ // Add a blank disk (this is a disk we can install to)
334
+ if err := builder .AddBootDisk (buildDiskFromOptions ()); err != nil {
335
+ return err
336
+ }
316
337
}
317
338
builder .Hostname = hostname
318
339
// for historical reasons, both --memory and --qemu-memory are supported
0 commit comments