Skip to content

Commit

Permalink
Add an option flag to allow using a pflash for firmware
Browse files Browse the repository at this point in the history
Since the merge of hashicorp#43 any script with a firmware setting, will
use an `-drive if=pflash` option instead of `-bios` when calling
QEMU, which has been shown to be problematic.

Implement a new option `pflash` instead, that could be set to
true for when that would be preferred (ex: when using a custom
firmware with variables), but use the old interface by default.

Fixes: hashicorp#66
  • Loading branch information
carenas committed Apr 8, 2022
1 parent 3615662 commit 79bad4a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
14 changes: 10 additions & 4 deletions builder/qemu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,18 @@ type Config struct {
// The number of cpus to use when building the VM.
// The default is `1` CPU.
CpuCount int `mapstructure:"cpus" required:"false"`
// The firmware file to be used by QEMU, which is to be set by the -bios
// option of QEMU. Particularly, this option can be set to use EFI instead
// of BIOS, by using "OVMF.fd" from OpenFirmware.
// If unset, no -bios option is passed to QEMU, using the default of QEMU.
// The firmware file to be used by QEMU
// this option could be set to use EFI instead of BIOS,
// by using "OVMF.fd" from OpenFirmware, for example.
// If unset, QEMU will load its default firmware.
// Also see the QEMU documentation.
Firmware string `mapstructure:"firmware" required:"false"`
// If a firmware file option was provided, this option can be
// used to change how qemu will get it.
// If false (the default), then the firmware is provided through
// the -bios option, but if true, a pflash drive will be used
// instead.
PFlash bool `mapstructure:"use_pflash" required:"false"`
// The interface to use for the disk. Allowed values include any of `ide`,
// `sata`, `scsi`, `virtio` or `virtio-scsi`^\*. Note also that any boot
// commands or kickstart type scripts must have proper adjustments for
Expand Down
2 changes: 2 additions & 0 deletions builder/qemu/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion builder/qemu/step_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func (s *stepRun) getDefaultArgs(config *Config, state multistep.StateBag) map[s
config.MachineType, config.Accelerator)
}

// Firmware
if config.Firmware != "" && !config.PFlash {
defaultArgs["-bios"] = config.Firmware
}

// Configure "-netdev" arguments
defaultArgs["-netdev"] = fmt.Sprintf("bridge,id=user.0,br=%s", config.NetBridge)
if config.NetBridge == "" {
Expand Down Expand Up @@ -275,7 +280,7 @@ func (s *stepRun) getDeviceAndDriveArgs(config *Config, state multistep.StateBag
}
}
// Firmware
if config.Firmware != "" {
if config.Firmware != "" && config.PFlash {
driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=pflash,format=raw,readonly=on", config.Firmware))
}

Expand Down
14 changes: 10 additions & 4 deletions docs-partials/builder/qemu/Config-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@
- `cpus` (int) - The number of cpus to use when building the VM.
The default is `1` CPU.

- `firmware` (string) - The firmware file to be used by QEMU, which is to be set by the -bios
option of QEMU. Particularly, this option can be set to use EFI instead
of BIOS, by using "OVMF.fd" from OpenFirmware.
If unset, no -bios option is passed to QEMU, using the default of QEMU.
- `firmware` (string) - The firmware file to be used by QEMU
this option could be set to use EFI instead of BIOS,
by using "OVMF.fd" from OpenFirmware, for example.
If unset, QEMU will load its default firmware.
Also see the QEMU documentation.

- `use_pflash` (bool) - If a firmware file option was provided, this option can be
used to change how qemu will get it.
If false (the default), then the firmware is provided through
the -bios option, but if true, a pflash drive will be used
instead.

- `disk_interface` (string) - The interface to use for the disk. Allowed values include any of `ide`,
`sata`, `scsi`, `virtio` or `virtio-scsi`^\*. Note also that any boot
commands or kickstart type scripts must have proper adjustments for
Expand Down

0 comments on commit 79bad4a

Please sign in to comment.