Skip to content

Commit 48e88a8

Browse files
committed
Enable builds to set disk image size (only for KVM)
1 parent ee1b69d commit 48e88a8

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

bin/gbuild

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ def build_one_configuration(suite, arch, build_desc)
5555
unless @options[:skip_image]
5656
info "Making a new image copy"
5757
system! "make-clean-vm --suite #{suite} --arch #{arch}"
58+
59+
if build_desc["disk_size"]
60+
info "Growing target disk image"
61+
system! "grow-target-vm --suite #{suite} --arch #{arch} --size #{build_desc["disk_size"]}"
62+
end
5863
end
5964

6065
info "Starting target"
@@ -76,7 +81,13 @@ def build_one_configuration(suite, arch, build_desc)
7681
%#{ENV['DISTRO'] || 'ubuntu'} ALL=(ALL) NOPASSWD: ALL
7782
EOF" if build_desc["sudo"] and @options[:allow_sudo]
7883

84+
info "Updating apt-get repository (log in var/install.log)"
85+
system! "on-target -u root apt-get update > var/install.log 2>&1"
86+
7987
info "Preparing build environment"
88+
if build_desc["disk_size"]
89+
system! "on-target -u root bash < target-bin/complete-resize.sh > var/install.log 2>&1"
90+
end
8091
system! "on-target setarch #{@arches[arch]} bash < target-bin/init-build.sh"
8192

8293
build_desc["files"].each do |filename|
@@ -94,9 +105,6 @@ EOF" if build_desc["sudo"] and @options[:allow_sudo]
94105
end
95106
end
96107

97-
info "Updating apt-get repository (log in var/install.log)"
98-
system! "on-target -u root apt-get update > var/install.log 2>&1"
99-
100108
info "Installing additional packages (log in var/install.log)"
101109
system! "on-target -u root -e DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install #{build_desc["packages"].join(" ")} > var/install.log 2>&1"
102110

libexec/grow-target-vm

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/sh
2+
set -e
3+
4+
SUITE=lucid
5+
ARCH=amd64
6+
SIZE=10G
7+
8+
VMSW=KVM
9+
if [ -n "$USE_LXC" ]; then
10+
VMSW=LXC
11+
elif [ -n "$USE_VBOX" ]; then
12+
VMSW=VBOX
13+
fi
14+
15+
usage() {
16+
echo "Usage: ${0##*/} [OPTION]..."
17+
echo "Resize target copy of the base client's disk image."
18+
echo
19+
cat << EOF
20+
--help display this help and exit
21+
--suite U build suite U instead of lucid
22+
--arch A build architecture A (e.g. i386) instead of amd64
23+
--size N new disk image size, in
24+
EOF
25+
}
26+
27+
if [ $# != 0 ] ; then
28+
while true ; do
29+
case "$1" in
30+
--help|-h)
31+
usage
32+
exit 0
33+
;;
34+
--suite|-s)
35+
SUITE="$2"
36+
shift 2
37+
;;
38+
--arch|-a)
39+
ARCH="$2"
40+
shift 2
41+
;;
42+
--size)
43+
SIZE="$2"
44+
shift 2
45+
;;
46+
--*)
47+
echo "unrecognized option $1"
48+
exit 1
49+
;;
50+
*)
51+
break
52+
;;
53+
esac
54+
done
55+
fi
56+
57+
export LXC_SUITE=$SUITE
58+
export LXC_ARCH=$ARCH
59+
60+
OUT=target-$SUITE-$ARCH
61+
62+
case $VMSW in
63+
KVM)
64+
out="$(qemu-img resize -f qcow2 "$OUT.qcow2" "$SIZE" || echo FAILED)"
65+
if grep -q "shrink" <<<"$out"; then
66+
echo "Disk image already large enough."
67+
exit 0
68+
elif grep -q "FAILED" <<<"$out"; then
69+
exit 1
70+
else
71+
echo "$out"
72+
fi
73+
;;
74+
*)
75+
echo "Growing disk images not supported with $VMSW" >&2
76+
exit 1
77+
;;
78+
esac

target-bin/complete-resize.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install expect-dev parted
4+
swapoff -a
5+
{ cat <<\EOF; sleep 1; while pidof parted; do sleep 1; done; } | unbuffer -p parted /dev/vda
6+
rm 2
7+
resizepart 1
8+
yes
9+
100%
10+
quit
11+
EOF
12+
resize2fs /dev/vda1

0 commit comments

Comments
 (0)