diff --git a/builder/virtualbox/step_attach_floppy.go b/builder/virtualbox/step_attach_floppy.go index be7394160..bb5c8c5d8 100644 --- a/builder/virtualbox/step_attach_floppy.go +++ b/builder/virtualbox/step_attach_floppy.go @@ -85,7 +85,6 @@ func (s *stepAttachFloppy) Cleanup(state map[string]interface{}) { defer os.Remove(s.floppyPath) driver := state["driver"].(Driver) - ui := state["ui"].(packer.Ui) vmName := state["vmName"].(string) command := []string{ @@ -97,7 +96,7 @@ func (s *stepAttachFloppy) Cleanup(state map[string]interface{}) { } if err := driver.VBoxManage(command...); err != nil { - ui.Error(fmt.Sprintf("Error unregistering floppy: %s", err)) + log.Printf("Error unregistering floppy: %s", err) } } diff --git a/builder/virtualbox/step_export.go b/builder/virtualbox/step_export.go index a37f718f4..c15fc1a0a 100644 --- a/builder/virtualbox/step_export.go +++ b/builder/virtualbox/step_export.go @@ -22,7 +22,8 @@ func (s *stepExport) Run(state map[string]interface{}) multistep.StepAction { vmName := state["vmName"].(string) // Clear out the Packer-created forwarding rule - ui.Say(fmt.Sprintf("Deleting forwarded port mapping for SSH (host port %d)", state["sshHostPort"])) + ui.Say("Preparing to export machine...") + ui.Message(fmt.Sprintf("Deleting forwarded port mapping for SSH (host port %d)", state["sshHostPort"])) command := []string{"modifyvm", vmName, "--natpf1", "delete", "packerssh"} if err := driver.VBoxManage(command...); err != nil { err := fmt.Errorf("Error deleting port forwarding rule: %s", err) @@ -31,6 +32,23 @@ func (s *stepExport) Run(state map[string]interface{}) multistep.StepAction { return multistep.ActionHalt } + // Remove the attached floppy disk, if it exists + if _, ok := state["floppy_path"]; ok { + ui.Message("Removing floppy drive...") + command := []string{ + "storageattach", vmName, + "--storagectl", "Floppy Controller", + "--port", "0", + "--device", "0", + "--medium", "none", + } + if err := driver.VBoxManage(command...); err != nil { + state["error"] = fmt.Errorf("Error removing floppy: %s", err) + return multistep.ActionHalt + } + + } + // Export the VM to an OVF outputPath := filepath.Join(config.OutputDir, "packer.ovf")