» Configuration
The VirtualBox provider exposes some additional configuration optionsthat allow you to more finely control your VirtualBox-powered Vagrantenvironments.
» GUI vs. Headless
By default, VirtualBox machines are started in headless mode, meaningthere is no UI for the machines visible on the host machine. Sometimes,you want to have a UI. Common use cases include wanting to see a browserthat may be running in the machine, or debugging a strange boot issue.You can easily tell the VirtualBox provider to boot with a GUI:
config.vm.provider "virtualbox" do |v|
v.gui = true
end
» Virtual Machine Name
You can customize the name that appears in the VirtualBox GUI bysetting the name
property. By default, Vagrant sets it to the containingfolder of the Vagrantfile plus a timestamp of when the machine was created.By setting another name, your VM can be more easily identified.
config.vm.provider "virtualbox" do |v|
v.name = "my_vm"
end
» Default NIC Type
By default Vagrant will not set the NIC type for network interfaces. Thisallows VirtualBox to apply the default NIC type for the guest. If you wouldlike to use a specific NIC type by default for guests, set the default_nic_type
option:
config.vm.provider "virtualbox" do |v|
v.default_nic_type = "82543GC"
end
» Linked Clones
By default new machines are created by importing the base box. For largeboxes this produces a large overhead in terms of time (the import operation)and space (the new machine contains a copy of the base box's image).Using linked clones can drastically reduce this overhead.
Linked clones are based on a master VM, which is generated by importing thebase box only once the first time it is required. For the linked clones onlydifferencing disk images are created where the parent disk image belongs tothe master VM.
config.vm.provider "virtualbox" do |v|
v.linked_clone = true
end
To have backward compatibility:
config.vm.provider 'virtualbox' do |v|
v.linked_clone = true if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.8.0')
end
If you do not want backward compatibility and want to force users tosupport linked cloning, you can use Vagrant.require_version
with 1.8.
Note: the generated master VMs are currently not removedautomatically by Vagrant. This has to be done manually. However, a masterVM can only be removed when there are no linked clones connected to it.
» VBoxManage Customizations
VBoxManage is a utility that canbe used to make modifications to VirtualBox virtual machines from the commandline.
Vagrant exposes a way to call any command against VBoxManage just priorto booting the machine:
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
end
In the example above, the VM is modified to have a host CPU executioncap of 50%, meaning that no matter how much CPU is used in the VM, nomore than 50% would be used on your own host machine. Some details:
The
:id
special parameter is replaced with the ID of the virtualmachine being created, so when a VBoxManage command requires an ID, youcan pass this special parameter.Multiple
customize
directives can be used. They will be executed in theorder given.
There are some convenience shortcuts for memory and CPU settings:
config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 2
end