From dbc24d935759d598197d9c46d3612c783860e1eb Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Thu, 5 Sep 2013 11:00:08 -0700 Subject: [PATCH] Enable customization of VirtualBox disk controller with `hard_drive_interface` option (SATA only). --- builder/virtualbox/builder.go | 5 +++++ builder/virtualbox/step_create_disk.go | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/builder/virtualbox/builder.go b/builder/virtualbox/builder.go index 703a9ba92..b7bc58c16 100644 --- a/builder/virtualbox/builder.go +++ b/builder/virtualbox/builder.go @@ -33,6 +33,7 @@ type config struct { GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"` GuestOSType string `mapstructure:"guest_os_type"` Headless bool `mapstructure:"headless"` + HardDriveInterface string `mapstructure:"hard_drive_interface"` HTTPDir string `mapstructure:"http_directory"` HTTPPortMin uint `mapstructure:"http_port_min"` HTTPPortMax uint `mapstructure:"http_port_max"` @@ -89,6 +90,10 @@ func (b *Builder) Prepare(raws ...interface{}) error { b.config.GuestAdditionsPath = "VBoxGuestAdditions.iso" } + if b.config.HardDriveInterface == "" { + b.config.HardDriveInterface = "ide" + } + if b.config.GuestOSType == "" { b.config.GuestOSType = "Other" } diff --git a/builder/virtualbox/step_create_disk.go b/builder/virtualbox/step_create_disk.go index cb456ed0a..80abeeb75 100644 --- a/builder/virtualbox/step_create_disk.go +++ b/builder/virtualbox/step_create_disk.go @@ -39,7 +39,9 @@ func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } - // Add the IDE controller so we can later attach the disk + // Add the IDE controller so we can later attach the disk. + // When the hard disk controller is not IDE, this device is still used + // by VirtualBox to deliver the guest extensions. controllerName := "IDE Controller" err = driver.VBoxManage("storagectl", vmName, "--name", controllerName, "--add", "ide") if err != nil { @@ -49,6 +51,22 @@ func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } + if config.HardDriveInterface == "sata" { + controllerName = "SATA Controller" + command = []string{ + "storagectl", vmName, + "--name", controllerName, + "--add", "sata", + "--sataportcount", "1", + } + if err := driver.VBoxManage(command...); err != nil { + err := fmt.Errorf("Error creating disk controller: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + } + // Attach the disk to the controller command = []string{ "storageattach", vmName,