Move initial root contents into a hook.

This is a necessary but not complete step towards supporting Fedora and Suse
distributions. Further work is needed (e.g. to quiesce daemons on
installation).

Change-Id: If3ea6093d41a21de755db52328226b84b5a3ede6
This commit is contained in:
Robert Collins 2013-02-11 17:01:36 +13:00
parent 988bebcefb
commit 1ee3a01447
8 changed files with 50 additions and 23 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
.tox
*.egg-info
dist
*.qcow2

View File

@ -87,6 +87,16 @@ Writing an element
Make as many of the following subdirectories as you need, depending on what
part of the process you need to customise:
* root.d: Create or adapt the initial root filesystem content. This is where
alternative distribution support is added, or customisations such as
building on an existing image. If no element configures a root, the ubuntu
element will be automatically invoked to obtain an Ubuntu image.
Runs outside the chroot on the host environment, so should cleanup after
itself using the root-finished.d hook.
NB: Only one element can use this at a time.
* inputs: $ARCH=i386|amd64 $TARGET\_ROOT=/path/to/target/workarea
* block-device-size.d: Alter the size (in GB) of the disk image. This is useful
when a particular element will require a certain minimum (or maximum) size.
You can either error and stop the build, or adjust the size to match.
@ -94,8 +104,8 @@ part of the process you need to customise:
so this should be used rarely - only one element in a mix can reliably set
a size.
* outputs: $IMAGE\_SIZE={size_in_GB}
* inputs: $IMAGE_SIZE={size_in_GB}
* outputs: $IMAGE\_SIZE={size\_in\_GB}
* inputs: $IMAGE\_SIZE={size\_in\_GB}
* block-device.d: customise the block device that the image will be made on
(e.g. to make partitions).

View File

@ -41,7 +41,6 @@ INSTALL_PACKAGES=""
COMPRESS_IMAGE="true"
TEMP=`getopt -o a:ho:xucp: -n $SCRIPTNAME -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
echo "XXX $TEMP"
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
@ -76,13 +75,11 @@ IMAGE_ELEMENT=$($SCRIPT_HOME/element-info --expand-dependencies $IMAGE_ELEMENT)
echo "Building elements: $IMAGE_ELEMENT"
echo "If prompted for sudo, install sudoers.d/img-build-sudoers into /etc/sudoers.d and restart the build."
mkdir -p $IMG_PATH
# TODO: make an element.
# TODO: make into an element.
ensure_nbd
mk_build_dir
ensure_base_available
eval_run_d block-device-size "IMAGE_SIZE="
qemu-img create -f qcow2 -o preallocation=metadata $TMP_IMAGE_PATH ${IMAGE_SIZE}G

View File

@ -0,0 +1 @@
Use Ubuntu cloud images as the baseline for built disk images.

View File

@ -0,0 +1,22 @@
#!/bin/bash
# These are useful, or at worst not harmful, for all images we build.
set -e
[ -n "$ARCH" ]
[ -n "$TARGET_ROOT" ]
IMG_PATH=~/.cache/image-create
CLOUD_IMAGES=${CLOUD_IMAGES:-http://cloud-images.ubuntu.com/}
RELEASE=${RELEASE:-quantal}
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$RELEASE-server-cloudimg-$ARCH-root.tar.gz}
mkdir -p $IMG_PATH
# TODO: don't cache -current forever.
if [ ! -f $IMG_PATH/$BASE_IMAGE_FILE ] ; then
echo "Fetching Base Image"
wget $CLOUD_IMAGES/$RELEASE/current/$BASE_IMAGE_FILE -O $IMG_PATH/$BASE_IMAGE_FILE.tmp
mv $IMG_PATH/$BASE_IMAGE_FILE.tmp $IMG_PATH/$BASE_IMAGE_FILE
fi
# Extract the base image
sudo tar -C $TARGET_ROOT -xzf $IMG_PATH/$BASE_IMAGE_FILE

View File

@ -3,7 +3,6 @@
set -e
set -o xtrace
# XXX: grub-probe on the nbd0 device returns nothing - workaround, manually
# specify modules. https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1073731

View File

@ -15,9 +15,6 @@
# options for create-baremetal-image.sh
ARCH=${ARCH:-$(dpkg --print-architecture)}
RELEASE=${RELEASE:-quantal}
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$RELEASE-server-cloudimg-$ARCH-root.tar.gz}
CLOUD_IMAGES=${CLOUD_IMAGES:-http://cloud-images.ubuntu.com/}
FS_TYPE=${FS_TYPE:-ext4}
# Used to set the file extension only at this stage.
IMAGE_TYPE=${IMAGE_TYPE:-qcow2}
@ -25,5 +22,4 @@ IMAGE_NAME=${IMAGE_NAME:-image}
export IMAGE_SIZE=${IMAGE_SIZE:-2} # N.B. This size is in GB
# Set via the CLI normally.
# IMAGE_ELEMENT=
IMG_PATH=~/.cache/image-create
export ELEMENTS_DIR=$(dirname $0)/../elements

View File

@ -48,15 +48,6 @@ function ensure_nbd () {
(lsmod | grep '^nbd ') || sudo modprobe nbd max_part=16
}
function ensure_base_available () {
# TODO: don't cache -current forever.
if [ ! -f $IMG_PATH/$BASE_IMAGE_FILE ] ; then
echo "Fetching Base Image"
wget $CLOUD_IMAGES/$RELEASE/current/$BASE_IMAGE_FILE -O $IMG_PATH/$BASE_IMAGE_FILE.tmp
mv $IMG_PATH/$BASE_IMAGE_FILE.tmp $IMG_PATH/$BASE_IMAGE_FILE
fi
}
function ensure_sudo () {
sudo echo "Ensuring sudo is available"
}
@ -69,8 +60,17 @@ function mount_tmp_image () {
}
function create_base () {
# Extract the base image
sudo tar -C $TMP_MOUNT_PATH -xzf $IMG_PATH/$BASE_IMAGE_FILE
# Copy data in to the root.
TARGET_ROOT=$TMP_MOUNT_PATH run_d root
if [ -z "$(ls /tmp/foo)" ] ; then
# Nothing copied in, use Ubuntu.
echo "Adding ubuntu element as / had no contents"
IMAGE_ELEMENT=$($SCRIPT_HOME/element-info --expand-dependencies $IMAGE_ELEMENT ubuntu)
generate_hooks
echo "Now building: $IMAGE_ELEMENT"
TARGET_ROOT=$TMP_MOUNT_PATH run_d root
fi
# Configure Image
# Setup resolv.conf so we can chroot to install some packages
@ -243,3 +243,4 @@ function copy_elements_lib () {
sudo mkdir -p $TMP_MOUNT_PATH/lib/diskimage-builder
sudo cp -t $TMP_MOUNT_PATH/lib/diskimage-builder $_LIB/elements-functions
}