Skip to content

Instantly share code, notes, and snippets.

@magicmarkker
Created December 16, 2014 15:41
Show Gist options
  • Select an option

  • Save magicmarkker/309bcee507dd7b770768 to your computer and use it in GitHub Desktop.

Select an option

Save magicmarkker/309bcee507dd7b770768 to your computer and use it in GitHub Desktop.
modify cpus and mem
config.vm.network :forwarded_port, guest: 3000, host: 3000
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
config.vm.provider :virtualbox do |vm|
vm.customize ["modifyvm", :id, "--name", project]
vm.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
host = RbConfig::CONFIG['host_os']
# Give VM 1/4 system memory & access to all cpu cores on the host
if host =~ /darwin/
cpus = `sysctl -n hw.ncpu`.to_i
# sysctl returns Bytes and we need to convert to MB
mem = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 4
elsif host =~ /linux/
cpus = `nproc`.to_i
# meminfo shows KB and we need to convert to MB
mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 / 4
else # sorry Windows folks, I can't help you
cpus = 2
mem = 1024
end
v.customize ["modifyvm", :id, "--memory", mem]
v.customize ["modifyvm", :id, "--cpus", cpus]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment