Merge pull request #10671 from dreibh/dreibh/virtualbox-options

More options for the VirtualBox ISO builder
This commit is contained in:
Megan Marsh 2021-02-22 14:45:19 -08:00 committed by GitHub
commit d398487afd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 140 additions and 3 deletions

View File

@ -44,9 +44,37 @@ 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"`
// 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 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.
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
@ -162,6 +190,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
}
@ -170,6 +220,39 @@ 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.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
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"
}

View File

@ -117,7 +117,12 @@ 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"`
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"`
@ -249,7 +254,12 @@ 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},
"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},

View File

@ -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, 10)
commands[0] = []string{
"createvm", "--name", name,
"--ostype", config.GuestOSType, "--register",
@ -40,11 +40,27 @@ 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}
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}
commands[9] = []string{"modifyvm", name, "--graphicscontroller", config.GfxController}
ui.Say("Creating virtual machine...")
for _, command := range commands {
err := driver.VBoxManage(command...)

View File

@ -1,8 +1,36 @@
<!-- Code generated from the comments of the Config struct in builder/virtualbox/iso/builder.go; DO NOT EDIT MANUALLY -->
- `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