75

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?

1
  • All the vb.* options are documented here.
    – Geremia
    Apr 11, 2020 at 15:38

3 Answers 3

81

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."

5
  • I have some problems with that. When I try to puts ioapic enable my VM show me an error message...
    – Robert
    Jan 20, 2014 at 13:55
  • I tried the above on a CentOS 6.5 box, but lscpu still showed 1 CPU. Then, I tried the following unsuccessfully: vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"] Mar 6, 2014 at 14:15
  • 2
    @Rob3: start with that you read that error message. Error message doesn't say that "it's broken". It's designated to help you understand, what's wrong. So the most important on error message is to read it. Also when you ask for help and don't post your error message, nobody will try to help you. May 27, 2014 at 18:52
  • @KevinMeredith: how many CPUs has your host (physical) system? May 27, 2014 at 18:53
  • 1
    @TopherHunt - yes, good article and if on Windows also remembering to disable Hyper-V! I added a comment to the article Feb 11, 2016 at 9:47
39

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
3
  • 1
    Any way to dynamically query available cpus and memory of host machine and allocate based on a condition, i.e. if host_cpus = 16 then v.cpus = 8 ? I wanted to allocate half my cpus and ram on two different systems i.e. one is 8 cpus & 8gb ram, the other 16 cpus, and 16gb of ram.
    – radtek
    Feb 8, 2016 at 21:31
  • 1
    @radtek: it’s all ruby, so at the very least you can just drop in a chunk of code to detect the CPU count (e.g. stackoverflow.com/questions/891537/…) and halve it. Feb 23, 2016 at 1:11
  • Thanks, I thought there would be a more native way to check.
    – radtek
    Feb 23, 2016 at 15:44
7

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.