Issue: (Virtualbox) On slow machine:Port forwarding and unregister machine fail:

243 views
Skip to first unread message

Turloch O'Tierney

unread,
Jul 7, 2015, 1:32:45 PM7/7/15
to packe...@googlegroups.com
Hi _packer_,

Issue: (Virtualbox) On slow machine:Port forwarding and unregister machine fail:

Thank you for your time,
Turloch

Details follow.
Port Forwarding
    virtualbox-ovf: Deleting forwarded port mapping for SSH (host port 3294)
==> virtualbox-ovf: Error deleting port forwarding rule: VBoxManage error: VBoxManage.exe: error: The machine 'packer-virtualbox-ovf-1436190505' is already locked for a session (or being unlocked)

Unregister machine (different run)
==> virtualbox-ovf: Error deleting VM: VBoxManage error: VBoxManage.exe: error: Cannot unregister the machine 'packer-virtualbox-ovf-1436175757' while it is locked

If I use -debug and periodically press enter the VM has time to unlock. (This would be hard to script)

(and while I am at it: (tried to halt the machine myself so I could add a pause after halt, packer had an error on stopping as it wanted to shut the machine down.)
==> virtualbox-ovf: Halting the virtual machine...
==> virtualbox-ovf: Error stopping VM: VBoxManage error: VBoxManage.exe: error: Invalid machine state: PoweredOff (must be Running, Paused or Stuck))

From a quick look at port forwarding:
func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string)

//XXXXXXXXXXX Wait a second to ensure VM is really shutdown not enough on a slow machine.XXXXXXXXXXXX
log.Println("1 second timeout to ensure VM is really shutdown")
time.Sleep(1 * time.Second)
ui.Say("Preparing to export machine...")

From a quick look at 
// Wait for the machine to actually shut down
log.Printf("Waiting max %s for shutdown to complete", s.Timeout)
shutdownTimer := time.After(s.Timeout)
for {
running, _ := driver.IsRunning(vmName)
if !running {
break
}

select {
case <-shutdownTimer:
err := errors.New("Timeout while waiting for machine to shut down.")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
default:
time.Sleep(500 * time.Millisecond)
}
}

Maybe it is locked for a couple of seconds after !running,

(
Test:Sleep in the shutdown command shell script: 
Result:small test case works either way.

Test:Could be database shutting down - will stop than in advance
).




Turloch O'Tierney

unread,
Jul 7, 2015, 3:13:05 PM7/7/15
to packe...@googlegroups.com

I am using:
 "shutdown_command": "echo 'password' | sudo -S shutdown -P now",
or maybe:
 "shutdown_command": "echo 'password' | sudo -S shutdown -P now && sleep 200",

Will try something like:
"echo sudo -S shutdown -P now > /tmp/shutdown.sh; echo 'password' | sudo -S sh /tmp/shutdown.sh"
I do not see the difference though.

I might put it down to a slow machine - and be resigned to pressing enter a few times and run in debug.

T

Alvaro Miranda Aguilera

unread,
Jul 7, 2015, 5:36:51 PM7/7/15
to packe...@googlegroups.com
Hello Turloch

What are the specs you have in the box you are using?

I have get the same error only on windows, and sometimes have been
something related to somehting creating a lock on the files, so
VirtualBox was just failing

- I did put the box in dropbox, and dropbox created a lock on the
disk, moved out of dropbox and solved the issue
- I did hit same error and found my backup solution was backing up the
disk.. same thing, excluded the build folder from backup
- one the same with antivirus


I can see you are using virtualbox-ovf, so you are starting with other
virtual machine image.. if you could start from an iso, and use
virtualbox-iso you can use atlas build to build th boxes.. the free
tier is 20gb in disk, 1gb on memory.

Thanks
Alvaro
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
> of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/mitchellh/packer/issues
> IRC: #packer-tool on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Packer" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to packer-tool...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/packer-tool/eaee2c9a-caf0-48f6-8d7d-42ef8129b8f4%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Turloch O'Tierney

unread,
Jul 13, 2015, 7:16:36 AM7/13/15
to packe...@googlegroups.com
Hi Alvaro,

Machine spec: Slow Desktop.
The locking issue could be a slow antivirus lock.

Could start from iso - it seems (cleaner and) a bit more work that starting from an base ova.
Atlas build I might look into however the packer project is for an enterprise and 
the virtualbox VM is quite large - I aim to get output .ova file down to 2 gb Ram/ 10Gb disk
(it is a little over that now).

Thank you for your time,
Turloch
Reply all
Reply to author
Forward
0 new messages