Should I use vagrant resume or vagrant up?

kofi picture kofi · Sep 22, 2014 · Viewed 7.2k times · Source

After learning for a couple of days I am happy to have successfully set-up my VM and run the Laravel start page. Very happy there :)

Can someone clarify "when" to use the vagrant functions. My questions:

  1. If I'm planning to turn off my computer should you use halt or suspend? (I am guessing halt) What if I forgot to do any of these two, would it be a problem?

  2. Right after I just turn on my computer should I use up or resume?

  3. What if I am putting my computer to sleep mode by shutting the lid down, is it necessary to vagrant suspend?

Answer

totymedli picture totymedli · Dec 10, 2015

In short

1. Shutting down

The "shutdown" methods differ in speed when you turn off/on the VM and in the amount of disk space the VM will take. From faster/more disk consumption to slower/less disk consumption, the comands are: vagrant suspend, vagrant halt and vagrant destroy.

2. Turning on

Just use vagrant up. The difference between the "startup" methods is that vagrant resume will just "wake up" the VM while vagrant up will make some config checks before this. For example, it will check if your vagrant box has a newer version and will notify you that you can update, by running vagrant box update.

Also you can use vagrant resume only on a VM that was previously suspended. Timewise, there is no noticeable difference between the two when used on a suspended machine.

For more details see the documentation references below.

3. Sleep/hibernation

Putting your computer to sleep or even hibernating it should cause no harm. The former is just a low power state while the latter saves the RAM to the storage drives and then restores it when you start your computer. This is OS level stuff, unless sleep failure or other problems occur it shouldn't influence anything.

Referencing the documentation

The Vagrant documentation has a section for what the different commands do:

Suspending the virtual machine by calling vagrant suspend will save the current running state of the machine and stop it. When you're ready to begin working again, just run vagrant up, and it will be resumed from where you left off. The main benefit of this method is that it is super fast, usually taking only 5 to 10 seconds to stop and start your work. The downside is that the virtual machine still eats up your disk space, and requires even more disk space to store all the state of the virtual machine RAM on disk.

Halting the virtual machine by calling vagrant halt will gracefully shut down the guest operating system and power down the guest machine. You can use vagrant up when you're ready to boot it again. The benefit of this method is that it will cleanly shut down your machine, preserving the contents of disk, and allowing it to be cleanly started again. The downside is that it'll take some extra time to start from a cold boot, and the guest machine still consumes disk space.

Destroying the virtual machine by calling vagrant destroy will remove all traces of the guest machine from your system. It'll stop the guest machine, power it down, and remove all of the guest hard disks. Again, when you're ready to work again, just issue a vagrant up. The benefit of this is that no cruft is left on your machine. The disk space and RAM consumed by the guest machine is reclaimed and your host machine is left clean. The downside is that vagrant up to get working again will take some extra time since it has to reimport the

Also regarding vagrant up and vagrant resume:

Command: vagrant up

This command creates and configures guest machines according to your Vagrantfile.

This is the single most important command in Vagrant, since it is how any Vagrant machine is created. Anyone using Vagrant must use this command on a day-to-day basis

Command: vagrant resume

This resumes a Vagrant managed machine that was previously suspended, perhaps with the suspend command.

Or just look at how the output of the two command differ in your terminal:

$ vagrant resume
==> default: Resuming suspended VM...
==> default: Booting VM...
...

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'laravel/homestead' is up to date...
==> default: Resuming suspended VM...
==> default: Booting VM...
...

During vagrant up you can see the the check in acton. If for example there is a newer version of your box, you will get a notification:

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'laravel/homestead' is up to date...
==> default: A newer version of the box 'laravel/homestead' is available! You currently
==> default: have version '0.3.3'. The latest is version '0.5.0'. Run
==> default: `vagrant box update` to update.
==> default: Resuming suspended VM...
==> default: Booting VM...