Running Vagrant Inside VMWare VM

I've run into the same issue today. The solution is quite simple.

  1. Power off vmware vitrual machine.
  2. Go to "edit virtual machine settings"
  3. Go to processors. There are three checkboxes there.
  4. Check second checkbox (enable VT-x/AMD-V)
  5. Power on machine.

After this virtualbox should work inside vmware.


To answer the original question as well as @blong's Vagrant forum post, this is what I've done to make this work.

I was trying to do something similar myself (actually Vagrant/VMware hosting Vagrant/Vbox) and I have performed all the optimizations I can think of, giving my "host" VM a large amount of RAM (24GB) and 6 cores, disabling swapping VMs to disk (this KILLS things on Windows when it happens) by setting "Fit all VM memory into reserved host memory", and allowing per VM page files (otherwise they live in the system page file which limits how many VMs you can run at once).

What I am doing has been working perfectly, the networking issues I've had were due to the corporate proxy I'm behind. Once I configured that my VM got internet access and all was right with the world.

I did have to manually set --natbindip1 and --natnet1 via the Vagrantfile in addition to the natdnsproxy1 and naddnshostresolver1 that were already set in my example (Virtualbox) Vagrantfile. These settings can be found in the Virtualbox documentation for the correct usage.

To sum it up, use the VT-x passthrough/"virtualize" option in your VM CPU settings, give the VM adequate memory, don't allow that memory to be swapped on the "root" host machine, and try to make sure your network ranges don't overlap or you'll have routing trouble.

Here is the Vagrantfile I was working from, it is based almost entirely on andreptb's gist for the modern.ie vagrant setup. https://gist.github.com/andreptb/57e388df5e881937e62a

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

# box name into env var, same script can be used with different boxes. Defaults to win7-ie11.
box_name = box_name = ENV['box_name'] != nil ? ENV['box_name'].strip : 'win7-ie11'
# box repo into env var, so private repos/cache can be used. Defaults to http://aka.ms
box_repo = ENV['box_repo'] != nil ? ENV['box_repo'].strip : 'http://aka.ms'

Vagrant.configure("2") do |config|
  # If the box is win7-ie11, the convention for the box name is modern.ie/win7-ie11
  config.vm.box = "modern.ie/" + box_name
  # If the box is win7-ie11, the convention for the box url is http://aka.ms/vagrant-win7-ie11
  config.vm.box_url = box_repo + "/vagrant-" + box_name
  # big timeout since windows boot is very slow
  config.vm.boot_timeout = 500

  # rdp forward
  config.vm.network "forwarded_port", guest: 3389, host: 3389, id: "rdp", auto_correct: true

  # winrm config, uses modern.ie default user/password. If other credentials are used must be changed here
  config.vm.communicator = "winrm"
  config.winrm.username = "IEUser"
  config.winrm.password = "Passw0rd!"

  config.vm.provider "virtualbox" do |vb|
    # first setup requires gui to be enabled so scripts can be executed in virtualbox guest screen
    #vb.gui = true
    vb.customize ["modifyvm", :id, "--memory", "1024"]
    vb.customize ["modifyvm", :id, "--vram", "128"]
    vb.customize ["modifyvm", :id,  "--cpus", "2"]
    vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]
  end
end

My additional changes:

# Need the WinRM gem for managing from Linux
$ sudo gem install winrm

    config.vm.communicator = "winrm"
+  config.winrm.host = "localhost"
    config.winrm.username = "IEUser"
    config.winrm.password = "Passw0rd!"
# This one may not be necessary, I added it for completeness
+  config.vm.guest = :windows

# In order to USE the two CPUs you need the ioapic
# Virtualbox gives an error in the GUI and only shows 1 CPU in the VM otherwise
      vb.customize ["modifyvm", :id, "--cpus", "2"]
+    vb.customize ["modifyvm", :id, "--ioapic", "on"]
# We had to modify the network range because we are running Virtualbox inside VMware
+    vb.customize ["modifyvm", :id, "--natnet1", "192.168.199.0/24"]

Remove the + signs and add those lines into the Vagrantfile above and you should have an equivalent working system to what I've been using.


If you are running virualbox in a VM in vsphere, you have to ssh to the ESXi to update a configuration.

Steps:

  1. ssh to ESXi server.
  2. find the vmx file which belong to your VM find / -name *.vmx
  3. poweroff your VM.(very important, or your change will be overwrite)
  4. edit that vmx, append a new configuration at the bottom of the file: vhv.enable = "TRUE"
  5. power on your VM
  6. enjoy the Vagrant. :)

I have tried this in two VMware products. Right-click on the VM:

  • In vCloud Director 5.5 VM properties on the Hardware tab there's an "Expose hardware-assisted CPU virtualization to guest OS" checkbox, but it's grayed out for me. YMMV.
  • In vSphere Version 5.5.0 Edit Settings > Virtual Hardware > CPU the checkbox is called "Expose hardware assisted virtualization to the guest OS," and that worked for me.