From fa844543ec012613574c77a8ba5fa41a874bddf6 Mon Sep 17 00:00:00 2001 From: Thomas Dreibholz Date: Sat, 20 Feb 2021 19:31:46 +0100 Subject: [PATCH 1/6] Added options for chipset and firmware. --- builder/virtualbox/iso/builder.go | 30 ++++++++++++++++++++++ builder/virtualbox/iso/builder.hcl2spec.go | 4 +++ builder/virtualbox/iso/step_create_vm.go | 5 +++- 3 files changed, 38 insertions(+), 1 deletion(-) 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...) From eb4a6f30a0f9b9083913aba486f27500079417f0 Mon Sep 17 00:00:00 2001 From: Thomas Dreibholz Date: Sat, 20 Feb 2021 19:59:39 +0100 Subject: [PATCH 2/6] Added option for NIC type. --- builder/virtualbox/iso/builder.go | 20 ++++++++++++++++++++ builder/virtualbox/iso/step_create_vm.go | 12 +++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index bd008548b..618d88a33 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -55,6 +55,15 @@ type Config struct { // 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"` + // The NIC type to be used for the network interfaces. + // When set to 82540EM, the NICs are Intel PRO/1000 MT Desktop (82540EM). This is the default. + // When set to 82543GC, the NICs are Intel PRO/1000 T Server (82543GC). + // When set to 82545EM, the NICs are Intel PRO/1000 MT Server (82545EM). + // When set to Am79C970A, the NICs are AMD PCNet-PCI II network card (Am79C970A). + // When set to Am79C973, the NICs are AMD PCNet-FAST III network card (Am79C973). + // When set to Am79C960, the NICs are AMD PCnet-ISA/NE2100 (Am79C960). + // When set to virtio, the NICs are VirtIO. + NICType string `mapstructure:"nic_type" required:"false"` // The guest OS type being installed. By default this is other, but you can // get dramatic performance improvements by setting this to the proper // value. To view all available values for this run VBoxManage list @@ -200,6 +209,17 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { b.config.HardDriveInterface = "ide" } + if b.config.NICType == "" { + b.config.NICType = "82540EM" + } + switch b.config.NICType { + case "82540EM", "82543GC", "82545EM", "Am79C970A", "Am79C973", "Am79C960", "virtio": + // do nothing + default: + errs = packersdk.MultiErrorAppend( + errs, errors.New("NIC type can only be 82540EM, 82543GC, 82545EM, Am79C970A, Am79C973, Am79C960 or virtio")) + } + if b.config.GuestOSType == "" { b.config.GuestOSType = "Other" } diff --git a/builder/virtualbox/iso/step_create_vm.go b/builder/virtualbox/iso/step_create_vm.go index 5cce54db9..1810789f3 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, 8) + commands := make([][]string, 9) commands[0] = []string{ "createvm", "--name", name, "--ostype", config.GuestOSType, "--register", @@ -47,6 +47,16 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis commands[6] = []string{"modifyvm", name, "--chipset", config.Chipset} commands[7] = []string{"modifyvm", name, "--firmware", config.Firmware} + // Set the configured NIC type for all 8 possible NICs + commands[8] = []string{"modifyvm", name, + "--nictype1", config.NICType, + "--nictype2", config.NICType, + "--nictype3", config.NICType, + "--nictype4", config.NICType, + "--nictype5", config.NICType, + "--nictype6", config.NICType, + "--nictype7", config.NICType, + "--nictype8", config.NICType} ui.Say("Creating virtual machine...") for _, command := range commands { From e9936cf0da9ff19f0e6693c3019c022961b829de Mon Sep 17 00:00:00 2001 From: Thomas Dreibholz Date: Sat, 20 Feb 2021 20:09:16 +0100 Subject: [PATCH 3/6] Added option for audio controller. --- builder/virtualbox/iso/builder.go | 13 +++++++++++++ builder/virtualbox/iso/step_create_vm.go | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index 618d88a33..5307ea955 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -64,6 +64,11 @@ type Config struct { // When set to Am79C960, the NICs are AMD PCnet-ISA/NE2100 (Am79C960). // When set to virtio, the NICs are VirtIO. NICType string `mapstructure:"nic_type" required:"false"` + // The audio controller type to be used. + // When set to ac97, the audio controller is ICH AC97 (default). + // When set to hda, the audio controller is Intel HD Audio. + // When set to sb16, the audio controller is SoundBlaster 16. + AudioController string `mapstructure:"audio_controller" required:"false"` // The guest OS type being installed. By default this is other, but you can // get dramatic performance improvements by setting this to the proper // value. To view all available values for this run VBoxManage list @@ -220,6 +225,14 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { errs, errors.New("NIC type can only be 82540EM, 82543GC, 82545EM, Am79C970A, Am79C973, Am79C960 or virtio")) } + switch b.config.AudioController { + case "ac97", "hda", "sb16": + // do nothing + default: + errs = packersdk.MultiErrorAppend( + errs, errors.New("Audio controller type can only be ac97, hda or sb16")) + } + if b.config.GuestOSType == "" { b.config.GuestOSType = "Other" } diff --git a/builder/virtualbox/iso/step_create_vm.go b/builder/virtualbox/iso/step_create_vm.go index 1810789f3..e258551c0 100644 --- a/builder/virtualbox/iso/step_create_vm.go +++ b/builder/virtualbox/iso/step_create_vm.go @@ -40,9 +40,11 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis commands[4] = []string{"modifyvm", name, "--usb", map[bool]string{true: "on", false: "off"}[config.HWConfig.USB]} if strings.ToLower(config.HWConfig.Sound) == "none" { - commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound} + commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound, + "--audiocontroller", config.AudioController} } else { - commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound, "--audioin", "on", "--audioout", "on"} + commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound, "--audioin", "on", "--audioout", "on", + "--audiocontroller", config.AudioController} } commands[6] = []string{"modifyvm", name, "--chipset", config.Chipset} From ffa8b7de8a20057d30003f95501a18318294b560 Mon Sep 17 00:00:00 2001 From: Thomas Dreibholz Date: Sat, 20 Feb 2021 20:21:57 +0100 Subject: [PATCH 4/6] Added option for the graphics controller. --- builder/virtualbox/iso/builder.go | 22 +++++++++++++++++++++- builder/virtualbox/iso/step_create_vm.go | 3 ++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index 5307ea955..53d1532c7 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -65,10 +65,16 @@ type Config struct { // When set to virtio, the NICs are VirtIO. NICType string `mapstructure:"nic_type" required:"false"` // The audio controller type to be used. - // When set to ac97, the audio controller is ICH AC97 (default). + // When set to ac97, the audio controller is ICH AC97. This is the default. // When set to hda, the audio controller is Intel HD Audio. // When set to sb16, the audio controller is SoundBlaster 16. AudioController string `mapstructure:"audio_controller" required:"false"` + // The graphics controller type to be used. + // When set to vboxvga, the graphics controller is VirtualBox VGA. This is the default. + // When set to vboxsvga, the graphics controller is VirtualBox SVGA. + // When set to vmsvga, the graphics controller is VMware SVGA. + // When set to none, the graphics controller is disabled. + GfxController string `mapstructure:"gfx_controller" required:"false"` // The guest OS type being installed. By default this is other, but you can // get dramatic performance improvements by setting this to the proper // value. To view all available values for this run VBoxManage list @@ -225,6 +231,20 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { errs, errors.New("NIC type can only be 82540EM, 82543GC, 82545EM, Am79C970A, Am79C973, Am79C960 or virtio")) } + if b.config.GfxController == "" { + b.config.GfxController = "vboxvga" + } + switch b.config.GfxController { + case "vboxvga", "vboxsvga", "vmsvga", "none": + // do nothing + default: + errs = packersdk.MultiErrorAppend( + errs, errors.New("Graphics controller type can only be vboxvga, vboxsvga, vmsvga, none")) + } + + if b.config.AudioController == "" { + b.config.AudioController = "ac97" + } switch b.config.AudioController { case "ac97", "hda", "sb16": // do nothing diff --git a/builder/virtualbox/iso/step_create_vm.go b/builder/virtualbox/iso/step_create_vm.go index e258551c0..32895e713 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, 9) + commands := make([][]string, 10) commands[0] = []string{ "createvm", "--name", name, "--ostype", config.GuestOSType, "--register", @@ -59,6 +59,7 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis "--nictype6", config.NICType, "--nictype7", config.NICType, "--nictype8", config.NICType} + commands[9] = []string{"modifyvm", name, "--graphicscontroller", config.GfxController} ui.Say("Creating virtual machine...") for _, command := range commands { From 8226bc9d9f18f08cfbdb0e60e49a6f0970d37315 Mon Sep 17 00:00:00 2001 From: Thomas Dreibholz Date: Sat, 20 Feb 2021 20:23:47 +0100 Subject: [PATCH 5/6] Ran "make generate". --- builder/virtualbox/iso/builder.hcl2spec.go | 6 ++++ .../virtualbox/iso/Config-not-required.mdx | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/builder/virtualbox/iso/builder.hcl2spec.go b/builder/virtualbox/iso/builder.hcl2spec.go index 04faf34f6..88a880458 100644 --- a/builder/virtualbox/iso/builder.hcl2spec.go +++ b/builder/virtualbox/iso/builder.hcl2spec.go @@ -120,6 +120,9 @@ type FlatConfig struct { 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"` + NICType *string `mapstructure:"nic_type" required:"false" cty:"nic_type" hcl:"nic_type"` + AudioController *string `mapstructure:"audio_controller" required:"false" cty:"audio_controller" hcl:"audio_controller"` + GfxController *string `mapstructure:"gfx_controller" required:"false" cty:"gfx_controller" hcl:"gfx_controller"` 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"` HardDriveInterface *string `mapstructure:"hard_drive_interface" required:"false" cty:"hard_drive_interface" hcl:"hard_drive_interface"` @@ -254,6 +257,9 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "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}, + "nic_type": &hcldec.AttrSpec{Name: "nic_type", Type: cty.String, Required: false}, + "audio_controller": &hcldec.AttrSpec{Name: "audio_controller", Type: cty.String, Required: false}, + "gfx_controller": &hcldec.AttrSpec{Name: "gfx_controller", Type: cty.String, 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}, "hard_drive_interface": &hcldec.AttrSpec{Name: "hard_drive_interface", Type: cty.String, Required: false}, diff --git a/website/content/partials/builder/virtualbox/iso/Config-not-required.mdx b/website/content/partials/builder/virtualbox/iso/Config-not-required.mdx index 8afdf7544..d77c4048c 100644 --- a/website/content/partials/builder/virtualbox/iso/Config-not-required.mdx +++ b/website/content/partials/builder/virtualbox/iso/Config-not-required.mdx @@ -1,8 +1,36 @@ +- `chipset` (string) - 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. + +- `firmware` (string) - 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. + - `disk_size` (uint) - The size, in megabytes, of the hard disk to create for the VM. By default, this is 40000 (about 40 GB). +- `nic_type` (string) - The NIC type to be used for the network interfaces. + When set to 82540EM, the NICs are Intel PRO/1000 MT Desktop (82540EM). This is the default. + When set to 82543GC, the NICs are Intel PRO/1000 T Server (82543GC). + When set to 82545EM, the NICs are Intel PRO/1000 MT Server (82545EM). + When set to Am79C970A, the NICs are AMD PCNet-PCI II network card (Am79C970A). + When set to Am79C973, the NICs are AMD PCNet-FAST III network card (Am79C973). + When set to Am79C960, the NICs are AMD PCnet-ISA/NE2100 (Am79C960). + When set to virtio, the NICs are VirtIO. + +- `audio_controller` (string) - The audio controller type to be used. + When set to ac97, the audio controller is ICH AC97. This is the default. + When set to hda, the audio controller is Intel HD Audio. + When set to sb16, the audio controller is SoundBlaster 16. + +- `gfx_controller` (string) - The graphics controller type to be used. + When set to vboxvga, the graphics controller is VirtualBox VGA. This is the default. + When set to vboxsvga, the graphics controller is VirtualBox SVGA. + When set to vmsvga, the graphics controller is VMware SVGA. + When set to none, the graphics controller is disabled. + - `guest_os_type` (string) - The guest OS type being installed. By default this is other, but you can get dramatic performance improvements by setting this to the proper value. To view all available values for this run VBoxManage list From 2b35873dd9c83ef5fe327ccabc35a1107ff5d74d Mon Sep 17 00:00:00 2001 From: Thomas Dreibholz Date: Sat, 20 Feb 2021 20:31:09 +0100 Subject: [PATCH 6/6] Formatting fix. --- builder/virtualbox/iso/builder.go | 2 +- builder/virtualbox/iso/step_create_vm.go | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index 53d1532c7..c82c435e0 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -224,7 +224,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { b.config.NICType = "82540EM" } switch b.config.NICType { - case "82540EM", "82543GC", "82545EM", "Am79C970A", "Am79C973", "Am79C960", "virtio": + case "82540EM", "82543GC", "82545EM", "Am79C970A", "Am79C973", "Am79C960", "virtio": // do nothing default: errs = packersdk.MultiErrorAppend( diff --git a/builder/virtualbox/iso/step_create_vm.go b/builder/virtualbox/iso/step_create_vm.go index 32895e713..bcef33a64 100644 --- a/builder/virtualbox/iso/step_create_vm.go +++ b/builder/virtualbox/iso/step_create_vm.go @@ -41,24 +41,24 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis if strings.ToLower(config.HWConfig.Sound) == "none" { commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound, - "--audiocontroller", config.AudioController} + "--audiocontroller", config.AudioController} } else { commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound, "--audioin", "on", "--audioout", "on", - "--audiocontroller", config.AudioController} + "--audiocontroller", config.AudioController} } commands[6] = []string{"modifyvm", name, "--chipset", config.Chipset} commands[7] = []string{"modifyvm", name, "--firmware", config.Firmware} // Set the configured NIC type for all 8 possible NICs commands[8] = []string{"modifyvm", name, - "--nictype1", config.NICType, - "--nictype2", config.NICType, - "--nictype3", config.NICType, - "--nictype4", config.NICType, - "--nictype5", config.NICType, - "--nictype6", config.NICType, - "--nictype7", config.NICType, - "--nictype8", config.NICType} + "--nictype1", config.NICType, + "--nictype2", config.NICType, + "--nictype3", config.NICType, + "--nictype4", config.NICType, + "--nictype5", config.NICType, + "--nictype6", config.NICType, + "--nictype7", config.NICType, + "--nictype8", config.NICType} commands[9] = []string{"modifyvm", name, "--graphicscontroller", config.GfxController} ui.Say("Creating virtual machine...")