racker/diskimage-builder

Name: diskimage-builder

Owner: racker

Description: Image building tools for OpenStack

Created: 2013-09-17 22:12:19.0

Updated: 2014-01-08 00:37:26.0

Pushed: 2013-09-20 20:27:18.0

Homepage: http://openstack.org

Size: 630

Language: Shell

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Image building tools for Openstack

These tools are the components of TripleO (https://github.com/openstack/tripleo-incubator) that are responsible for building disk images.

This repository has the core functionality for building disk images, file system images and ramdisk images for use with OpenStack (both virtual and bare metal). The core functionality includes the various operating system specific modules for disk/filesystem images, and deployment and hardware inventory ramdisks.

The TripleO project also develops elements that can be used to deploy OpenStack itself. These live in the TripleO elements repository (https://github.com/openstack/tripleo-image-elements).

What tools are there?
Why?

Automation: While users and operators can manually script or put together ram disks and disk images, mature automation makes customisation and testing easier.

Installation

Invocation

The scripts can generally just be run. Options can be set on the command line or by exporting variables to override those present in lib/img-defaults. -h to get help. The image building scripts expect to be able to invoke commands with sudo, so if you want them to run non-interactively, you should either run them as root, with sudo -E, or allow your build user to run any sudo command without password.

Using the variable ELEMENTS_PATH will allow to specify multiple elements locations. It's a colon (:) separated path list, and it will work in a first path/element found, first served approach. The included elements tree is used when no path is supplied, and is added to the end of the path if a path is supplied.

Requirements

If you have 4GB of available physical RAM*, or more, diskimage-builder will create a tmpfs mount to build the image in. This will improve image build time by building in RAM. This can be disabled completely by passing –no-tmpfs to disk-image-create. ramdisk-image-create does not use a tmpfs mount. If tmpfs is not used, you will need enough room in /tmp to store two uncompressed cloud images. If you do have tmpfs, you will still need /tmp space for one uncompressed cloud image and about 20% of that for working files.

* As reported by /proc/meminfo MemTotal

Caches and offline mode

Since retrieving and transforming operating system image files, git repositories, Python or Ruby packages, and so on can be a significant overhead, we cache many of the inputs to the build process in ~/.cache/image-create/. The writing an element documention describes the interface within disk-image-builder for caching. When invoking disk-image-builder the –offline option will instruct disk-image-builder to not refresh cached resources.

Note that we don't maintain operating system package caches, instead depending on your local infrastructure (e.g. Squid cache, or an APT or Yum proxy) to facilitate caching of that layer, so you need to arrange independently for offline mode.

Base images

These are cached by the standard elements - ubuntu, fedora.

source-repositories

Git repositories and tarballs obtained via the source-repositories element will be cached.

C and C++ compilation

Ccache is configured by the base element. Any compilation that honours ccache will be cached.

PyPI

The pypi element will bind mount a PyPI mirror from the cache dir and configure pip and easy-install to use it.

Design

Images are built using a chroot and bind mounted /proc /sys and /dev. The goal of the image building process is to produce blank slate machines that have all the necessary bits to fulfill a specific purpose in the running of an Openstack cloud: e.g. a nova-compute node. Images produce either a filesystem image with a label of cloudimg-rootfs, or can be customised to produce whole disk images (but will still contain a filesystem labelled cloudimg-rootfs). Once the file system tree is assembled a loopback device with filesystem (or partition table and file system) is created and the tree copied into it. The file system created is an ext4 filesystem just large enough to hold the file system tree and can be resized up to 1PB in size.

An element is a particular set of code that alters how the image is built, or runs within the chroot to prepare the image. E.g. the local-config element copies in the http proxy and ssh keys of the user running the image build process into the image, whereas the vm element makes the image build a regular VM image with partition table and installed grub boot sector. The mellanox element adds support for mellanox infiniband hardware to both the deploy ramdisk and the built images.

Images start as a base ubuntu cloud image. Other distributions may be added in future, the infrastructure deliberately makes few assumptions about the exact operating system is use. The base image has opensshd running (a new key generated on first boot) and accepts use keys via the cloud metadata service, loading them into the 'ubuntu' user.

The goal of a built image is to have any global configuration ready to roll, but nothing that ties it to a specific cloud instance: images should be able to be dropped into a test cloud and validated, and then deployed into a production cloud (usually via bare metal nova) for production use. As such, the image contents can be modelled as three distinct portions:

The goal of the image building tools is to create machine images that contain the correct global content and are ready for 'last-mile' configuration by the nova metadata API, after which a configuration management system can take over (until the next deploy, when it all starts over from scratch).

Existing elements

Elements are found in the subdirectory elements. Each element is in a directory named after the element itself. Elements should have a README.md in the root of the element directory describing what it is for.

Writing an element

Conform to the following conventions:

Make as many of the following subdirectories as you need, depending on what part of the process you need to customise:

Ramdisk elements support the following files in their element directories:

Global image-build variables
Structure of an element

The above-mentioned global content can be further broken down in a way that encourages composition of elements and reusability of their components. One possible approach to this would be to label elements as either a “driver”, “service”, or “config” element. Below are some examples.

In this way, depending on the hardware and in which availability zone it is to be deployed, an image would be composed of:

zero or more driver-elements one or more service-elements zero or more config-elements

It should be noted that this is merely a naming convention to assist in managing elements. Diskimage-builder is not, and should not be, functionally dependent upon specific element names.

Debugging elements

The build-time environment and command line arguments are captured by the 'base' element and written to /etc/dib_environment and /etc/dib_arguments inside the image.

Export 'break' to drop to a shell during the image build. Break points can be set either before or after any of the hook points by exporting “break=[before|after]-hook-name”. Multiple break points can be specified as a comma-delimited string. Some examples:

Images are built such that the Linux kernel is instructed not to switch into graphical consoles (i.e. it will not activate KMS). This maximises compatibility with remote console interception hardware, such as HP's iLO. However, you will typicallly only see kernel messages on the console - init daemons (e.g. upstart) will usually be instructed to output to a serial console so nova's console-log command can function. There is an element in the tripleo-image-elements repository called “remove-serial-console” which will force all boot messages to appear on the main console.

Testing Elements

Elements can be tested using python. To create a test:

To run all the tests use testr - testr run. To run just some tests provide one or more regex filters - tests matching any of them are run - testr run apt-proxy.

Third party elements

Pending implementation. The idea is to have a search path for elements.

Copyright

Copyright 2012 Hewlett-Packard Development Company, L.P. Copyright (c) 2012 NTT DOCOMO, INC.

All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.