Merge pull request #1929 from lxbsz/wip-64471
[teuthology.git] / build_qemu_image.sh
1 #!/bin/sh -x
2 set -e
3
4 IMAGE_URL=http://cloud-images.ubuntu.com/releases/precise/release/ubuntu-12.04-server-cloudimg-amd64-disk1.img
5
6 wget -O base.qcow2 $IMAGE_URL
7
8 image=base.raw
9 qemu-img convert -O raw base.qcow2 $image
10 rm -f base.qcow2
11
12 # Note: this assumes that sector size is 512, and that there's only one
13 # partition. very brittle.
14 START_SECT=$(fdisk -lu $image | grep ^$image | awk '{print $3}')
15 START_BYTE=$(echo "$START_SECT * 512" | bc)
16
17 root=/tmp/$$
18
19 cleanup() {
20     sudo chroot $root rm -f /etc/resolv.conf || true
21     sudo chroot $root ln -s ../run/resolvconf/resolv.conf /etc/resolv.conf || true
22         sudo umount $root/proc || true
23         sudo umount $root/sys || true
24         sudo umount $root/dev/pts || true
25         sudo umount $root
26     sudo rmdir $root
27 }
28 trap cleanup INT TERM EXIT
29
30 sudo mkdir $root
31 sudo mount -o loop,offset=$START_BYTE $image $root
32
33 # set up chroot
34 sudo mount -t proc proc $root/proc
35 sudo mount -t sysfs sysfs $root/sys
36 sudo mount -t devpts devptr $root/dev/pts
37
38 # set up network access
39 sudo chroot $root rm /etc/resolv.conf
40 sudo cp /etc/resolv.conf $root/etc/resolv.conf
41
42 # packages
43 # These should be kept in sync with ceph-qa-chef.git/cookbooks/ceph-qa/default.rb
44 sudo chroot $root apt-get -y --force-yes install iozone3 bonnie++ dbench \
45     tiobench build-essential attr libtool automake gettext uuid-dev      \
46     libacl1-dev bc xfsdump dmapi xfslibs-dev
47
48 # install ltp without ltp-network-test, so we don't pull in xinetd and
49 # a bunch of other unnecessary stuff
50 sudo chroot $root apt-get -y --force-yes --no-install-recommends install ltp-kernel-test
51
52 # add 9p fs support
53 sudo chroot $root apt-get -y --force-yes install linux-image-extra-virtual
54
55 cleanup
56 trap - INT TERM EXIT
57
58 qemu-img convert -O qcow2 $image output.qcow2
59 rm -f $image
60
61 exit 0