Skip to content

Commit f2a0924

Browse files
committed
mantle/kola/qemuexec: Add a disk when booting from ISO
Most of the time people probably want to test an install workflow and they can't really do that if only the ISO is attached to the VM via a CDROM drive (read only media). Let's add a disk by default for convenience.
1 parent cf2e1ba commit f2a0924

File tree

2 files changed

+57
-32
lines changed

2 files changed

+57
-32
lines changed

mantle/cmd/kola/qemuexec.go

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,41 @@ func parseBindOpt(s string) (string, string, error) {
125125
return parts[0], parts[1], nil
126126
}
127127

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+
128163
func runQemuExec(cmd *cobra.Command, args []string) error {
129164
var err error
130165

@@ -283,36 +318,22 @@ func runQemuExec(cmd *cobra.Command, args []string) error {
283318
builder.Firmware = kola.QEMUOptions.Firmware
284319
}
285320
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
297323
}
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-
})
307324
if err != nil {
308325
return err
309326
}
310327
}
311328
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)
313330
if err != nil {
314331
return err
315332
}
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+
}
316337
}
317338
builder.Hostname = hostname
318339
// for historical reasons, both --memory and --qemu-memory are supported

mantle/platform/qemu.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,18 +1077,22 @@ func (builder *QemuBuilder) addDiskImpl(disk *Disk, primary bool) error {
10771077
return err
10781078
}
10791079
if primary {
1080-
// If the board doesn't support -fw_cfg or we were explicitly
1081-
// requested, inject via libguestfs on the primary disk.
1082-
if err := builder.renderIgnition(); err != nil {
1083-
return errors.Wrapf(err, "rendering ignition")
1084-
}
1085-
requiresInjection := builder.ConfigFile != "" && builder.ForceConfigInjection
1086-
if requiresInjection || builder.AppendFirstbootKernelArgs != "" || builder.AppendKernelArgs != "" {
1087-
if err := setupPreboot(builder.architecture, builder.ConfigFile, builder.AppendFirstbootKernelArgs, builder.AppendKernelArgs,
1088-
disk.dstFileName, disk.SectorSize); err != nil {
1089-
return errors.Wrapf(err, "ignition injection with guestfs failed")
1080+
// Only try to inject config if it hasn't already been injected somewhere
1081+
// else, which can happen when running an ISO install.
1082+
if !builder.configInjected {
1083+
// If the board doesn't support -fw_cfg or we were explicitly
1084+
// requested, inject via libguestfs on the primary disk.
1085+
if err := builder.renderIgnition(); err != nil {
1086+
return errors.Wrapf(err, "rendering ignition")
1087+
}
1088+
requiresInjection := builder.ConfigFile != "" && builder.ForceConfigInjection
1089+
if requiresInjection || builder.AppendFirstbootKernelArgs != "" || builder.AppendKernelArgs != "" {
1090+
if err := setupPreboot(builder.architecture, builder.ConfigFile, builder.AppendFirstbootKernelArgs, builder.AppendKernelArgs,
1091+
disk.dstFileName, disk.SectorSize); err != nil {
1092+
return errors.Wrapf(err, "ignition injection with guestfs failed")
1093+
}
1094+
builder.configInjected = true
10901095
}
1091-
builder.configInjected = true
10921096
}
10931097
}
10941098
diskOpts := disk.DeviceOpts

0 commit comments

Comments
 (0)