Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting "Paravirtualization Interface" in Vagrantfile

VirtualBox 5 exposes a setting called "Paravirtualization Interface" that can improve performance for some specific guest operating systems.

Is there a way to set this option in a Vagrantfile?

And in general: Is there documentation on how to set the acceleration settings via the Vagrantfile?

like image 643
selfawaresoup Avatar asked Jul 14 '15 14:07

selfawaresoup


2 Answers

Found it. VBoxManage (the VirtualBox CLI tool) has an optional argument called --paravirtprovider. You can add that to the vb.customize call:

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.provider "virtualbox" do |vb|
    vb.customize [
      "modifyvm", :id,
      "--memory", "1024",
      "--paravirtprovider", "kvm", # for linux guest
      "--cpus", "2"
    ]
  end
end

The other CPU settings are also available that way, vb.customize accepts the same argument as VBoxManage. Refer to VboxManage --help to get a list of all the options.

like image 109
selfawaresoup Avatar answered Sep 22 '22 10:09

selfawaresoup


My Vagrantfile did not have a vb.customize section (maybe the accepted answer uses older format (?)). Based on https://www.vagrantup.com/docs/virtualbox/configuration.html and https://www.virtualbox.org/manual/ch08.html (search for --nictype) the following worked for me. I did not need to set KVM explicitely, because I was on Linux and it was the default.

Vagrant.configure("2") do |config|

    config.vm.box = "ubuntu/bionic64"
    config.vm.hostname = "whatever"

    config.vm.provider "virtualbox" do |vb|
        vb.memory = "512"
        vb.cpus = "2"
        vb.default_nic_type = "virtio"
    end
end

By setting this default_nic_type to virtio, not only the first NAT-ed NIC got this type, but also I defined a second NIC (not shown here) and it also got created as virtio (virtio-net in virtualbox settings GUI).

like image 38
Attila123 Avatar answered Sep 20 '22 10:09

Attila123