summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Sprickerhof <git@jochen.sprickerhof.de>2023-01-17 10:26:11 +0100
committerJochen Sprickerhof <git@jochen.sprickerhof.de>2023-01-17 11:07:05 +0100
commit94245ed6dbc64d32ad8da9788cef29dbe0732e6b (patch)
treef9d6f29eb0793c1bf6bff2fb1af1424352e69813
parentf524f063ea335221c1ee2a74ba18f7b5a808fdb5 (diff)
downloaddebvm-94245ed6dbc64d32ad8da9788cef29dbe0732e6b.tar.gz
Allow arbitrary image sizes
-rwxr-xr-xbin/debvm-create20
-rwxr-xr-xtests/dist-upgrades.sh2
2 files changed, 10 insertions, 12 deletions
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<debvm-create> [B<-a> I<architecture>] [B<-h> I<hostname>] [B<-k> F<sshkey>] [B<-o> F<output>] [B<-r> I<release>] [B<-s> <task>] [B<-z> I<size_in_GB>] [B<--> I<mmdebstrap options>]
+B<debvm-create> [B<-a> I<architecture>] [B<-h> I<hostname>] [B<-k> F<sshkey>] [B<-o> F<output>] [B<-r> I<release>] [B<-s> <task>] [B<-z> I<size>] [B<--> I<mmdebstrap options>]
=head1 DESCRIPTION
@@ -86,9 +86,10 @@ Without the hook, dependencies will pull the B<usrmerge> package as needed, whic
=back
-=item B<-z> I<size_in_GB>, B<--size>=I<size_in_GB>
+=item B<-z> I<size>, B<--size>=I<size>
-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"
diff --git a/tests/dist-upgrades.sh b/tests/dist-upgrades.sh
index 177712b..b90f17b 100755
--- a/tests/dist-upgrades.sh
+++ b/tests/dist-upgrades.sh
@@ -37,7 +37,7 @@ EOF
chmod +x upgrade
ssh-keygen -f "$SSH_KEYPATH" -N ''
-debvm-create -k "$SSH_KEYPATH.pub" -r jessie -z 3 -- --customize-hook="copy-in upgrade /usr/local/bin"
+debvm-create --sshkey="$SSH_KEYPATH.pub" -r jessie --size=3G -- --customize-hook="copy-in upgrade /usr/local/bin"
SSH_PORT=2222
for RELEASE in stretch buster bullseye bookworm sid; do