Tag/tag.png

Unsupported Version
This article applies to an unsupported version of Ubuntu. More info...

Tag/tag.png

Candidate for Deletion
This article may not be appropriate for this wiki, and may be deleted. More info...

Ubuntu Release: JeOS 8.10 (Intrepid Ibex) - (Note : JeOS is discontinued as a standalone product. An equivalent installation can be done now with the standard Ubuntu Server installer by pressing F4 at the first screen)

Introduction

This page documents the building of a virtual appliance using Ubuntu Server Edition's JeOS and vmbuilder. It is an update of the original article, covering the same process, but using Ubuntu's vmbuilder.

IconsPage/warning.png However helpful this document may be for those people using vmbuilder to install a normal (but minimal) Ubuntu server, this document contains instructions specific to the building of an image intended to be mass-deployed (appliance).

What is JeOS?

Ubuntu JeOS (pronounced "Juice") is an efficient variant of the Ubuntu Server operating system, configured specifically for virtual appliances. It is no longer available as a CD image for download. Now you can install it with either:

JeOS is a specialized installation of Ubuntu Server Edition with a tuned kernel that contains only the base elements needed to run within a virtualized environment.

Ubuntu JeOS has been tuned to take advantage of key performance technologies in the latest virtualization products from VMware. This combination of reduced size and optimized performance ensures that Ubuntu JeOS Edition delivers a highly efficient use of server resources in large virtual deployments.

Without unnecessary drivers, and only the minimal required packages, ISVs can configure their supporting OS exactly as they require. Updates, whether for security or enhancement reasons, will be limited to the bare minimum of what is required in their specific environment. In turn, users deploying virtual appliances built on top of JeOS will have to go through fewer updates and therefore less maintenance than they would have had to with a standard full installation of a server.

What is Ubuntu's vmbuilder?

vmbuilder is a script that automates the process of creating a ready to use VM based on Ubuntu. There is no need for a JeOS CD image. The currently supported hypervisors are KVM, Xen and VMware.

You can pass command line options to add extra packages, remove packages, choose which version of Ubuntu, which mirror, etc. On recent hardware with plenty of RAM, tmpdir in /dev/shm or using a tmpfs, and a local mirror, you can bootstrap a VM in less than a minute.

First introduced as a shell script in Ubuntu 8.04 LTS, ubuntu-vm-builder started as a hack to help developers test their new code in a virtual machine without having to restart from scratch each time. As Ubuntu administrators started to notice this script, a few of them went on improving it and adapting it for so many use cases that Søren Hansen (the author of the script and Ubuntu virtualization specialist, not the golf player) decided to rewrite it from scratch for Intrepid as a Python script with a few new design goals:

The general principles and commands remain the same.

Initial setup

In this article, we assume that you have installed and configured libvirt and KVM locally on the machine you are using. For details on how to perform this, please refer to:

We also assume that you know how to use a text based text editor such as nano or vi. If you have not used any of them before, you can get an overview of the various text editors available by reading the PowerUsersTextEditors page. This tutorial has been done on KVM, but the general principle should remain on other virtualization technologies.

Install vmbuilder

The name of the package that we need to install is python-vm-builder:

Note: if you are running hardy, you can still perform most of this using the older version of the package named ubuntu-vm-builder, there are only a few changes to the syntax of the tool for the command line parameters. On the other hand, all templates and configuration files syntax have been modified. Note as well that python-vm-builder includes a wrapper to the ubuntu-vm-builder command so that scripts written for hardy should remain functional on Intrepid (again to the exception of templates/configuration files).

Defining your virtual machine

Defining a virtual machine with Ubuntu's vmbuilder is quite simple, but here are a few things to consider:

The vmbuilder command line has 2 main parameters: the virtualization technology (hypervisor) and the targeted distribution. Optional parameters are quite numerous and can be found using the following command:

Note: you need to specify which hypervisor and distribution you are targeting in order to get a full list of options as some of them are specific to the tools used.

In the following, we'll pick some of those parameters to define our virtual appliance.

Base parameters

As this example is based on KVM and Ubuntu 8.10 (Intrepid Ibex), and we are likely to rebuild the same virtual machine multiple times, we'll invoke vmbuilder with the following first parameters:

Notes:

installation parameters

Configuring the network

Assigning a fixed IP address

As a virtual appliance may be deployed on various very different networks, it is very difficult to know what the actual network will look like. In order to simplify configuration, it is a good idea to take an approach similar to what network hardware vendors usually do, namely assigning an initial fixed IP address to the appliance in a private class network that you will provide in your documentation. An address in the range 192.168.0.0/24 is usually a good choice.

To do this we'll use the following parameters:

We assume for now that default values are good enough, so the resulting invocation becomes:

Modifying the libvirt template to use bridging

Because our appliance will probably need to be accessed by remote hosts, we need to configure libvirt so that the appliance uses bridge networking. To do this we use vmbuilder's template mechanism to modify the default one.

In our working directory we create the template hierarchy and copy the template we want to modify:

we can then edit mytemplates/libvirt/libvirtxml.tmpl to change

into

and specify on the command line where our modified templates are stored by adding the following option:

Notes:

Partitioning

Partitioning of the virtual appliance will have to take into consideration what you are planning to do with it. Because most appliances want to have separate storage for data, having a separate /var would make sense.

In order to do this vmbuilder provides us with --part:

In our case we will define a text file name vmbuilder.partition which will contain the following:

Note that as we are using virtual disk images, the actual sizes that we put here are maximum sizes for these volumes.

Our command line now looks like:

User and password

Again setting up a virtual appliance, you will need to provide a default user and password that is generic so that you can include it in your documentation. We will see later on in this tutorial how we will provide some security by defining a script that will be run the first time a user actually logs in the appliance, that will, among other things, ask him to change his password. In this example I will use 'user' as my user name, and 'default' as the password.

To do this we use the following optional parameters:

Our resulting command line becomes:

Installing required packages

In this example we will be installing a package (Limesurvey) that accesses a mysql database and has a web interface. We will therefore require our OS to provide us with:

This is done using vmbuilder by specifying the --addpkg command multiple times:

However, due to the way vmbuilder operates, packages that have to ask questions to the user during the post install phase are not supported and should instead be installed while interactivity can occur. This is the case of Limesurvey, which we will have to install later, once the user logs in.

Other packages that ask simple debconf question, such as mysql-server asking to set a password, the package can be installed immediately, but we will have to reconfigure it the first time the user logs in.

If some packages that we need to install are not in main, we need to list all repositories that we want to use (including main) with --comp and --ppa:

Limesurvey not being part of the archive at the moment, we'll specify it's PPA (personal package archive) address so that it is added to the VM /etc/apt/source.list, so we add the following options to the command line:

OpenSSH

Another convenient tool that we want to have on our appliance is OpenSSH, as it will provide our admins to access to access the appliance remotely. However, pushing in the wild an appliance with a pre-installed OpenSSH host key is somewhat of a security risk, since it allows one server to masquerade as another. To fix this we'll use a --firstboot script to generate a new one. (Note that we can't reliably install the OpenSSH package at boot, since we are not guaranteed to have a working network by the time the boot script runs.)

Speed consideration

Packages caching

When vmbuilder creates builds your system, it has to go fetch each one of the packages that composes it over the network to one of the official repositories, which, depending on your internet connection speed and the load of the mirror, can have a big impact on the actual build time. In order to reduce this, it is recommended to either have a local repository (which can be created using apt-mirror) or using a caching proxy such as apt-cache. The later option being much simpler to implement and requiring less disk space, it is the one we will pick in this tutorial. To install it, simply type :

once this is complete, your (empty) proxy is ready for use on http://mirroraddress:9999 and will find ubuntu repository under /ubuntu. For vmbuilder to use it, we'll have to use the --mirror option

so we add to the command line:

Note: the mirror address specified here will also be used in the /etc/apt/source.list of the newly created guest, so it is useful to specify here an address that can be resolved by the guest or to plan on resetting this address later on, such as in a --firstboot script. If you use an address which cannot be resolved, or use either 127.0.0.1 or localhost then any applications that you would like to install in your --firstlogin script, e.g. the application package, will not be installed. In that case, you may want to use the followings options that have been more recently added to vmbuilder:

Option: install a local mirror

If we are in a larger environment, it may make sense to setup a local mirror of the Ubuntu repositories. The package apt-mirror provides you with a script that will handle the mirroring for you. You should plan on having about 20 gigabyte of free space per supported release and architecture.

By default, apt-mirror uses the configuration file in /etc/apt/mirror.list. As it is set up, it will replicate only the architecture of the local machine. If you would like to support other architectures on your mirror, simply duplicate the lines starting with "deb", replacing the deb keyword by /deb-{arch} where arch can be i386, amd64, etc... For example, on an amd64 machine, to have the i386 archives as well, you will have :

Notice that the source packages are not mirrored as they are seldom used compared to the binaries and they do take a lot more space, but they can be easily added to the list.

Once the mirror has finished replicating (and this can be quite long), you need to configure Apache so that your mirror files (in /var/spool/apt-mirror if you did not change the default), are published by your Apache server. I am not going to detail this process here, as Apache configuration is not our goal and many tutorials already exist on the subject.

Installing in a RAM disk

As you can easily imagine, writing to RAM is a LOT faster than writing to disk. If you have some free memory, letting vmbuilder perform its operation in a RAMdisk will help a lot and the option --tmpfs will help you do just that:

so adding

sounds like a very good idea if you have 1G of free ram.

Packaging the application

Two option are available to us:

In our case we'll use Limesurvey as example web application for which we wish to provide a virtual appliance. As noted before, we've made a version of the package available in a PPA (personal package archive).

Finishing install on first boot and login

First boot

As we mentioned earlier, the first time the machine boots we'll need to reconfigure openssh-server so that the key generated for it is unique for each machine. Since we are planning to distribute our image, it would be really bad if all of our images had the same ssh host key as it would allow all kinds of attacks from anyone having full access to on of the images. We also use this place to expire our user account so that he is forced to change it the first time he logs in. To do this, we'll write a script called boot.sh as follow:

and we add the following option to our command line:

First login

Mysql and Limesurvey needing some user interaction during their setup, we'll set them up the first time a user logs in using a script named login.sh. We'll also use this script to let the user specify the keyboard and other locale info he wants to use:

and we add the following option to our command line:

Useful additions

Setting up for automated updates

To have your system be configured to update itself on a regular basis, we will just install unattended-upgrades, so we add the following option to our command line:

As we have put our application package in a PPA, the process will update not only the system, but also the application each time we update the version in the PPA.

ACPI event handling

For your virtual machine to be able to handle restart and shutdown events it is being sent, it is a good idea to install the acpid package as well. To do this we just add the following option:

Final command line

Using configuration files

As you can see above, command lines can become quite long and it sometimes becomes useful to store some common parameters in a configurations file. If present, the /etc/vmbuilder.cfg and ~/.vmbuilder.cfg files can do just that, and you can also override them using the -c ALTCONFIG option, pointing to whatever other file you want.

The syntax of these files is as follow:

where :

Values are evaluated in this order:

  1. program default
  2. content of the configuration files (/etc/vmbuilder.cfg, ~/.vmbuilder.cfg, file specified by -c), evaluated in that order. Sections are evaluated in the following order within each file:

    1. content of the [DEFAULT] section
    2. content of the appropriate [<hypervisor>] section

    3. content of the appropriate [<distro>] section

    4. content of the appropriate [<hypervisor>/<distro>] section

  3. values specified on the command line

so that the last one encountered will always be the one that is used.

For example, we could simplify the above command line by using the following:

where mylimesurveyappliance.cfg would contain:

or, if mirror and tmpfs is something we always want for every VM, we can define them in ~/vmbuilder.cfg as:

and remove the above 2 lines from the mylimesurveyappliance.cfg files.

Note: Configuration files are read using Python's ConfigParser module for more syntax details.

Conclusion

We sincerely hope that this tutorial will make building your own appliance simpler. For further documentation on the Ubuntu Server Edition, please refer to our Server Guide: https://help.ubuntu.com/8.10/serverguide/C/index.html. If you are interested in learning more, or have questions or suggestions, you are welcome to talk with us on:


CategoryDoc

JeOSVMBuilder (last edited 2017-09-26 16:56:40 by ckimes)