Posts Tagged cloud

Howto Vagrant on Fedora using Libvirt (kvm)

Install

The following is assuming an updated Fedora 20 system.

Sudo (or Root)

sudo yum -y install libvirt-devel libxslt-devel libxml2-devel
sudo yum -y install https://dl.bintray.com/mitchellh/vagrant/vagrant_1.6.5_x86_64.rpm

Libvirt Plugins

From our favourite user (see the ‘Notes’ section about User & Space):

vagrant plugin install vagrant-mutate # Optional, only for migrating boxes
vagrant plugin install vagrant-libvirt --plugin-version=0.0.20

Get Started

Environment

To avoid using ‘–provider=libvirt’ option all the time when running vagrant commands, add the following to .bash_profile:

export VAGRANT_DEFAULT_PROVIDER=libvirt

Adding an image a box

Let’s use a Fedora 20 guest for libvirt provider (available here [1]):

vagrant box add https://vagrantcloud.com/gildub/fedora20

Alternatively, a box can be added via either:

  • Convert other providers boxes (virtualbox, etc) using vagrant-mutate [2]
  • Create your own vagrant box [3]

Init & Vagrantfile

mkdir test1
cd test1

Create a Vagrantfile (or ack your own using ‘vagrant init’ to generate one):

cat > Vagrantfile <<EOF
Vagrant.configure("2") do |config|
  config.vm.define :vm1 do |vm|
    vm.vm.box = "fedora20"
    vm.vm.network :private_network, :ip => '192.168.200.40'
    vm.vm.network :private_network, :ip => '192.168.201.40'
  end
end
EOF

Run

vagrant up

Notes

User & Space

Any user will do but it’s preferable not to use ‘root’. 

Keep in mind that boxes, among other things, are stored in ‘~/.vagrant’.  And also ‘/var/lib/libvirt/’ can grow quickly, so keep it provisioned.

Libvirt Plugin Version

Don’t forget to specify the version wen installing vagrant-libvirt plugin otherwise you might end up using an older version with issues.

Private networks

Private networks are NATed therefore only visible from the host and have internet access accordingly.

Libvirt & SELinux

To avoid using ‘root’ for testing, the following provides full credentials to the specified user. Thanks to purpleidea [4].

sudo sh -c "cat >> /etc/polkit-1/localauthority/50-local.d/vagrant.pkla <<EOF
[Allow $USERNAME libvirt management permissions]
Identity=unix-user:$USERNAME
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
EOF"

Fedora 20 Guests

There is an issue with Fedora 20 guests during the network setup. A fix is available here [5] and should make it to the next release.

Links

[1] https://vagrantcloud.com/gildub/fedora20
[2] https://github.com/sciurus/vagrant-mutate
[3] https://github.com/pradels/vagrant-libvirt/tree/master/example_box
[4] https://ttboj.wordpress.com/2013/12/09/vagrant-on-fedora-with-libvirt/
[5] https://github.com/mitchellh/vagrant/commit/bd4d4284c473860b800906e4db889b5a04552d70

, , , , ,

Leave a comment