Lyte's Blog

Bad code, bad humour and bad hair.

Applying Settings to All Vagrant VMs

After upgrading from Ubuntu 12.04 (“Precise Pangolin”) to 12.10 (“Quantal Quetzal”) I lost the DNS resolver that VirtualBox normally provides on 10.0.2.3, meaning I couldn’t boot my Vagrant VMs.

Finding an answer that worked around it for singular VMs, I wanted something that worked for all VMs on the laptop (at least until I can fix the actually broken DNS resolver) and I’ve found one.

As per http://docs-v1.vagrantup.com/v1/docs/vagrantfile.html, it’s possible to specify additional parameters to Vagrant in ~/.vagrant.d/Vagrantfile - but it’s not exactly clear how, turns out you can just place them in a normal config block like so:

1
2
3
Vagrant::Config.run do |config|
    config.vm.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end

Before applying the fix I was getting hangs at “Waiting for VM to boot” like so:

1
2
3
4
5
6
7
8
9
10
$ vagrant up
[default] VM already created. Booting if it's not already running...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.

after applying the fix, it continues on:

1
2
3
4
5
6
7
...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Configuring and enabling network interfaces...
[default] Setting host name...
[default] Mounting shared folders...
[default] -- v-root: /vagrant

Edit: I just thought I’d add that the config has changed slightly with Vagrant 1.1+, so you now need a “v2 config block” (see: http://docs.vagrantup.com/v2/virtualbox/configuration.html):

1
2
3
4
5
Vagrant::configure('2') do |config|
  config.vm.provider "virtualbox" do |v|
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
  end
end

Comments