Add tar as an output type

Add support for d-i-b to create tarballs, the primary consumer for
tarball images would be linux containers.

Change-Id: I27d67401f3e4415226a4a51e1dde46f739c0220a
This commit is contained in:
Derek Higgins 2014-04-28 23:33:59 +01:00
parent 50cb019a25
commit e7d105a751
3 changed files with 31 additions and 3 deletions

View File

@ -23,7 +23,9 @@ What tools are there?
Element dependencies are automatically included. Support for other Element dependencies are automatically included. Support for other
architectures depends on your environment being able to run binaries of that architectures depends on your environment being able to run binaries of that
platform. For instance, to enable armhf on Ubuntu install the qemu-user-static platform. For instance, to enable armhf on Ubuntu install the qemu-user-static
package. package. The default output format from disk-image-create is qcow2. To instead
output a tarball pass in "-t tar". This tarball could then be used as an image
for a linux container(see docs/docker.md).
* ramdisk-image-create -o filename {element} [{element} ...] : Create a kernel+ * ramdisk-image-create -o filename {element} [{element} ...] : Create a kernel+
ramdisk pair for running maintenance on bare metal machines (deployment, ramdisk pair for running maintenance on bare metal machines (deployment,

View File

@ -46,6 +46,7 @@ function show_options () {
echo "Options:" echo "Options:"
echo " -a i386|amd64|armhf -- set the architecture of the image(default amd64)" echo " -a i386|amd64|armhf -- set the architecture of the image(default amd64)"
echo " -o imagename -- set the imagename of the output image file(default image)" echo " -o imagename -- set the imagename of the output image file(default image)"
echo " -t qcow2|tar -- set the imagetype of the output image file(default qcow2)"
echo " -x -- turn on tracing" echo " -x -- turn on tracing"
echo " -u -- uncompressed; do not compress the image - larger but faster" echo " -u -- uncompressed; do not compress the image - larger but faster"
echo " -c -- clear environment before starting work" echo " -c -- clear environment before starting work"
@ -83,7 +84,7 @@ function show_options () {
INSTALL_PACKAGES="" INSTALL_PACKAGES=""
COMPRESS_IMAGE="true" COMPRESS_IMAGE="true"
TEMP=`getopt -o a:ho:xucnp: -l no-tmpfs,offline,help,min-tmpfs:,image-size:,image-cache:,max-online-resize: -n $SCRIPTNAME -- "$@"` TEMP=`getopt -o a:ho:t:xucnp: -l no-tmpfs,offline,help,min-tmpfs:,image-size:,image-cache:,max-online-resize: -n $SCRIPTNAME -- "$@"`
if [ $? -ne 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi if [ $? -ne 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential! # Note the quotes around `$TEMP': they are essential!
@ -93,6 +94,7 @@ while true ; do
case "$1" in case "$1" in
-a) export ARCH=$2; shift 2 ;; -a) export ARCH=$2; shift 2 ;;
-o) export IMAGE_NAME=$2; shift 2 ;; -o) export IMAGE_NAME=$2; shift 2 ;;
-t) export IMAGE_TYPE=$2; shift 2 ;;
-h|--help) show_options; exit 0;; -h|--help) show_options; exit 0;;
-x) shift; set -x;; -x) shift; set -x;;
-u) shift; export COMPRESS_IMAGE="";; -u) shift; export COMPRESS_IMAGE="";;
@ -181,9 +183,15 @@ mount_proc_dev_sys
run_d_in_target finalise run_d_in_target finalise
finalise_base finalise_base
if [ "$IMAGE_TYPE" == "tar" ]; then
sudo tar -C ${TMP_BUILD_DIR}/mnt -cf $IMAGE_NAME.tar --exclude ./sys \
--exclude ./proc --xattrs --xattrs-include=\* .
sudo chown $USER: $IMAGE_NAME.tar
fi
unmount_image unmount_image
if [ "$IS_RAMDISK" == "0" ]; then if [ "$IS_RAMDISK" == "0" -a "$IMAGE_TYPE" != "tar" ]; then
compress_and_save_image $IMAGE_NAME.$IMAGE_TYPE compress_and_save_image $IMAGE_NAME.$IMAGE_TYPE
else else
# This is a ramdisk build, we have already extracted the kernel and ramdisk # This is a ramdisk build, we have already extracted the kernel and ramdisk

18
docs/docker.md Normal file
View File

@ -0,0 +1,18 @@
Creating Docker Images
======================
disk-image-create can be used to create a tarball suitable to be imported as a
docker image. To do this you can change the output of disk-image-create to tar
with the -t flag and run docker e.g.
```
disk-image-create -o image -t tar fedora selinux-permissive
```
Assuming you have docker running and have permission to use it, the tarball can
be imported into docker and run.
```
docker import - image:test1 < image.tar
docker run -t -i image:test1 /bin/bash
```