spetz83
spetz83

Reputation: 532

Vagrant destroyed on host shut down, Windows

After working in a Vagrant VM and making some changes I will suspend the VM using vagrant suspend. If I then restart the host computer and then attempt to run vagrant resume, the terminal sits for a bit and then brings me back to a command prompt without any feedback. So, naturally I then try vagrant ssh, and I receive the following:

VM must be running to open SSH connection. Run vagrant up to start the virtual machine.

If I run vagrant up, I find that all the changes I made prior to the suspend have been overwriten by the base box import.

Is this intended behavior? I am runny Windows 8 pro x64.

Upvotes: 12

Views: 8608

Answers (4)

Markus-ipse
Markus-ipse

Reputation: 7396

This happens to me every now and then, I reboot and there's no trace of my vagrant machine anymore. Even running vboxmanage list vms doesn't show my VM, but if I reboot my computer again and this time I open Virtualbox GUI before trying to do vboxmanage list vms (or don't open it first depending on which way failed on previous attempt) and it'll list my Vagrant machine and its ID.

Armed with this ID I can go into .vagrant/machines/default/virtualbox/ and create a file named "id" and add a single line containing the id of the vagrant machine. And after that you can start it with vagrant up it's probably safest to add --no-provision though as it has happened that it's started provisioning even though a machine already existed..

Upvotes: 4

cttyler
cttyler

Reputation: 11

I just recently encountered a somewhat similar situation, and ultimately discovered that there is a scenario where a 'vagrant suspend' effectively destroys a VM. That's running Vagrant on a Windows host with Virtual Box 4.3.14 as the virtualization provider. Rolling Virtual Box back to 4.3.12 is a way to work around the issue. Details here: https://github.com/mitchellh/vagrant/issues/4276

Upvotes: 1

Alex
Alex

Reputation: 35008

The idea of vagrant is to use the base box and then make customizations with provisioning methods. So always a vagrant destroy (removes all data of the VM) and vagrant up builts the box again, based on the base box, should work.

Anyways, you did not do a vagrant destroy the data should still be there.

If you did a vagrant suspend that means the boxes state is frozen by Virtual Box.

Next, you should do a vagrant resume: http://docs.vagrantup.com/v2/cli/resume.html

But if you did a vagrant up in between, the data might be lost. You could open the VirtualBox GUI and see if there are still some preserved snapshots.

Upvotes: 6

avhilchen
avhilchen

Reputation: 109

I'd suggest creating a project directory for each VM you plan to use. If you change into that empty project directory before doing vagrant init a dedicated Vagrantfile is created for that project/VM, which then can be customized to your needs. To use that customized Vagrantfile then, just run vagrant up from inside your projects directory. Not sure if this solves your problem but it's worth a try I guess. ;-)

Btw. you can check if your VM is running with the command vagrant status [machine-name].

Upvotes: 2

Related Questions