Last Updated: February 25, 2016
·
4.085K
· bt3gl

Getting Started with Vagrant in Fedora 20

Updating the Kernel

Before starting, you need to make sure that the kernel is up to date, otherwise you can get a DKMSError. To find information about the kernel type:

$ cat /proc/version

Or, to check the kernels that are installed:

$ rpm -q kernel

To check if you are using the latest Kernel, the output of the following commands should match:

$ rpm -qa kernel |sort -V |tail -n 1
$ uname -r

Install VirtualBox

Add the VirtualBox Repository

$ cd /etc/yum.repos.d/
$ wget http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo
$ yum update

Installing

$ yum install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms
$ yum install VirtualBox-4-3  (or the latest)

Rebuild the Kernel Module

$ service vboxdrv setup

or

$ /etc/init.d/vboxdrv setup

Adding Users

Add VirtualBox users to vboxusers group:

$ usermod -a -G vboxusers USERNAME

In case you get a kernel error, try:

$ KERN_DIR=/usr/src/kernels/`uname -r`
$ yum export KERN_DIR

Running

$ virtualbox

Connecting to Vagrant

Vagrant is a tool to manage virtual machines. Using the command vagrant up allow you to work in a clean environment based on a standard template.

Installing

Download the source from https://www.vagrantup.com/downloads.html and type:

$ rpm -U vagrant*

Creating a Ubuntu VM

Simple like this:

$ vagrant init hashicorp/precise32
$ vagrant up

Now, you can SSH to it:

$ vagrant ssh

Yes, it's that easy!

Removing all Traces

$ vagrant destroy

Project Setup

You can configure your project using a Vagrantfile, which marks the root directory of the project. This file also describe the machine resources. To create a Vagrant file do:

$ vagrant init

It should be committed to version control with the project. This way, every person working with the project can benefit from Vagrant.

Boxes

The standard templates are base boxes, which allows you to easily clone virtual machines.
You can download publicly available boxes by:

$ vagrant box add {title} {url}

To start the box:

$ vagrant init {title}
$ vagrant up

To configure a box to be used as the base in a project, you edit the Vagrantfile with the name of the box (hashicorp/precise32):

Vagrant.configure("2") do |config|
    config.vm.box = "hashicorp/precise32"
end

Examples of boxes can be found at http://www.vagrantbox.es.

Synced Folders

Vagrant automatically syncs files to and from the guest machine. By default it shares under /vagrant in the guest machine.

Provisioning

It allows to automatically install software and alter configurations in boxes. You could install directly inside the box, but by provisioning you make the process repeatable.

Vagrant will automatically install software when you vagrant up, so that the guest machine can be repeatably created and ready-to-use.

To install something with provisioning, create a bootstrap.sh script in the /vagrant folder with the following contend:

#!/usr/bin/env bash
apt-get update
apt-get install -y apache2
rm -rf /var/www
ln -fs /vagrant /var/www

Now configure the Vagrantfile to run the script when up, adding the provision line:

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise32"
  config.vm.provision :shell, path: "bootstrap.sh"

Run $ vagrant up and that's it!

In the Cloud

To have Vagrant in the cloud, sign up at https://vagrantcloud.com.

You can share your boxes there! In the terminal type:

$ vagrant login
$ vagrant share --sh

To share your box with someone:

$ vagrant connect --sh [SHARE NAME]