Skip to content

Commit

Permalink
KVM --disksize option to grow target disk image
Browse files Browse the repository at this point in the history
This is needed for users with larger caches.
  • Loading branch information
luke-jr committed Aug 23, 2018
1 parent 5dca443 commit f67e14c
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 10 deletions.
31 changes: 21 additions & 10 deletions bin/gbuild
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def build_one_configuration(suite, arch, build_desc)
unless @options[:skip_image]
info "Making a new image copy"
system! "make-clean-vm --suite #{suite} --arch #{arch}"

if @options[:disksize]
info "Growing target disk image"
system! "grow-target-vm --suite #{suite} --arch #{arch} --size #{@options[:disksize]}G"
end
end

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

if build_desc["multiarch"]
info "Adding multiarch support (log in var/install.log)"
for a in build_desc["multiarch"]
system! "on-target -u root dpkg --add-architecture #{a} > var/install.log 2>&1"
end
end

info "Updating apt-get repository (log in var/install.log)"
system! "on-target -u root apt-get update > var/install.log 2>&1"

info "Preparing build environment"
if @options[:disksize]
system! "on-target -u root bash < target-bin/complete-resize.sh > var/install.log 2>&1"
end
system! "on-target setarch #{@arches[arch]} bash < target-bin/init-build.sh"

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

if build_desc["multiarch"]
info "Adding multiarch support (log in var/install.log)"
for a in build_desc["multiarch"]
system! "on-target -u root dpkg --add-architecture #{a} > var/install.log 2>&1"
end
end

info "Updating apt-get repository (log in var/install.log)"
system! "on-target -u root apt-get update > var/install.log 2>&1"

info "Installing additional packages (log in var/install.log)"
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"

Expand Down Expand Up @@ -186,6 +194,9 @@ OptionParser.new do |opts|
opts.on("-m MEM", "--memory MEM", "memory to allocate in MiB") do |v|
@options[:memory] = v
end
opts.on("--disksize SIZE", "grow disk image to size in GiB") do |v|
@options[:disksize] = v
end
opts.on("-c PAIRS", "--commit PAIRS", "comma separated list of DIRECTORY=COMMIT pairs") do |v|
@options[:commit] = v
end
Expand Down
78 changes: 78 additions & 0 deletions libexec/grow-target-vm
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/sh
set -e

SUITE=lucid
ARCH=amd64
SIZE=10G

VMSW=KVM
if [ -n "$USE_LXC" ]; then
VMSW=LXC
elif [ -n "$USE_VBOX" ]; then
VMSW=VBOX
fi

usage() {
echo "Usage: ${0##*/} [OPTION]..."
echo "Resize target copy of the base client's disk image."
echo
cat << EOF
--help display this help and exit
--suite U build suite U instead of lucid
--arch A build architecture A (e.g. i386) instead of amd64
--size N new disk image size, in
EOF
}

if [ $# != 0 ] ; then
while true ; do
case "$1" in
--help|-h)
usage
exit 0
;;
--suite|-s)
SUITE="$2"
shift 2
;;
--arch|-a)
ARCH="$2"
shift 2
;;
--size)
SIZE="$2"
shift 2
;;
--*)
echo "unrecognized option $1"
exit 1
;;
*)
break
;;
esac
done
fi

export LXC_SUITE=$SUITE
export LXC_ARCH=$ARCH

OUT=target-$SUITE-$ARCH

case $VMSW in
KVM)
out="$(qemu-img resize -f qcow2 "$OUT.qcow2" "$SIZE" || echo FAILED)"
if grep -q "shrink" <<<"$out"; then
echo "Disk image already large enough."
exit 0
elif grep -q "FAILED" <<<"$out"; then
exit 1
else
echo "$out"
fi
;;
*)
echo "Growing disk images not supported with $VMSW" >&2
exit 1
;;
esac
11 changes: 11 additions & 0 deletions target-bin/complete-resize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install expect-dev parted tcl
root_partno=$(perl -nle 'm[^/dev/vda(\d+)\s+/\s]&&print $1' /proc/mounts)
# TODO: Delete all swap and use space
{ cat <<EOF; sleep 1; while pidof parted; do sleep 1; done; } | unbuffer -p parted /dev/vda
resizepart Fix ${root_partno} yes 100%
quit
EOF
resize2fs /dev/vda${root_partno}

0 comments on commit f67e14c

Please sign in to comment.