Skip to content

Instantly share code, notes, and snippets.

@oojikoo-gist
Created February 12, 2015 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oojikoo-gist/a21169193e42c17cd675 to your computer and use it in GitHub Desktop.
Save oojikoo-gist/a21169193e42c17cd675 to your computer and use it in GitHub Desktop.
vagrant: nfs config

If you are running on OS X or a Linux that supports NFS folders,

you can also use NFS shared folders.

Vagrantfile:

config.vm.synced_folder ".", "/vagrant", type: "nfs"
config.vm.network "private_network", ip: "192.168.50.1"
# Required for NFS to work, pick any local IP
config.vm.network :private_network, ip: '192.168.50.50'
# Use NFS for shared folders for better performance
config.vm.synced_folder '.', '/vagrant', nfs: true

Use all CPU cores and 1/4 system memory

config.vm.provider "virtualbox" do |v|
  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