From 48e8e0a7e63c423206421077e7e7f26b4194c15e Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Thu, 21 Jun 2012 19:23:42 -0700 Subject: [PATCH] Add script to create a vm image with extra packages --- build_qemu_image.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 build_qemu_image.sh diff --git a/build_qemu_image.sh b/build_qemu_image.sh new file mode 100755 index 0000000000000..614f519aafdc2 --- /dev/null +++ b/build_qemu_image.sh @@ -0,0 +1,61 @@ +#!/bin/sh -x +set -e + +IMAGE_URL=http://cloud-images.ubuntu.com/releases/precise/release/ubuntu-12.04-server-cloudimg-amd64-disk1.img + +wget -O base.qcow2 $IMAGE_URL + +image=base.raw +qemu-img convert -O raw base.qcow2 $image +rm -f base.qcow2 + +# Note: this assumes that sector size is 512, and that there's only one +# partition. very brittle. +START_SECT=$(fdisk -lu $image | grep ^$image | awk '{print $3}') +START_BYTE=$(echo "$START_SECT * 512" | bc) + +root=/tmp/$$ + +cleanup() { + sudo chroot $root rm -f /etc/resolv.conf || true + sudo chroot $root ln -s ../run/resolvconf/resolv.conf /etc/resolv.conf || true + sudo umount $root/proc || true + sudo umount $root/sys || true + sudo umount $root/dev/pts || true + sudo umount $root + sudo rmdir $root +} +trap cleanup INT TERM EXIT + +sudo mkdir $root +sudo mount -o loop,offset=$START_BYTE $image $root + +# set up chroot +sudo mount -t proc proc $root/proc +sudo mount -t sysfs sysfs $root/sys +sudo mount -t devpts devptr $root/dev/pts + +# set up network access +sudo chroot $root rm /etc/resolv.conf +sudo cp /etc/resolv.conf $root/etc/resolv.conf + +# packages +# These should be kept in sync with ceph-qa-chef.git/cookbooks/ceph-qa/default.rb +sudo chroot $root apt-get -y --force-yes install iozone3 bonnie++ dbench \ + tiobench build-essential attr libtool automake gettext uuid-dev \ + libacl1-dev bc xfsdump dmapi xfslibs-dev + +# install ltp without ltp-network-test, so we don't pull in xinetd and +# a bunch of other unnecessary stuff +sudo chroot $root apt-get -y --force-yes --no-install-recommends install ltp-kernel-test + +# add 9p fs support +sudo chroot $root apt-get -y --force-yes install linux-image-extra-virtual + +cleanup +trap - INT TERM EXIT + +qemu-img convert -O qcow2 $image output.qcow2 +rm -f $image + +exit 0 -- 2.39.5