Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use vagrant resume or vagrant up?

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?

like image 473
kofi Avatar asked Sep 22 '14 03:09

kofi


People also ask

How do I resume a vagrant VM?

Command: vagrant resume [name|id] This resumes a Vagrant managed machine that was previously suspended, perhaps with the suspend command. The configured provisioners will not run again, by default. You can force the provisioners to re-run by specifying the --provision flag.

What does vagrant up -- provision do?

Provisioners in Vagrant allow you to automatically install software, alter configurations, and more on the machine as part of the vagrant up process. This is useful since boxes typically are not built perfectly for your use case.

What is vagrant up command?

Command: vagrant up [name|id] 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.

Can I have more than one vagrant box?

You can definitely run multiple Vagrant boxes concurrently, as long as their configuration does not clash with one another in some breaking way, e.g. mapping the same network ports on the host, or using same box names/IDs inside the same provider.


3 Answers

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...
like image 165
totymedli Avatar answered Oct 10 '22 09:10

totymedli


  1. I usually use halt when I shut down my computer. When you suspend, I believe it stores the current stage image on disk. If you don't care about storage problem then you could use suspend.

  2. If you suspended your VM then you should use resume so that last state is restored. If you just starting the VM, use "up"

  3. I don't think it's necessary to suspend VM whenever when you hibernate your computer.

like image 37
ganni Avatar answered Oct 10 '22 08:10

ganni


in short, if you use

$ vagrant suspend

then use

$ vagrant resume

but if you use

$ vagrant halt

then use

$ vagrant up
like image 27
smakintel.com Avatar answered Oct 10 '22 08:10

smakintel.com