From 94245ed6dbc64d32ad8da9788cef29dbe0732e6b Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Tue, 17 Jan 2023 10:26:11 +0100 Subject: Allow arbitrary image sizes --- bin/debvm-create | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'bin/debvm-create') diff --git a/bin/debvm-create b/bin/debvm-create index 95305a9..c58092c 100755 --- a/bin/debvm-create +++ b/bin/debvm-create @@ -11,7 +11,7 @@ debvm-create - Create a VM image for various Debian releases and architectures =head1 SYNOPSIS -B [B<-a> I] [B<-h> I] [B<-k> F] [B<-o> F] [B<-r> I] [B<-s> ] [B<-z> I] [B<--> I] +B [B<-a> I] [B<-h> I] [B<-k> F] [B<-o> F] [B<-r> I] [B<-s> ] [B<-z> I] [B<--> I] =head1 DESCRIPTION @@ -86,9 +86,10 @@ Without the hook, dependencies will pull the B package as needed, whic =back -=item B<-z> I, B<--size>=I +=item B<-z> I, B<--size>=I -Specify the minimum image size in giga bytes. +Specify the minimum image size as an integer and optional unit (example: 10K is 10*1024). +Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000). The resulting image will be grown as a sparse file to this size if necessary. The default is 1 GB. @@ -112,7 +113,7 @@ set -u ARCHITECTURE=$(dpkg --print-architecture) IMAGE=rootfs.ext4 -SIZE=$((1024*1024*1024)) +SIZE=1G SKIP=, SSHKEY= SUITE=unstable @@ -130,7 +131,7 @@ die() { exit 1 } usage() { - die "usage: $0 [-a architecture] [-h hostname] [-k sshkey] [-o output] [-r release] [-s task] [-z size_in_GB] [-- mmdebstrap options]" + die "usage: $0 [-a architecture] [-h hostname] [-k sshkey] [-o output] [-r release] [-s task] [-z size] [-- mmdebstrap options]" } usage_error() { echo "error: $*" 1>&2 @@ -157,7 +158,7 @@ opt_release() { SUITE=$1 } opt_size() { - SIZE=$(($1*1024*1024*1024)) + SIZE=$1 } while getopts :a:h:k:o:r:s:z:-: OPTCHAR; do @@ -296,11 +297,8 @@ set -ex mmdebstrap "$@" -IMAGESIZE=$(stat -c %s "$IMAGE") -if test "$IMAGESIZE" -lt "$SIZE"; then - truncate -s "$SIZE" "$IMAGE" - /sbin/resize2fs "$IMAGE" -fi +truncate -s ">$SIZE" "$IMAGE" +/sbin/resize2fs "$IMAGE" /sbin/tune2fs -L debvm -i 0 -O extents,uninit_bg,dir_index,has_journal "$IMAGE" # Must fsck after tune2fs: https://ext4.wiki.kernel.org/index.php/UpgradeToExt4 /sbin/fsck.ext4 -fDp "$IMAGE" -- cgit v1.2.3