From 16110c6be6903be52ebd94c095aae20a87545892 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 6 Nov 2014 23:13:09 +0300 Subject: [PATCH 1/2] add CD-ROM only if not used disk_image, also boot from it only if CD-ROM present Signed-off-by: Vasiliy Tolstov --- builder/qemu/builder.go | 14 ++++++++++---- builder/qemu/step_run.go | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index 1c3d2cdca..7df0ff8c2 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -418,6 +418,15 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe return nil, fmt.Errorf("Failed creating Qemu driver: %s", err) } + steprun := &stepRun{} + if !b.config.DiskImage { + steprun.BootDrive = "once=d" + steprun.Message = "Starting VM, booting from CD-ROM" + } else { + steprun.BootDrive = "c" + steprun.Message = "Starting VM, booting disk image" + } + steps := []multistep.Step{ &common.StepDownload{ Checksum: b.config.ISOChecksum, @@ -436,10 +445,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe new(stepHTTPServer), new(stepForwardSSH), new(stepConfigureVNC), - &stepRun{ - BootDrive: "once=d", - Message: "Starting VM, booting from CD-ROM", - }, + steprun, &stepBootWait{}, &stepTypeBootCommand{}, &common.StepConnectSSH{ diff --git a/builder/qemu/step_run.go b/builder/qemu/step_run.go index bb2876f86..3f900d651 100644 --- a/builder/qemu/step_run.go +++ b/builder/qemu/step_run.go @@ -82,7 +82,9 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0,hostfwd=tcp::%v-:22", sshHostPort) defaultArgs["-device"] = fmt.Sprintf("%s,netdev=user.0", config.NetDevice) defaultArgs["-drive"] = fmt.Sprintf("file=%s,if=%s,cache=%s", imgPath, config.DiskInterface, config.DiskCache) - defaultArgs["-cdrom"] = isoPath + if !config.DiskImage { + defaultArgs["-cdrom"] = isoPath + } defaultArgs["-boot"] = bootDrive defaultArgs["-m"] = "512M" defaultArgs["-vnc"] = vnc From 2126615b3d4f0532ff49299fffb08fcb81a43233 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 6 Nov 2014 23:47:00 +0300 Subject: [PATCH 2/2] disk_filename is used for artifacts, but it missed in case of disk_image = true Signed-off-by: Vasiliy Tolstov --- builder/qemu/step_copy_disk.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/builder/qemu/step_copy_disk.go b/builder/qemu/step_copy_disk.go index 7f2efe30e..54c3084ac 100644 --- a/builder/qemu/step_copy_disk.go +++ b/builder/qemu/step_copy_disk.go @@ -2,10 +2,11 @@ package qemu import ( "fmt" - "github.com/mitchellh/multistep" - "github.com/mitchellh/packer/packer" "path/filepath" "strings" + + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" ) // This step copies the virtual disk that will be used as the @@ -19,6 +20,7 @@ func (s *stepCopyDisk) Run(state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packer.Ui) path := filepath.Join(config.OutputDir, fmt.Sprintf("%s.%s", config.VMName, strings.ToLower(config.Format))) + name := config.VMName + "." + strings.ToLower(config.Format) command := []string{ "convert", @@ -39,6 +41,8 @@ func (s *stepCopyDisk) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } + state.Put("disk_filename", name) + return multistep.ActionContinue }