A Closer Look at the KIWI Imaging System

Article Source Linux Developer Network
July 27, 2009, 8:39 am

Ever jealously looked at the geeks carrying around their Linux system on a tiny USB stick?

If the answer is yes you have probably also wondered about how to create one of these little gadgets for yourself. You may have even searched the net with your favorite search engine and found a number of HOW-TO instructions listing what at first glance appears to be an endless list of steps and commands.

With KIWI the creation of a USB stick-installed OS, the creation of an appliance, or the creation of a VM (Virtual Machine) or LiveCD with your own customized distribution has become a matter of setting up a configuration directory and running a few simple commands.

What is KIWI?

KIWI is an open source project licensed under GPL v2. The project has its roots in the openSUSE Build Service. If you have used an openSUSE LiveCD then you have used an image created by KIWI. However, KIWI does more than just create LiveCD images. KIWI supports the creation of VMware virtual machine images, Xen virtual machine images, LiveCD images, PXE (Preboot Execution Environment) images for thin clients, EC2 images (EC2 tools are a separate download and install step), as well as OEM (Original Equipment Manufacturer) images.

An OEM image is a raw image of the OS one can dump onto a hard drive or USB stick using “dd”. One of the killer features of KIWI is that it is possible to create all these different image types from one description. In short, KIWI is an imaging system that allows you to create demos, appliances, and other gadgets with your own customized OS.

I Want It, Where Do I Get It?

KIWI is hosted on berlios.de and you can pull the source using an anonymous git clone

git clone git://git.berlios.de/kiwi kiwi

a simple call to make in the top level directory will produce what you need (assuming you have the necessary required header files and tools installed).

If you would rather not build KIWI from scratch you can get rpms from the openSUSE build service

If you happen to use a SUSE-based distribution, openSUSE or SUSE Linux Enterprise, you can simply add the repository and install the packages with YaST.

How Does It Work?

For those interested in great technical details the KIWI Image System Cookbook is the place to start. The Cooking with KIWI wiki provides a good place to start experimenting with some quick examples.

From a conceptual level KIWI works as illustrated in the figure below:

As you can see the kiwi tool chain operates in a two-step process. During the preparation step KIWI uses configuration information from a file named config.xml in the image description directory, packages from a repository (multiple repositories can be configured in the xml file), and files from the image description directory to create the unpacked image directory. In the image creation step kiwi uses the unpacked image directory and information from the image description directory to create the final image.

Packages, yes you’ve noticed this potentially loaded issue. KIWI does not interact with packages directly, rather it relies on package management tools to do the right thing with respect to dependencies and package formats. KIWI supports the SUSE native Zypper package manager and it supports the Smart package manager. This should cover most everybody’s needs.

Within the image description directory at least the config.xml file must exist (for the XML tags and schema of this file please refer to the documentation). In addition to this file one can create a basic root directory tree, appropriately named “root” and all files within this tree will end up in the same place in the image to be created.

For example if you want to have a plethora of wall papers in your image and you decide that the wallpaper images should be in /usr/local/share/wallpapers you would simply place all the image files into image_description_dir/root/usr/local/share/wallpapers. With this you have an infinite possibility to customize your image. This mechanism is referred to as overlays.

In addition to the overlay mechanism, KIWI provides hooks to run scripts. One hook is implemented to run at the end of the package installation step but prior to execution of the package scripts. The second hook is provided at the beginning of the image creation process. The shell scripts executed by these hooks are expected to exist at the top level of the image description directory and are named config.sh and install.sh, respectively.

The config.xml is the specification for the image to be created. You can specify multiple repositories to be used, packages to be added or deleted from the image, what user accounts (with password) to be created in the image, and many other thing you think you want to do with the image, including easy customization of the bootsplash images.

Getting Started

One of the packages KIWI provides is a template package (kiwi-templates). These templates are supported by the KIWI maintainers and are based on JeOS (pronounced juice). JeOS stands for Just Enough Operating System, which means one gets just enough software to get a machine up and running. Once KIWI and the template package are installed you can list the templates using the command

kiwi -l

To create an image from one of these templates simply enter

kiwi -b  -d 

The templates have a default repository that will be used to retrieve the packages. You can specify a repository with the –set-repo command line option.

By default these templates use zypper as the package manager. Therefore you can only use a repository zypper can handle. The templates are also a great starting point for your own images, just copy a template configuration directory and change the config.xml file to your liking by adding packages etc. The Cooking with KIWI wiki is a great place to get more of the details that are outside the scope of this article.

One more quick note before we reach the end. All KIWI commands need to be executed as super user for the simple reason that the tools perform package installation into the image being created. Kiwi has no effect on your host system.

Wrapping Up

KIWI is a great tool to automate the creation of appliances, demo LiveCDs, or simply creating your own customized distribution. As a command line tool the process can be easily integrated into any build process eliminating the previously often “one-off” nature of appliance creation. Is it child’s play? Certainly not. A reasonable understanding of XML is a plus when working on the config.xml file and a good understanding of the way a Linux system works as a whole makes things a lot easier. If you would rather use a GUI there is hope for you yet, keep an eye on SUSE Studio, a web-based front end to KIWI.

Enjoy your Linux image creation.