Browse Source

Merge f67e14c013 into 5dca443989

pull/172/merge
Luke Dashjr 2 years ago
parent
commit
bd71162f0d
No account linked to committer's email address
3 changed files with 110 additions and 10 deletions
  1. 21
    10
      bin/gbuild
  2. 78
    0
      libexec/grow-target-vm
  3. 11
    0
      target-bin/complete-resize.sh

+ 21
- 10
bin/gbuild View File

@@ -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"
@@ -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|
@@ -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"

@@ -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

+ 78
- 0
libexec/grow-target-vm View File

@@ -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
- 0
target-bin/complete-resize.sh View File

@@ -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}

Loading…
Cancel
Save