Wednesday, May 8, 2013

Using Vagrant outside of the "Norm"

Vagrant has come along way with the version 1.0. Now you are freed from the handcuffs of Virtualbox. This is great news to be able to use any type of virtual machine. KVM is a common virtual machine used in production environments and its built in to linux. All it takes is installing a few packages and you can be up and running vagrant with kvm.

There is are a couple things that we need do first.
Install Vagrant's latest version from the download site.

Then install the plugin.
vagrant plugin install vagrant-kvm
vagrant plugin list
view raw gistfile1.sh hosted with ❤ by GitHub
Once installed then we need to get a box and convert it for the kvm provider.
#!/bin/bash
# get-vagrant-box.sh
vagrant box add precise64 http://files.vagrantup.com/precise64.box
pushd ~/.vagrant.d/boxes/precise64/
cp -R virtualbox/ kvm
cd kvm
# copy the Vagrantfile and metadata.json file in this directory
pwd
popd
{"provider": "kvm"}
view raw metadata.json hosted with ❤ by GitHub
# Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.base_mac = "00163e779fe9"
config.vm.network :private_network, ip: "192.168.2.100"
end
# Load include vagrant file if it exists after the auto-generated
# so it can override any of the settings
include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__)
load include_vagrantfile if File.exist?(include_vagrantfile)
view raw Vagrantfile hosted with ❤ by GitHub

Here is a simple Vagrantfile you need to spin up your own KVM vagrant instance.
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
end
view raw Vagrantfile hosted with ❤ by GitHub

This is about as easy as it gets.
vagrant up provider=kvm

The code base for vagrant-kvm is located here. https://github.com/adrahon/vagrant-kvm#quick-start

1 comment:

  1. Great, thanks. I've been having performance problems with bundler gem installations on virtualbox lately. I wonder if this will help.

    ReplyDelete