Configuring VirtualBox Provider
1. Setting VM Name (vb.name)
| Property | Value | Description |
|---|---|---|
| vb.name | "my-vm" |
Sets the name of the VirtualBox VM |
Example: Setting VM Name
Vagrant.configure("2") do |config|
config.vm.provider :virtualbox do |vb|
vb.name = "my-vm"
end
end
2. Configuring Memory (vb.memory)
| Option | Values | Description |
|---|---|---|
| vb.memory | 512 to 8192 |
Amount of RAM (in MB) to allocate to the virtual machine |
Example: Setting Memory to 2GB
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
end
end
3. Setting CPU Count (vb.cpus)
| Option | Values | Description |
|---|---|---|
| vb.cpus | 1, 2, 4, etc. |
Number of virtual CPUs to allocate to the guest machine |
Example: Setting CPU Count
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |vb|
vb.cpus = 2
end
end
4. Enabling GUI Mode (vb.gui)
| Option | Values | Description |
|---|---|---|
| vb.gui | true / false |
Enables or disables the VirtualBox GUI for the VM. Defaults to false. |
Example: Enable GUI Mode
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |vb|
vb.gui = true
end
end
Note: Enabling GUI mode allows you to interact with the VM through VirtualBox's graphical interface, which can be useful for debugging or running GUI-based applications.
5. Customizing VM Settings (vb.customize)
The vb.customize directive allows you to execute VBoxManage commands directly on the VirtualBox VM. This is useful for advanced configuration that isn't exposed through Vagrant's standard provider options.
| Setting | Description | Example |
|---|---|---|
| vb.customize | Executes a VBoxManage command on the VM. Can be used multiple times for different settings. | |
Example: Enable NAT DNS Host Resolver
vagrant.config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
Example: Set VM Memory to 2GB
vagrant.config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
Note: The
:id placeholder refers to the VM's unique identifier assigned by VirtualBox. Vagrant handles this automatically.
6. Setting Linked Clone (vb.linked_clone)
| Option | Values | Description |
|---|---|---|
| vb.linked_clone | true | false |
Enables or disables the use of linked clones for VirtualBox VMs. When set to true, Vagrant will attempt to create a linked clone of the base box, which can significantly reduce disk usage and improve performance. |
Example: Enabling Linked Clone
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.provider :virtualbox do |vb|
vb.linked_clone = true
end
end
Note: Linked clones require a base box that supports this feature. Not all base boxes are compatible with linked clones.
7. Configuring Video Memory
| Option | Values | Description |
|---|---|---|
| vb.customize | "modifyvm", "--vram", "128" |
Sets the video memory size in MB |
Example: Setting Video Memory
Vagrant.configure("2") do |config|
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", "--vram", "128"]
end
end
Note: Video memory is used for 3D acceleration and graphics rendering in the VM. Increasing VRAM can improve performance for GUI applications or games running inside the VM.
8. Enabling 3D Acceleration
| Option | Values | Notes |
|---|---|---|
| config.vm.provider | "virtualbox" |
Specifies the VirtualBox provider |
| config.vm.provider "virtualbox" do |vb| | ... |
Block to configure VirtualBox-specific settings |
| vb.customize | ["modifyvm", :id, "--accelerate3d", "on"] |
Enables 3D acceleration for the VM |
Example: Enabling 3D Acceleration in Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
end
end
Note: 3D acceleration requires VirtualBox 6.1 or later and compatible guest additions.
9. Configuring Network Adapters
| Adapter Type | Description | Default Value | Notes |
|---|---|---|---|
| private_network | Creates a private network interface for the VM | false |
Can be configured with static IP or DHCP |
| public_network | Creates a public network interface for the VM | false |
Allows access from host machine to VM |
| type | Specifies the type of network adapter (e.g., dhcp, static) |
dhcp |
Used in conjunction with private_network or public_network |
Example: Configuring a Private Network with Static IP
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.56.10"
end
Example: Configuring a Public Network with DHCP
Vagrant.configure("2") do |config|
config.vm.network "public_network", type: "dhcp"
end
Note: When using
public_network, Vagrant will attempt to use the first available interface. You may need to specify a specific interface using bridge option.
Warning: Ensure that the IP address assigned to a private network does not conflict with other networks in your environment.
10. Setting Storage Controllers
| Property | Values | Description |
|---|---|---|
| storage.controller | "IDE", "SATA", "SCSI", "SAS", "NVMe" |
Specifies the type of storage controller to use for the VM. |
| storage.controller_name | string |
Name of the storage controller (e.g., "IDE Controller"). |
| storage.controller_type | "IDE", "SATA", "SCSI", "SAS", "NVMe" |
Specifies the type of storage controller to use for the VM. |
| storage.controller_port_count | int |
Number of ports available on the storage controller (default: 1). |
| storage.controller_device_count | int |
Number of devices that can be attached to the controller (default: 1). |
Example: Configure Storage Controller
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |vb|
vb.storage.controller = "SATA"
vb.storage.controller_name = "SATA Controller"
vb.storage.controller_port_count = 2
vb.storage.controller_device_count = 3
end
end
11. Enabling USB Support
| Option | Values | Notes |
|---|---|---|
| config.vm.provider | "virtualbox" |
Specify VirtualBox provider |
| config.vm.provider "virtualbox" do |vb| | ... |
VirtualBox-specific configuration block |
| vb.customize | ["modifyvm", :id, "--usb", "on"] |
Enable USB support for VM |
| vb.customize | ["modifyvm", :id, "--usbehci", "on"] |
Enable USB 2.0/3.0 support (EHCI) |
Example: Enabling USB Support in Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--usb", "on"]
vb.customize ["modifyvm", :id, "--usbehci", "on"]
end
end
Note: USB support requires VirtualBox Extension Pack to be installed on the host machine.
12. Configuring Paravirtualization
| Option | Values | Description |
|---|---|---|
| config.vm.provider | "virtualbox" |
Specifies the VirtualBox provider for Vagrant |
| config.vm.provider "virtualbox" do |vb| | block |
Configuration block for VirtualBox-specific settings |
| vb.customize | array |
Allows direct VirtualBox command-line customization |
Example: Enabling Paravirtualization
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |vb|
vb.customize ["setextradata", :id, "VBoxInternal/Devices/e1000/0/LUN/0/Config/Paravirt", "on"]
end
end
Note: Paravirtualization can improve performance but is not supported on all guest operating systems. Ensure the guest OS supports it before enabling.