-
Notifications
You must be signed in to change notification settings - Fork 292
/
build_qemu_image.sh
executable file
·61 lines (46 loc) · 1.73 KB
/
build_qemu_image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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