diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index 14cbafb22..bd008548b 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -44,6 +44,14 @@ type Config struct { vboxcommon.VBoxVersionConfig `mapstructure:",squash"` vboxcommon.VBoxBundleConfig `mapstructure:",squash"` vboxcommon.GuestAdditionsConfig `mapstructure:",squash"` + // The chipset to be used: PIIX3 or ICH9. + // When set to piix3, the firmare is PIIX3. This is the default. + // When set to ich9, the firmare is ICH9. + Chipset string `mapstructure:"chipset" required:"false"` + // The firmware to be used: BIOS or EFI. + // When set to bios, the firmare is BIOS. This is the default. + // When set to efi, the firmare is EFI. + Firmware string `mapstructure:"firmware" required:"false"` // The size, in megabytes, of the hard disk to create for the VM. By // default, this is 40000 (about 40 GB). DiskSize uint `mapstructure:"disk_size" required:"false"` @@ -162,6 +170,28 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { errs = packersdk.MultiErrorAppend(errs, b.config.BootConfig.Prepare(&b.config.ctx)...) errs = packersdk.MultiErrorAppend(errs, b.config.GuestAdditionsConfig.Prepare(b.config.CommConfig.Comm.Type)...) + if b.config.Chipset == "" { + b.config.Chipset = "piix3" + } + switch b.config.Chipset { + case "piix3", "ich9": + // do nothing + default: + errs = packersdk.MultiErrorAppend( + errs, errors.New("chipset can only be piix3 or ich9")) + } + + if b.config.Firmware == "" { + b.config.Firmware = "bios" + } + switch b.config.Firmware { + case "bios", "efi": + // do nothing + default: + errs = packersdk.MultiErrorAppend( + errs, errors.New("firmware can only be bios or efi")) + } + if b.config.DiskSize == 0 { b.config.DiskSize = 40000 } diff --git a/builder/virtualbox/iso/builder.hcl2spec.go b/builder/virtualbox/iso/builder.hcl2spec.go index a931724c1..04faf34f6 100644 --- a/builder/virtualbox/iso/builder.hcl2spec.go +++ b/builder/virtualbox/iso/builder.hcl2spec.go @@ -117,6 +117,8 @@ type FlatConfig struct { GuestAdditionsPath *string `mapstructure:"guest_additions_path" cty:"guest_additions_path" hcl:"guest_additions_path"` GuestAdditionsSHA256 *string `mapstructure:"guest_additions_sha256" cty:"guest_additions_sha256" hcl:"guest_additions_sha256"` GuestAdditionsURL *string `mapstructure:"guest_additions_url" required:"false" cty:"guest_additions_url" hcl:"guest_additions_url"` + Chipset *string `mapstructure:"chipset" required:"false" cty:"chipset" hcl:"chipset"` + Firmware *string `mapstructure:"firmware" required:"false" cty:"firmware" hcl:"firmware"` DiskSize *uint `mapstructure:"disk_size" required:"false" cty:"disk_size" hcl:"disk_size"` GuestOSType *string `mapstructure:"guest_os_type" required:"false" cty:"guest_os_type" hcl:"guest_os_type"` HardDriveDiscard *bool `mapstructure:"hard_drive_discard" required:"false" cty:"hard_drive_discard" hcl:"hard_drive_discard"` @@ -249,6 +251,8 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "guest_additions_path": &hcldec.AttrSpec{Name: "guest_additions_path", Type: cty.String, Required: false}, "guest_additions_sha256": &hcldec.AttrSpec{Name: "guest_additions_sha256", Type: cty.String, Required: false}, "guest_additions_url": &hcldec.AttrSpec{Name: "guest_additions_url", Type: cty.String, Required: false}, + "chipset": &hcldec.AttrSpec{Name: "chipset", Type: cty.String, Required: false}, + "firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false}, "disk_size": &hcldec.AttrSpec{Name: "disk_size", Type: cty.Number, Required: false}, "guest_os_type": &hcldec.AttrSpec{Name: "guest_os_type", Type: cty.String, Required: false}, "hard_drive_discard": &hcldec.AttrSpec{Name: "hard_drive_discard", Type: cty.Bool, Required: false}, diff --git a/builder/virtualbox/iso/step_create_vm.go b/builder/virtualbox/iso/step_create_vm.go index 15a049a12..5cce54db9 100644 --- a/builder/virtualbox/iso/step_create_vm.go +++ b/builder/virtualbox/iso/step_create_vm.go @@ -26,7 +26,7 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis name := config.VMName - commands := make([][]string, 6) + commands := make([][]string, 8) commands[0] = []string{ "createvm", "--name", name, "--ostype", config.GuestOSType, "--register", @@ -45,6 +45,9 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound, "--audioin", "on", "--audioout", "on"} } + commands[6] = []string{"modifyvm", name, "--chipset", config.Chipset} + commands[7] = []string{"modifyvm", name, "--firmware", config.Firmware} + ui.Say("Creating virtual machine...") for _, command := range commands { err := driver.VBoxManage(command...)