Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a VM in Vagrant with VirtualBox with two CPUs?

Tags:

vagrant

On Windows 7 64 bit trying to start up a VM (Ubuntu 32 bit). I'm having trouble getting my VM to show two cores despite adding the modify vm command in my Vagrantfile. My Vagrant version is 1.2.2.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "precise32"
  config.vm.box_url = "http://files.vagrantup.com/precise32.box"

  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--memory", "2048"]
    vb.customize ["modifyvm", :id, "--cpus", "2"]   
  end  
end

With this Vagrantfile I issue the vagrant up command. Then I issue vagrant ssh followed by lscpu which yields:

Architecture:          i686
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 58
Stepping:              9
CPU MHz:               2565.513
BogoMIPS:              5131.02
L1d cache:             32K
L1d cache:             32K
L2d cache:             6144K

I think CPU(s) should show 2, so my VM only has one CPU right now. How can I get 2 CPUs to show up when I run lscpu?

like image 954
nikhil Avatar asked Jun 14 '13 20:06

nikhil


People also ask

Can I assign all cores to VM?

The answer to this question depends pretty much on what you would like to do. In some cases it might be useful to assign all cores to a VM or even running multiple VM having each one the full amount of CPUs assigned. In such cases a VM can make full use of the whole processing power of the host.


3 Answers

Add vb.customize ["modifyvm", :id, "--ioapic", "on"] to the config.vm.provider block inside your Vagrantfile.

Looking at the VirtualBox documentation it mentions:

"Note Enabling the I/O APIC is required for 64-bit guest operating systems, especially Windows Vista; it is also required if you want to use more than one virtual CPU in a virtual machine."

like image 104
nikhil Avatar answered Oct 16 '22 20:10

nikhil


If you are running vagrant using Oracle Virtualbox then the most common issue is with Hyper-V in Windows 7, 8 or 10. That will limit you to 32bit and one cpu.

Run or search for "Windows Features" and select "Turn Windows Features On or Off".

In the checkboxes make sure Hyper-V is off - you can't enable VT-x for Virtualbox with Microsoft Hyper-V hogging it.

Then, you can make your Vagrantfile boot very user friendly with:

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "2404"
    vb.cpus = "2"
  end

Assuming you want to have two cores running and just a bit over 2 Gig of memory

ps - don't forget to add your port forwarding. For PHPStorm (xdebug, mysql, and web) I use:

  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "forwarded_port", guest: 3306, host: 3306
  config.vm.network "forwarded_port", guest: 9000, host: 9000
like image 36
brianlmerritt Avatar answered Oct 16 '22 19:10

brianlmerritt


It seems you have not mentioned which provider you are using. As of Vagrant 1.7 many VM providers (such as VirtualBox, HyperV) supports the following configuration in your Vagrantfile:

config.vm.provider "virtualbox" do |v|
  v.memory = 1024
  v.cpus = 2
end

Check out the specific provider you are using in the vagrant documentation.

like image 7
mehmet Avatar answered Oct 16 '22 21:10

mehmet