diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index c82c435e0..ba2507ef1 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -52,6 +52,14 @@ type Config struct { // 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"` + // Nested virtualization: false or true. + // When set to true, nested virtualisation (VT-x/AMD-V) is enabled. + // When set to false, nested virtualisation is disabled. This is the default. + NestedVirt bool `mapstructure:"nested_virt" required:"false"` + // RTC time base: UTC or local. + // When set to true, the RTC is set as UTC time. + // When set to false, the RTC is set as local time. This is the default. + RTCTimeBase string `mapstructure:"rtc_time_base" 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"` @@ -212,6 +220,17 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { errs, errors.New("firmware can only be bios or efi")) } + if b.config.RTCTimeBase == "" { + b.config.RTCTimeBase = "local" + } + switch b.config.RTCTimeBase { + case "UTC", "local": + // do nothing + default: + errs = packersdk.MultiErrorAppend( + errs, errors.New("rtc_time_base can only be UTC or local")) + } + if b.config.DiskSize == 0 { b.config.DiskSize = 40000 } diff --git a/builder/virtualbox/iso/step_create_vm.go b/builder/virtualbox/iso/step_create_vm.go index bcef33a64..f0f9c4f27 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, 10) + commands := make([][]string, 12) commands[0] = []string{ "createvm", "--name", name, "--ostype", config.GuestOSType, "--register", @@ -60,6 +60,16 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis "--nictype7", config.NICType, "--nictype8", config.NICType} commands[9] = []string{"modifyvm", name, "--graphicscontroller", config.GfxController} + if config.RTCTimeBase == "UTC" { + commands[10] = []string{"modifyvm", name, "--rtcuseutc", "on"} + } else { + commands[10] = []string{"modifyvm", name, "--rtcuseutc", "off"} + } + if config.NestedVirt == true { + commands[11] = []string{"modifyvm", name, "--nested-hw-virt", "on"} + } else { + commands[11] = []string{"modifyvm", name, "--nested-hw-virt", "off"} + } ui.Say("Creating virtual machine...") for _, command := range commands {