Episode #5 - Create a Vagrant box with Veewee

Loading the player...

About Episode - Duration: 9 minutes, Published: 2013-06-05

In this episode we will create a Vagrant box with Veewee. We will use Veewee to create a working Vagrant SL (Scientific Linux) 6.4 box from a SL 6.3 template. I'll demonstrate the process end-to-end. This process should work with RHEL and CentOS too.

Download: mp4 or webm

Get notified about future content via the mailing list, follow @jweissig_ on Twitter for episode updates, or use the RSS feed.

Links, Code, and Transcript

If you are new to Vagrant, then I suggest you watch episode #42, before watching this one.

In this episode we are going to create a custom Vagrant box using Veewee. Veewee is a tool for easily creating custom Vagrant boxes, it provides many virtual machine templates that can be used. I suggest checking out the Veewee Github page, it has lots of useful information.

You will need to have VirtualBox, Ruby, and Vagrant installed before you can use Veewee. To install Veewee, I just used, gem install veewee. Veewee integrates with your Vagrant install. I think of Veewee as a type of vagrant plugin, once you have Veewee installed, Vagrant will have an additional sub-command called basebox.

# install veewee
gem install veewee

Before we get started with Veewee, I always like to create a project directory. So, as I mentioned earlier, Veewee comes with a bunch of templates. Let take a look at the Veewee templates. To take a look at the templates that are provided, you can run, vagrant basebox templates. As you can see there is quite a few, and there is a wide range of operating systems that are supported, include Linux, BSD, Solaris, and even Windows. Since the list is so large, I generally pipe the output to grep.

# create project directory
mkdir veewee-sl64-x86_64
cd veewee-sl64-x86_64
# review templates
vagrant basebox templates
# grep through templates
vagrant basebox templates | grep scientificlinux

In this episode, we are going to focus on Scientific Linux, or just SL for short. We are going to create a SL 6.4 Vagrant box, and we are going to use the SL 6.3 template as a starting point. We are going to run, vagrant basebox define, what we want to call the new Vagrant box, and the template we want to use. Lets just copy this line and modify it to our needs. So now we have, vagrant basebox define sl64 x86 64, based off the SL 6.3 x86 64 version.

# define a new basebox off and existing template
vagrant basebox define 'sl64-x86_64' 'scientificlinux-6.3-x86_64-netboot'

After running this command, we are given a directory structure, inside that directory structure there are various configuration files. I should mention that you could run this command now, and it would give you a working SL 6.3 box, but we want to create a SL 6.4, so we are going to have to modify the definition and kickstart files, basically just to update the source iso image, from SL 6.3 to SL 6.4.

Before we edit the definition and kickstart files, let me briefly give you an overview of what the directory structure looks like. Located in the definitions directory, are the files Veewee uses to build our vagrant box. Most of these files are post install scripts, but there is also our definition, and kickstart file. You can open your favourite editor, and we are going to review the definition and kickstart files.

# modify your definition and kickstart files if needed
vi definitions/sl64-x86_64/definition.rb
vi definitions/sl64-x86_64/ks.cfg

In the definition file, there are three lines that need to be updated, these reference the install media. You can see out kickstart file is mentioned, and a little farther down, there is the post install scripts that are referenced.

So, were do we find the SL 6.4 install media? Lets take a look at the Scientific Linux website. Scientific Linux was put together by a few Government Labs and various Universities, it is also a Redhat derivative, just like CentOS. I found a download mirror that is geographically close me. We are going to use the “sl64 x86 64 boot ISO”. I am just going to copy that link, and use that in our definition and kickstart files.

Okay, armed with our SL boot ISO we can now update ISO source, and then we are going copy the ISO name, and update the ISO field. Lastly, we are going to update the ISO md5, taken from the Scientific Linux website, and that is it for the definitions file. Now lets review the kickstart file.

We are going to update the second line here, this points to the SL 6.4 RPMs. This is a pretty standard kickstart file, but there is one interesting thing at the bottom. A vagrant user and group will be added, along with a sudoers entry.

Okay, lets update the install url, just a copy and paste from before, replacing the ISO folder, with the OS folder. This points to the install packages needed by kickstart.

One last thing before we start building our SL 6.4 box. This step is not required but I think it is a useful piece of information to have. You can create a directory called iso. This directory will hold, you guessed it, ISO images. Basically what we are going to do, is download the ISO, that we put into the definitions file from the Scientific Linux website. This step is not required, as the Veewee install scripts will notice, and download the ISO for you. I thought it would be useful to understand where this lived in the file system hierarchy it.

# optionally download install iso
mkdir iso
wget http://ftp.scientificlinux.org/linux/scientific/6.4/x86_64/iso/SL-64-x86_64-2013-03-18-boot.iso

Okay, just to recap, we installed Veewee, created a project directory, reviewed the Veewee templates, defined a new box called “sl64 x86 64”, updated the definition and kickstart files, and lastly downloaded the install media. Now we are ready to create our new SL 6.4 box, we do this by running, vagrant basebox build ‘sl64-x86_64’.

# build the basebox
vagrant basebox build 'sl64-x86_64'

Veewee is pretty cleaver in that it automated the install. A VirtualBox GUI is even displayed, allowing you to watch what is happening along the way. As you can see here, Veewee even simulates keyboard input, pointing the installer at our kickstart script.

Our kickstart file has been executed. From this point on, it is a pretty straight forward install. The system is going to reboot, and then our Veewee post install scripts, mentioned in the definitions file, are going to run. These scripts install things like Ruby, Puppet, Chef, and the VirtualBox tools.

The basebox build is totally automated, there is no user input required, but it does take about 15 minutes for the process to complete, then you are hopefully presented with a message saying the build was successful!

If you want to do any finishing touches, you can use this ssh commend to gain remote access. To export the box we run, vagrant basebox export ‘sl64 64bit’. The end result is our SL 6.4 64bit Vagrant box!

# export your basebox
vagrant basebox export 'sl64-x86_64'

I found that this box is a little bit large, I still have some experimenting to do, I will probably start with a bare bones install and work from there, but this proves the concept works. You can now add this new SL 6.4 64-bit box, to Vagrant by running, vagrant box add sl64 64bit, and our newly create box file.

# add the box to vagrant
vagrant box add 'sl64-x86_64' 'sl64-x86_64.box'

After this we can run, vagrant init sl6.4 64-bit, to initialize our SL 6.4 64-bit box. Then we can run, vagrant up, to power on the box. Then lets run, vagrant ssh, to connect. Looks like we have a working system! Lets check a couple things, like uptime, to make sure this is out newly created box, and lets also cat the the redhat-release file.

# initialize the box
vagrant init 'sl64-x86_64'
# start the box
vagrant up
# ssh to the box
vagrant ssh
# destroy the box
vagrant destroy

Okay, now lets exit, and destroy this instance of the virtual machine.