Skip to content

Commit f67e14c

Browse files
committed
KVM --disksize option to grow target disk image
This is needed for users with larger caches.
1 parent 5dca443 commit f67e14c

File tree

3 files changed

+110
-10
lines changed

3 files changed

+110
-10
lines changed

bin/gbuild

Lines changed: 21 additions & 10 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 @options[:disksize]
60+
info "Growing target disk image"
61+
system! "grow-target-vm --suite #{suite} --arch #{arch} --size #{@options[:disksize]}G"
62+
end
5863
end
5964

6065
info "Starting target"
@@ -76,7 +81,20 @@ 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+
if build_desc["multiarch"]
85+
info "Adding multiarch support (log in var/install.log)"
86+
for a in build_desc["multiarch"]
87+
system! "on-target -u root dpkg --add-architecture #{a} > var/install.log 2>&1"
88+
end
89+
end
90+
91+
info "Updating apt-get repository (log in var/install.log)"
92+
system! "on-target -u root apt-get update > var/install.log 2>&1"
93+
7994
info "Preparing build environment"
95+
if @options[:disksize]
96+
system! "on-target -u root bash < target-bin/complete-resize.sh > var/install.log 2>&1"
97+
end
8098
system! "on-target setarch #{@arches[arch]} bash < target-bin/init-build.sh"
8199

82100
build_desc["files"].each do |filename|
@@ -94,16 +112,6 @@ EOF" if build_desc["sudo"] and @options[:allow_sudo]
94112
end
95113
end
96114

97-
if build_desc["multiarch"]
98-
info "Adding multiarch support (log in var/install.log)"
99-
for a in build_desc["multiarch"]
100-
system! "on-target -u root dpkg --add-architecture #{a} > var/install.log 2>&1"
101-
end
102-
end
103-
104-
info "Updating apt-get repository (log in var/install.log)"
105-
system! "on-target -u root apt-get update > var/install.log 2>&1"
106-
107115
info "Installing additional packages (log in var/install.log)"
108116
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"
109117

@@ -186,6 +194,9 @@ OptionParser.new do |opts|
186194
opts.on("-m MEM", "--memory MEM", "memory to allocate in MiB") do |v|
187195
@options[:memory] = v
188196
end
197+
opts.on("--disksize SIZE", "grow disk image to size in GiB") do |v|
198+
@options[:disksize] = v
199+
end
189200
opts.on("-c PAIRS", "--commit PAIRS", "comma separated list of DIRECTORY=COMMIT pairs") do |v|
190201
@options[:commit] = v
191202
end

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
4+
DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install expect-dev parted tcl
5+
root_partno=$(perl -nle 'm[^/dev/vda(\d+)\s+/\s]&&print $1' /proc/mounts)
6+
# TODO: Delete all swap and use space
7+
{ cat <<EOF; sleep 1; while pidof parted; do sleep 1; done; } | unbuffer -p parted /dev/vda
8+
resizepart Fix ${root_partno} yes 100%
9+
quit
10+
EOF
11+
resize2fs /dev/vda${root_partno}

0 commit comments

Comments
 (0)