ghbzhw
Last Updated: February 25, 2016
·
24.77K
· 8xx8ru
355 reasonably small

Vagrantfile. Set memory and CPU

To set virtual machine memory size use:

config.vm.customize ["modifyvm", :id, "--memory", 2048]

To set virtual machine CPU's count use:

config.vm.customize ["modifyvm", :id, "--cpus", 2]

or to set half of available CPU's count:

config.vm.customize ["modifyvm", :id, "--cpus", `awk "/^processor/ {++n} END {print n}" /proc/cpuinfo 2> /dev/null || sh -c 'sysctl hw.logicalcpu 2> /dev/null || echo ": 2"' | awk \'{print \$2}\' `.chomp ]
Say Thanks
Respond

7 Responses
Add your response

4728
Personalise skype   make a free weemee    google chrome 001

In Linux to find number of CPU cores you can call nproc command.

over 1 year ago ·
11209
04ed2b23acc1400315dd1fb5f364b065

This works on Mac & Linux:

config.vm.customize ["modifyvm", :id, "--cpus", `#{RbConfig::CONFIG['host_os'] =~ /darwin/ ? 'sysctl -n hw.ncpu' : 'nproc'}`.chomp]
over 1 year ago ·
11241
7e945991d1d70075cff59331d72ef4d8

@swrobel As far as I know, sysctl -n hw.ncpu shows the virtual CPU count, but vbox can only go as high as the physical cores, which is sysctl -n hw.physicalcpu_max :)

over 1 year ago ·
11266
04ed2b23acc1400315dd1fb5f364b065

@patcon where are you reading that virtualbox only supports physical cores? I'm able to use all 4 logical cores on my Macbook...

over 1 year ago ·
11637
5d59040e82b5fd59f9fdd8671b99a1c5

what's wrong with the setting from vagrant documentation?

v.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
over 1 year ago ·
15805
Beneidel1

now you can use these shortcuts:
v.cpus = 4 v.memory = 2048

over 1 year ago ·
26546
None

Like benjamine said, but a more complete example. This is valid for version 2 of Vagrantfile configuration:


config.vm.provider "virtualbox" do |vb|
    vb.memory = "2048"
    vb.cpus = "2"
end
over 1 year ago ·
Filed Under