From e7d105a751c77b50b3ad67694178e3a501c98964 Mon Sep 17 00:00:00 2001 From: Derek Higgins Date: Mon, 28 Apr 2014 23:33:59 +0100 Subject: [PATCH] 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 --- README.md | 4 +++- bin/disk-image-create | 12 ++++++++++-- docs/docker.md | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 docs/docker.md diff --git a/README.md b/README.md index 8008e91f..7f75e413 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,9 @@ What tools are there? Element dependencies are automatically included. Support for other 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 - 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 pair for running maintenance on bare metal machines (deployment, diff --git a/bin/disk-image-create b/bin/disk-image-create index 1ae4cf11..ad4a8f6d 100755 --- a/bin/disk-image-create +++ b/bin/disk-image-create @@ -46,6 +46,7 @@ function show_options () { echo "Options:" 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 " -t qcow2|tar -- set the imagetype of the output image file(default qcow2)" echo " -x -- turn on tracing" echo " -u -- uncompressed; do not compress the image - larger but faster" echo " -c -- clear environment before starting work" @@ -83,7 +84,7 @@ function show_options () { INSTALL_PACKAGES="" 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 # Note the quotes around `$TEMP': they are essential! @@ -93,6 +94,7 @@ while true ; do case "$1" in -a) export ARCH=$2; shift 2 ;; -o) export IMAGE_NAME=$2; shift 2 ;; + -t) export IMAGE_TYPE=$2; shift 2 ;; -h|--help) show_options; exit 0;; -x) shift; set -x;; -u) shift; export COMPRESS_IMAGE="";; @@ -181,9 +183,15 @@ mount_proc_dev_sys run_d_in_target finalise 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 -if [ "$IS_RAMDISK" == "0" ]; then +if [ "$IS_RAMDISK" == "0" -a "$IMAGE_TYPE" != "tar" ]; then compress_and_save_image $IMAGE_NAME.$IMAGE_TYPE else # This is a ramdisk build, we have already extracted the kernel and ramdisk diff --git a/docs/docker.md b/docs/docker.md new file mode 100644 index 00000000..9761210f --- /dev/null +++ b/docs/docker.md @@ -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 +```