Vagrant – Virtual Machine Settings

Previous posts: “Vagrant Provisioning” and “Create a Puppet Server and Agent

In this post we will deal with Vagrant Virtual Machine Settings like CPU, RAM, name, GUI and CPU execution cap. These configuration changes are needed as the default box definitions may not be enough for your testing environment.

Here is our example:

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define "box1" do |box1| = "ubuntu/trusty64"
     box1.vm.provider "virtualbox" do |vb|
       vb.customize ["modifyvm", :id, "--memory", "2048"]
       vb.customize ["modifyvm", :id, "--cpus", "2"]
       vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
       vb.gui = true = "testmyname"
     end "private_network", ip: "", adapter: 2

Here are the details for each line:

box1.vm.provider “virtualbox” do |vb|
You need to define a new block for each machine to change the settings of it.

vb.customize [“modifyvm”, :id, “–memory”, “2048”]
This line defines RAM as 2 GBs.

vb.customize [“modifyvm”, :id, “–cpus”, “2”]
This line defines two CPUs for the virtual machine.

vb.customize [“modifyvm”, :id, “–cpuexecutioncap”, “50”]
This line ensures that the virtual machine cannot use more than 50% of host CPU.

vb.gui = true
This line enables the GUI of Virtualbox so you can interact with the virtual machine from Virtualbox GUI. = “testmyname”
This line gives a meaningful name to your virtual machine in Virtualbox.

Now lets test our config and see what happens with “vagrant up“:

Now I have a Virtualbox GUI for the virtual machine.
Vagrant - Virtual Machine Settings

Checking the details of the Virtualmachine:
As you can see the name, CPU, RAM, CPU execution cap are set correctly.
Vagrant - Virtual Machine Settings 2

Links: Registered & Protected