From 6cd0bef858db460ecb4a6b153225d15bdc62a5fd Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 23 Dec 2022 12:18:26 +0100 Subject: add documentation in pod2man format Fixes: #2 --- README.md | 4 +-- debvm-create | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ debvm-run | 56 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd1c8cc..8109b2a 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ contains the root filesystem of a (Debian) installation including an init system and a kernel. There is no partition table or bootloader. The following paths are assumed inside: * `/bin/true` is used to detect the architecture of an image - * `/vmlinuz` must be a symbolic link pointing to a regular file containing - the kernel. + * `/vmlinuz` or `/vmlinux` (depending on the architecture) must be a symbolic + link pointing to a regular file containing the kernel. * `/initrd.img` must be a symbolic link pointing to a regular file containing the initrd image. diff --git a/debvm-create b/debvm-create index a8f164d..6026a7c 100755 --- a/debvm-create +++ b/debvm-create @@ -4,6 +4,85 @@ # shellcheck disable=SC2016 # Intentional quoting technique +: <<'POD2MAN' +=head1 NAME + +debvm-create - Create a VM image for various Debian releases and architectures + +=head1 SYNOPSIS + +B [B<-a> I] [B<-h> I] [B<-k> I] [B<-m> I] [B<-o> I] [B<-p> I] [B<-r> I] [B<-s> I] [B<--> I] + +=head1 DESCRIPTION + +B is essentially a thin wrapper around B for creating a raw ext4 filesystem image for booting with B. +The purpose of these images primarily is testing the different releases and architectures. +Beyond essential packages, the image will contain B, an init system and a suitable kernel package. +Notably absent is a bootloader and partition table. +In order to boot such an image, one is supposed to extract the kernel and initrd from the image and pass it to a suitable bootloader. +No user account is created and root can login without specifying a password. + +=head1 OPTIONS + +=over 8 + +=item B<-a> I + +Specify a Debian architecture name. +By default, the native architecture is being used. +A suitable kernel image is automatically selected and installed into the image. + +=item B<-h> I + +Set the hostname of the virtual machine. +By default, the hostname is B. + +=item B<-k> I + +Install the given ssh public key file into the virtual machine image for the root user. +This option also causes the ssh server to be installed. +By default, no key or server is installed. + +=item B<-m> I + +Specify the Debian mirror to be used for downloading packages and to be configured inside the virtual machine image. +By default, B is being used. + +=item B<-o> I + +Specify the file name of the resulting virtual machine image. +By default, it is written to B. + +=item B<-p> I + +Request additional packages to be installed into the virtual machine image. +This option can be specified multiple times and packages can be separated with comma. +Package recommendations are not honoured. + +=item B<-r> I + +Use the given Debian release. +By default, B is being used. + +=item B<-s> I + +Specify the image size in giga bytes. +The default image size is 1 GB. + +=item B<--> I + +All options beyond a double dash are passed to B before the suite, target and mirror specification. +This can be used to provide additional hooks for image customization. + +=back + +=head1 SEE ALSO + + debvm-run(1) mmdebstrap(1) + +=cut +POD2MAN + set -u ARCHITECTURE=$(dpkg --print-architecture) diff --git a/debvm-run b/debvm-run index edb01ad..1081597 100755 --- a/debvm-run +++ b/debvm-run @@ -2,6 +2,62 @@ # Copyright 2022 Helmut Grohne # SPDX-License-Identifier: MIT +: <<'POD2MAN' +=head1 NAME + +debvm-run - Run a VM image created by debvm-create + +=head1 SYNOPSIS + +B [B<-g>] [B<-i> I] [B<-s> I] [B<--> I] + +=head1 DESCRIPTION + +B is essentially a thing wrapper around B for running a virtual machine image created by B or something compatible. +The virtual machine image is expected to be a raw ext4 image with file system label B. +The architecture of the machine is detected from the contained B. +It must contain a symbolic link pointing to a kernel image at B or B depending on the architecture and a symbolic link pointing to an initrd image at B. +Both are extracted and passed to B. +A net interface configured for user mode is added automatically. + +=head1 OPTIONS + +=over 8 + +=item B<-g> + +By default, the option B<-nographic> is passed to B and one interacts with the serial console of the machine. +This configuration is skipped in the presence of this option. + +=item B<-i> I + +This option specifies the location of the virtual machine image file. +By default B in the working directory is used. + +=item B<-s> I + +If given, B is configured to pass connections to I<127.0.0.1:sshport> to port 22 of the virtual machine. + +=item B<--> I + +All options beyond a double dash are passed to B. +This can be used to configure additional hardware components. +Another use of this method is passing B<-snapshot> to avoid modifying the virtual machine image. + +=back + +=head1 LIMITATIONS + +Due to the way kernel and bootloader are being extracted before running qemu, one cannot upgrade a kernel and then just reboot. +Instead, B must be terminated and B should be launched again to pick up a new kernel. + +=head1 SEE ALSO + + debvm-create(1) qemu(1) + +=cut +POD2MAN + set -u IMAGE=rootfs.ext2 -- cgit v1.2.3 From 4f4eaae62f21c8229d0e3779d1b1045cdf818dfe Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 23 Dec 2022 17:08:29 +0100 Subject: Use jessie-or-older hook in latest mmdebstrap --- debvm-create | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/debvm-create b/debvm-create index a8f164d..da1899c 100755 --- a/debvm-create +++ b/debvm-create @@ -205,8 +205,7 @@ if test "$DEBVER" -le 8; then # Use obsolete and expired keys. set -- '--keyring=/usr/share/keyrings/debian-archive-removed-keys.gpg' "$@" set -- --aptopt='Apt::Key::gpgvcommand "/usr/libexec/mmdebstrap/gpgvnoexpkeysig"' "$@" - # chfn does not work, because libpam-runtime.postinst is late setting up /etc/pam.d/common-auth et al, see #1026765 - set -- --extract-hook='chroot "$1" pam-auth-update --package --force' "$@" + set -- --hook-dir=/usr/share/mmdebstrap/hooks/jessie-or-older "$@" fi if test "$DEBVER" -ge 12; then -- cgit v1.2.3 From eca678290ac4f28f610ef05570ac6df338839490 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 23 Dec 2022 14:37:06 +0100 Subject: CI: Use local ssh key --- .gitlab-ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b2ce36c..6c8dbc5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,7 +25,7 @@ codespell: ts=$(sleepenh 0 || [ $? -eq 1 ]) for i in $(seq 30); do rv=0 - ssh $sshopt -o ConnectTimeout="$timeout" -i ~/.ssh/id -p 2222 root@localhost echo success || rv=$? + ssh $sshopt -o ConnectTimeout="$timeout" -i ssh_id -p 2222 root@localhost echo success || rv=$? test $rv -eq 0 && break ts=$(sleepenh "$ts" "$timeout" || [ $? -eq 1 ]); if test $i -eq 30; then @@ -33,7 +33,7 @@ codespell: exit 1 fi done - - ssh $sshopt -i ~/.ssh/id -p 2222 root@localhost poweroff + - ssh $sshopt -i ssh_id -p 2222 root@localhost poweroff release_test: extends: .test_script @@ -51,8 +51,8 @@ release_test: - apt-get update - apt-get dist-upgrade --yes - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client sleepenh qemu-kvm - - ssh-keygen -f ~/.ssh/id -N '' - - ./debvm-create -k ~/.ssh/id.pub -r "$RELEASE" + - ssh-keygen -f ssh_id -N '' + - ./debvm-create -k ssh_id.pub -r "$RELEASE" arch_test: extends: .test_script @@ -75,5 +75,5 @@ arch_test: - apt-get update - apt-get dist-upgrade --yes - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client sleepenh qemu-system binfmt-support arch-test qemu-user-static - - ssh-keygen -f ~/.ssh/id -N '' - - ./debvm-create -k ~/.ssh/id.pub -a $ARCHITECTURE + - ssh-keygen -f ssh_id -N '' + - ./debvm-create -k ssh_id.pub -a "$ARCHITECTURE" -- cgit v1.2.3 From 60dc263bfe8a05541feed56f00fef7ac15dc49cf Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 23 Dec 2022 14:38:30 +0100 Subject: CI: fix indention --- .gitlab-ci.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6c8dbc5..b8bb17d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,12 +41,12 @@ release_test: parallel: matrix: - RELEASE: - - sid - - bookworm - - bullseye - - buster - - stretch - - jessie + - sid + - bookworm + - bullseye + - buster + - stretch + - jessie before_script: - apt-get update - apt-get dist-upgrade --yes @@ -60,13 +60,13 @@ arch_test: parallel: matrix: - ARCHITECTURE: - - arm64 - - armhf - - i386 - - mips64el - - mipsel - - ppc64el - - s390x + - arm64 + - armhf + - i386 + - mips64el + - mipsel + - ppc64el + - s390x before_script: - | if [ ! -e /proc/sys/fs/binfmt_misc/status ]; then -- cgit v1.2.3 From 8899775ccfce4b0b9373b3e3bd00220cca349f93 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 23 Dec 2022 14:48:35 +0100 Subject: CI: drop stage (not needed) --- .gitlab-ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b8bb17d..8af5b41 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,6 @@ image: debian:sid-slim shellcheck: - stage: test script: - apt-get update - apt-get dist-upgrade --yes @@ -9,7 +8,6 @@ shellcheck: - shellcheck debvm-* codespell: - stage: test script: - apt-get update - apt-get dist-upgrade --yes @@ -37,7 +35,6 @@ codespell: release_test: extends: .test_script - stage: test parallel: matrix: - RELEASE: @@ -56,7 +53,6 @@ release_test: arch_test: extends: .test_script - stage: test parallel: matrix: - ARCHITECTURE: -- cgit v1.2.3 From 9aa4cb7de93569c35994faea051b9e390da25008 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 23 Dec 2022 22:51:50 +0100 Subject: standardize on image name rootfs.ext4 Reported-by: Johannes Schauer Marin Rodrigues --- debvm-create | 4 ++-- debvm-run | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/debvm-create b/debvm-create index 6026a7c..5fc8950 100755 --- a/debvm-create +++ b/debvm-create @@ -86,7 +86,7 @@ POD2MAN set -u ARCHITECTURE=$(dpkg --print-architecture) -IMAGE=rootfs.ext2 +IMAGE=rootfs.ext4 INCLUDE_PACKAGES=init MIRROR="http://deb.debian.org/debian" SIZE=$((1024*1024*1024)) @@ -304,4 +304,4 @@ 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 rootfs.ext2 +/sbin/fsck.ext4 -fDp "$IMAGE" diff --git a/debvm-run b/debvm-run index 1081597..729ba6d 100755 --- a/debvm-run +++ b/debvm-run @@ -32,7 +32,7 @@ This configuration is skipped in the presence of this option. =item B<-i> I This option specifies the location of the virtual machine image file. -By default B in the working directory is used. +By default B in the working directory is used. =item B<-s> I @@ -60,7 +60,7 @@ POD2MAN set -u -IMAGE=rootfs.ext2 +IMAGE=rootfs.ext4 SSHPORT= GRAPHICAL= -- cgit v1.2.3 From 86ad5dc1f589d78053eeaa7054dd5a4e5d606422 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 23 Dec 2022 22:55:37 +0100 Subject: improve documentation wording and content Reported-by: Johannes Schauer Marin Rodrigues --- debvm-create | 6 +++--- debvm-run | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/debvm-create b/debvm-create index 5fc8950..65b3c54 100755 --- a/debvm-create +++ b/debvm-create @@ -16,9 +16,9 @@ B [B<-a> I] [B<-h> I] [B<-k> I] [B =head1 DESCRIPTION B is essentially a thin wrapper around B for creating a raw ext4 filesystem image for booting with B. -The purpose of these images primarily is testing the different releases and architectures. +The purpose of these images primarily is testing the different releases and architectures without access to a physical machine of that architecture. Beyond essential packages, the image will contain B, an init system and a suitable kernel package. -Notably absent is a bootloader and partition table. +Notably absent is a bootloader and a partition table. In order to boot such an image, one is supposed to extract the kernel and initrd from the image and pass it to a suitable bootloader. No user account is created and root can login without specifying a password. @@ -56,7 +56,7 @@ By default, it is written to B. =item B<-p> I Request additional packages to be installed into the virtual machine image. -This option can be specified multiple times and packages can be separated with comma. +This option can be specified multiple times and packages can be separated by a comma. Package recommendations are not honoured. =item B<-r> I diff --git a/debvm-run b/debvm-run index 729ba6d..cb782db 100755 --- a/debvm-run +++ b/debvm-run @@ -13,7 +13,7 @@ B [B<-g>] [B<-i> I] [B<-s> I] [B<--> I] =head1 DESCRIPTION -B is essentially a thing wrapper around B for running a virtual machine image created by B or something compatible. +B is essentially a thin wrapper around B for running a virtual machine image created by B or something compatible. The virtual machine image is expected to be a raw ext4 image with file system label B. The architecture of the machine is detected from the contained B. It must contain a symbolic link pointing to a kernel image at B or B depending on the architecture and a symbolic link pointing to an initrd image at B. @@ -42,14 +42,16 @@ If given, B is configured to pass connections to I<127.0.0.1:sshport> to p All options beyond a double dash are passed to B. This can be used to configure additional hardware components. -Another use of this method is passing B<-snapshot> to avoid modifying the virtual machine image. +One possible use of this method is passing B<-snapshot> to avoid modifying the virtual machine image. =back =head1 LIMITATIONS -Due to the way kernel and bootloader are being extracted before running qemu, one cannot upgrade a kernel and then just reboot. +Due to the way kernel and bootloader are being extracted before running B, one cannot upgrade a kernel and then just reboot. +Attempting to do so, will still use the old kernel. Instead, B must be terminated and B should be launched again to pick up a new kernel. +In order to avoid accidental reboots, one may pass B<-no-reboot> to B. =head1 SEE ALSO -- cgit v1.2.3 From 0c50e3b74ec8173d6b0b5f26250a8feee0ceda7b Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 23 Dec 2022 22:58:11 +0100 Subject: another documentation improvement I missed earlier Reported-by: Johannes Schauer Marin Rodrigues --- debvm-run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debvm-run b/debvm-run index cb782db..c227aa3 100755 --- a/debvm-run +++ b/debvm-run @@ -50,7 +50,7 @@ One possible use of this method is passing B<-snapshot> to avoid modifying the v Due to the way kernel and bootloader are being extracted before running B, one cannot upgrade a kernel and then just reboot. Attempting to do so, will still use the old kernel. -Instead, B must be terminated and B should be launched again to pick up a new kernel. +Instead, B must be terminated and B should be launched again to pick up the new kernel. In order to avoid accidental reboots, one may pass B<-no-reboot> to B. =head1 SEE ALSO -- cgit v1.2.3 From af4f1eb0cd386e7d6aa06a097998f4bbcbf9bb43 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 23 Dec 2022 20:55:37 +0100 Subject: Move tests to tests/create-and-run.sh (Closes: #4) --- .gitlab-ci.yml | 31 ++++--------------------------- tests/create-and-run.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 27 deletions(-) create mode 100755 tests/create-and-run.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8af5b41..5d5f375 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,27 +14,7 @@ codespell: - apt-get --no-install-recommends --yes install codespell - codespell debvm-* -.test_script: - script: - - timeout 240s ./debvm-run -s 2222 & - - | - timeout=5 - sshopt="-o StrictHostKeyChecking=no $(if test "$RELEASE" = jessie; then echo -o PubkeyAcceptedKeyTypes=+ssh-rsa; fi)" - ts=$(sleepenh 0 || [ $? -eq 1 ]) - for i in $(seq 30); do - rv=0 - ssh $sshopt -o ConnectTimeout="$timeout" -i ssh_id -p 2222 root@localhost echo success || rv=$? - test $rv -eq 0 && break - ts=$(sleepenh "$ts" "$timeout" || [ $? -eq 1 ]); - if test $i -eq 30; then - echo "timeout reached" >&2 - exit 1 - fi - done - - ssh $sshopt -i ssh_id -p 2222 root@localhost poweroff - release_test: - extends: .test_script parallel: matrix: - RELEASE: @@ -44,15 +24,13 @@ release_test: - buster - stretch - jessie - before_script: + script: - apt-get update - apt-get dist-upgrade --yes - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client sleepenh qemu-kvm - - ssh-keygen -f ssh_id -N '' - - ./debvm-create -k ssh_id.pub -r "$RELEASE" + - PATH=.:$PATH ./tests/create-and-run.sh -r "$RELEASE" arch_test: - extends: .test_script parallel: matrix: - ARCHITECTURE: @@ -63,7 +41,7 @@ arch_test: - mipsel - ppc64el - s390x - before_script: + script: - | if [ ! -e /proc/sys/fs/binfmt_misc/status ]; then mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc @@ -71,5 +49,4 @@ arch_test: - apt-get update - apt-get dist-upgrade --yes - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client sleepenh qemu-system binfmt-support arch-test qemu-user-static - - ssh-keygen -f ssh_id -N '' - - ./debvm-create -k ssh_id.pub -a "$ARCHITECTURE" + - PATH=.:$PATH ./tests/create-and-run.sh -a "$ARCHITECTURE" diff --git a/tests/create-and-run.sh b/tests/create-and-run.sh new file mode 100755 index 0000000..dfd4022 --- /dev/null +++ b/tests/create-and-run.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# shellcheck disable=SC2086 + +set -ex + +cleanup() { + rm -f ssh_id ssh_id.pub test.ext2 +} + +trap cleanup EXIT INT TERM QUIT + +ssh-keygen -f ssh_id -N '' +debvm-create -k ssh_id.pub -o test.ext2 "$@" + +timeout 240s debvm-run -s 2222 -i test.ext2 & +timeout=5 +sshopt="-o StrictHostKeyChecking=no $(if test "$2" = jessie; then echo -o PubkeyAcceptedKeyTypes=+ssh-rsa; fi)" +ts=$(sleepenh 0 || [ $? -eq 1 ]) +for i in $(seq 30); do + rv=0 + ssh $sshopt -o ConnectTimeout="$timeout" -i ssh_id -p 2222 root@localhost echo success || rv=$? + test $rv -eq 0 && break + ts=$(sleepenh "$ts" "$timeout" || [ $? -eq 1 ]); + if test "$i" -eq 30; then + echo "timeout reached" >&2 + exit 1 + fi +done +ssh $sshopt -i ssh_id -p 2222 root@localhost poweroff -- cgit v1.2.3 From c9a0ca87fc9b3bdb3350663be663835fcbf15190 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 23 Dec 2022 23:09:13 +0100 Subject: Use ext4 for test image extension --- tests/create-and-run.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/create-and-run.sh b/tests/create-and-run.sh index dfd4022..4b5d986 100755 --- a/tests/create-and-run.sh +++ b/tests/create-and-run.sh @@ -5,15 +5,15 @@ set -ex cleanup() { - rm -f ssh_id ssh_id.pub test.ext2 + rm -f ssh_id ssh_id.pub test.ext4 } trap cleanup EXIT INT TERM QUIT ssh-keygen -f ssh_id -N '' -debvm-create -k ssh_id.pub -o test.ext2 "$@" +debvm-create -k ssh_id.pub -o test.ext4 "$@" -timeout 240s debvm-run -s 2222 -i test.ext2 & +timeout 240s debvm-run -s 2222 -i test.ext4 & timeout=5 sshopt="-o StrictHostKeyChecking=no $(if test "$2" = jessie; then echo -o PubkeyAcceptedKeyTypes=+ssh-rsa; fi)" ts=$(sleepenh 0 || [ $? -eq 1 ]) -- cgit v1.2.3 From 6f6f3d632c199fd56e5063d6e5ecab13ea69ac55 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 23 Dec 2022 23:14:34 +0100 Subject: Simplify .gitlab-ci.yml --- .gitlab-ci.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5d5f375..3d91676 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,10 +42,7 @@ arch_test: - ppc64el - s390x script: - - | - if [ ! -e /proc/sys/fs/binfmt_misc/status ]; then - mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc - fi + - test -e /proc/sys/fs/binfmt_misc/status || mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc - apt-get update - apt-get dist-upgrade --yes - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client sleepenh qemu-system binfmt-support arch-test qemu-user-static -- cgit v1.2.3 From 99374d17fc20abc1659d46280971376f795babaf Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Fri, 23 Dec 2022 23:40:06 +0100 Subject: Fix image name for fsck --- debvm-create | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debvm-create b/debvm-create index a8f164d..7cc5e31 100755 --- a/debvm-create +++ b/debvm-create @@ -225,4 +225,4 @@ 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 rootfs.ext2 +/sbin/fsck.ext4 -fDp "$IMAGE" -- cgit v1.2.3 From 98fd7c69af3dd9b2dc56399197dc1e441939012e Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 25 Dec 2022 17:35:22 +0100 Subject: debvm-create: do not truncate images beyond their minimum size --- debvm-create | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/debvm-create b/debvm-create index da1899c..d3631fc 100755 --- a/debvm-create +++ b/debvm-create @@ -220,8 +220,11 @@ set -ex mmdebstrap "$@" -truncate -s "$SIZE" "$IMAGE" -/sbin/resize2fs "$IMAGE" +IMAGESIZE=$(stat -c %s "$IMAGE") +if test "$IMAGESIZE" -lt "$SIZE"; then + truncate -s "$SIZE" "$IMAGE" + /sbin/resize2fs "$IMAGE" +fi /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 rootfs.ext2 -- cgit v1.2.3 From b44e90f2139b97ac92bd69123679d04d16c9bd15 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 27 Dec 2022 13:01:09 +0100 Subject: debvm-run: reenable smp for real An empty MAX_SMP was supposed to mean "no limit", but it actually caused the -smp flag to be skipped entirely. Fixes: f3caaf885cf4 ("debvm-run: reenable smp for ppc64el") --- debvm-run | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debvm-run b/debvm-run index edb01ad..972eac6 100755 --- a/debvm-run +++ b/debvm-run @@ -140,9 +140,9 @@ else ;; esac fi -if test "$MAX_SMP" -gt 1; then +if test -z "$MAX_SMP" || test "$MAX_SMP" -gt 1; then NPROC=$(nproc) - test "$NPROC" -gt "$MAX_SMP" && NPROC=$MAX_SMP + test -n "$MAX_SMP" && test "$NPROC" -gt "$MAX_SMP" && NPROC=$MAX_SMP set -- -smp "$NPROC" "$@" fi -- cgit v1.2.3 From c42caac69b5d32c6330716a829d33086b04f2b76 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 27 Dec 2022 13:05:00 +0100 Subject: support long options This change extends option parsing of the debvm tools: * Uses posix getopts. No additional dependencies. * Long option are supported. The option value may be a separate argument or separated with =. * Option value may follow short option immediately, e.g. -as390x * Multiple short options may be combined, e.g. -gs 2222 Technical limitation: * Short options are parsed inside a double dash, e.g. -g-image=rootfs.ext4 --- debvm-create | 111 +++++++++++++++++++++++++++++++++++------------------------ debvm-run | 66 +++++++++++++++++++++++++---------- 2 files changed, 113 insertions(+), 64 deletions(-) diff --git a/debvm-create b/debvm-create index d3631fc..5ac62e7 100755 --- a/debvm-create +++ b/debvm-create @@ -15,67 +15,88 @@ SSHKEY= SUITE=unstable VMNAME=testvm +nth_arg() { + shift "$1" + printf "%s" "$1" +} + die() { echo "$*" 1>&2 exit 1 } - usage() { die "usage: $0 [-a architecture] [-h hostname] [-k sshkey] [-m mirror] [-o output] [-p packages] [-r release] [-s size_in_GB] [-- mmdebstrap options]" } +usage_error() { + echo "error: $*" 1>&2 + usage +} +opt_architecture() { + ARCHITECTURE=$1 +} +opt_hostname() { + VMNAME=$1 +} +opt_mirror() { + MIRROR=$1 +} +opt_sshkey() { + SSHKEY=$1 +} +opt_output() { + IMAGE=$1 +} +opt_package() { + INCLUDE_PACKAGES="$INCLUDE_PACKAGES,$1" +} +opt_release() { + SUITE=$1 +} +opt_size() { + SIZE=$(($1*1024*1024*1024)) +} -while test "$#" -gt 0; do - case "$1" in - -a) - test "$#" -eq 1 && usage - ARCHITECTURE=$2 - shift 2 - ;; - -h) - test "$#" -eq 1 && usage - VMNAME=$2 - shift 2 - ;; - -k) - test "$#" -eq 1 && usage - SSHKEY=$2 - shift 2 - ;; - -m) - test "$#" -eq 1 && usage - MIRROR=$2 - shift 2 - ;; - -o) - test "$#" -eq 1 && usage - IMAGE=$2 - shift 2 - ;; - -p) - test "$#" -eq 1 && usage - INCLUDE_PACKAGES="$INCLUDE_PACKAGES,$2" - shift 2 - ;; - -r) - test "$#" -eq 1 && usage - SUITE=$2 - shift 2 +while getopts :a:h:k:m:o:p:r:s:-: OPTCHAR; do + case "$OPTCHAR" in + a) opt_architecture "$OPTARG" ;; + h) opt_hostname "$OPTARG" ;; + k) opt_sshkey "$OPTARG" ;; + m) opt_mirror "$OPTARG" ;; + o) opt_output "$OPTARG" ;; + p) opt_package "$OPTARG" ;; + r) opt_release "$OPTARG" ;; + s) opt_size "$OPTARG" ;; + -) + case "$OPTARG" in + help) + usage + ;; + architecture|hostname|mirror|output|package|release|size|sshkey) + test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG" + "opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")" + OPTIND=$((OPTIND+1)) + ;; + architecture=*|hostname=*|mirror=*|output=*|package=*|release=*|size=*|sshkey=*) + "opt_${OPTARG%%=*}" "${OPTARG#*=}" + ;; + *) + usage_error "unrecognized option --$OPTARG" + ;; + esac ;; - -s) - test "$#" -eq 1 && usage - SIZE=$(($2*1024*1024*1024)) - shift 2 + :) + usage_error "missing argument for -$OPTARG" ;; - --) - shift - break + '?') + usage_error "unrecognized option -$OPTARG" ;; *) - usage + die "internal error while parsing command options, please report a bug" ;; esac done +shift "$((OPTIND - 1))" if test -n "$SSHKEY" && ! test -f "$SSHKEY"; then die "error: ssh keyfile '$SSHKEY' not found" diff --git a/debvm-run b/debvm-run index 972eac6..c800215 100755 --- a/debvm-run +++ b/debvm-run @@ -8,40 +8,68 @@ IMAGE=rootfs.ext2 SSHPORT= GRAPHICAL= +nth_arg() { + shift "$1" + printf "%s" "$1" +} + die() { echo "$*" 1>&2 exit 1 } - usage() { die "usage: $0 [-g] [-i image] [-s sshport] [-- qemu options]" } +usage_error() { + echo "error: $*" 1>&2 + usage +} -while test "$#" -gt 0; do - case "$1" in - -g) - GRAPHICAL=1 - shift - ;; - -i) - test "$#" -eq 1 && usage - IMAGE=$2 - shift 2 +opt_graphical() { + GRAPHICAL=1 +} +opt_image() { + IMAGE=$1 +} +opt_sshport() { + SSHPORT=$1 +} + +while getopts :gi:s:-: OPTCHAR; do + case "$OPTCHAR" in + g) opt_graphical ;; + i) opt_image "$OPTARG" ;; + s) opt_sshport "$OPTARG" ;; + -) + case "$OPTARG" in + help) + usage + ;; + graphical|image|sshport) + test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG" + "opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")" + OPTIND=$((OPTIND+1)) + ;; + image=*|sshport=*) + "opt_${OPTARG%%=*}" "${OPTARG#*=}" + ;; + *) + usage_error "unrecognized option --$OPTARG" + ;; + esac ;; - -s) - test "$#" -eq 1 && usage - SSHPORT=$2 - shift 2 + :) + usage_error "missing argument for -$OPTARG" ;; - --) - shift - break + '?') + usage_erro "unrecognized option -$OPTARG" ;; *) - usage + die "internal error while parsing command options, please report a bug" ;; esac done +shift "$((OPTIND - 1))" test -f "$IMAGE" || die "image '$IMAGE' not found" test -s "$IMAGE" || die "image '$IMAGE' is empty" -- cgit v1.2.3 From dcf46b1c7602bb2ddd13e9bcf1fb66a8690f4864 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Tue, 27 Dec 2022 16:20:54 +0100 Subject: test script: Use positional arguments Reported-by: Helmut Grohne --- .gitlab-ci.yml | 4 ++-- tests/create-and-run.sh | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3d91676..6427330 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,7 +28,7 @@ release_test: - apt-get update - apt-get dist-upgrade --yes - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client sleepenh qemu-kvm - - PATH=.:$PATH ./tests/create-and-run.sh -r "$RELEASE" + - PATH=.:$PATH ./tests/create-and-run.sh $(dpkg --print-architecture) "$RELEASE" arch_test: parallel: @@ -46,4 +46,4 @@ arch_test: - apt-get update - apt-get dist-upgrade --yes - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client sleepenh qemu-system binfmt-support arch-test qemu-user-static - - PATH=.:$PATH ./tests/create-and-run.sh -a "$ARCHITECTURE" + - PATH=.:$PATH ./tests/create-and-run.sh "$ARCHITECTURE" sid diff --git a/tests/create-and-run.sh b/tests/create-and-run.sh index 4b5d986..0e2a3ca 100755 --- a/tests/create-and-run.sh +++ b/tests/create-and-run.sh @@ -2,6 +2,11 @@ # shellcheck disable=SC2086 +if test "$#" -ne 2; then + echo "$(basename $0) takes two positional arguments. architecture and release" 1>&2 + exit 1 +fi + set -ex cleanup() { @@ -11,7 +16,7 @@ cleanup() { trap cleanup EXIT INT TERM QUIT ssh-keygen -f ssh_id -N '' -debvm-create -k ssh_id.pub -o test.ext4 "$@" +debvm-create -k ssh_id.pub -o test.ext4 -a "$1" -r "$2" timeout 240s debvm-run -s 2222 -i test.ext4 & timeout=5 -- cgit v1.2.3 From d43e76f6f4c3f2e6ce196c5544b7ff5653c024c8 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 28 Dec 2022 08:16:25 +0100 Subject: debvm-create: allow easily overriding the kernel image When adding your own kernel image via -p, it will now skip the automatically detected one. --- debvm-create | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/debvm-create b/debvm-create index a903350..c4159e1 100755 --- a/debvm-create +++ b/debvm-create @@ -111,8 +111,6 @@ case "$SUITE" in ;; esac - - KERNEL_SUFFIX=-$ARCHITECTURE case "$ARCHITECTURE" in amd64|arm64) @@ -138,7 +136,13 @@ case "$ARCHITECTURE" in ;; esac -INCLUDE_PACKAGES="$INCLUDE_PACKAGES,linux-image$KERNEL_SUFFIX" +case ",$INCLUDE_PACKAGES," in + *,linux-image-*) + ;; + *) + INCLUDE_PACKAGES="$INCLUDE_PACKAGES,linux-image$KERNEL_SUFFIX" + ;; +esac if test -n "$SSHKEY"; then INCLUDE_PACKAGES="$INCLUDE_PACKAGES,openssh-server" -- cgit v1.2.3 From 85c2b4d28d66bad39ef8989b313dab3d1356429f Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 28 Dec 2022 10:04:49 +0100 Subject: add a mmdebstrap example hook for mounting 9p file systems --- 9pmounthook/customize.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 9pmounthook/customize.sh diff --git a/9pmounthook/customize.sh b/9pmounthook/customize.sh new file mode 100755 index 0000000..67c4240 --- /dev/null +++ b/9pmounthook/customize.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# Copyright 2022 Helmut Grohne +# SPDX-License-Identifier: MIT +# +# This is a mmdebstrap customize hook that adds a systemd-generator that causes +# 9p filesystems to be automatically mounted to /media/$SOMETAG during boot. +# You can enable it by passing the containing directory to --hook-dir. +# In order to add a 9p filesystem to your VM, pass +# -virtfs local,security_model=none,mount_tag=$SOMETAG,path=$SOMEDIR +# Note that the linux-image-cloud-* does not include a 9p driver. + +set -eu +GENERATOR_PATH="$1/etc/systemd/system-generators/9p-generator" +mkdir -p "${GENERATOR_PATH%/*}" +cat >"$GENERATOR_PATH" << 'ENDOFGENERATOR' +#!/bin/sh + +UNITDIR=$1 + +modprobe 9pnet_virtio || exit 0 + +for tagfile in /sys/bus/virtio/devices/*/mount_tag; do + tag=$(cat "$tagfile") || continue + test -z "$tag" && continue + mountpoint="/media/$tag" + mkdir -p "$mountpoint" + unitname="$(systemd-escape -p "$mountpoint").mount" + cat > "$UNITDIR/$unitname" < Date: Wed, 28 Dec 2022 10:06:49 +0100 Subject: debvm-create: rename -s option to -z The idea is to eventually add a mechanism for skipping steps similar to how mmdebstrap allows skipping them. --- debvm-create | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debvm-create b/debvm-create index 2362beb..cddab8f 100755 --- a/debvm-create +++ b/debvm-create @@ -25,7 +25,7 @@ die() { exit 1 } usage() { - die "usage: $0 [-a architecture] [-h hostname] [-k sshkey] [-m mirror] [-o output] [-p packages] [-r release] [-s size_in_GB] [-- mmdebstrap options]" + die "usage: $0 [-a architecture] [-h hostname] [-k sshkey] [-m mirror] [-o output] [-p packages] [-r release] [-z size_in_GB] [-- mmdebstrap options]" } usage_error() { echo "error: $*" 1>&2 @@ -57,7 +57,7 @@ opt_size() { SIZE=$(($1*1024*1024*1024)) } -while getopts :a:h:k:m:o:p:r:s:-: OPTCHAR; do +while getopts :a:h:k:m:o:p:r:z:-: OPTCHAR; do case "$OPTCHAR" in a) opt_architecture "$OPTARG" ;; h) opt_hostname "$OPTARG" ;; @@ -66,7 +66,7 @@ while getopts :a:h:k:m:o:p:r:s:-: OPTCHAR; do o) opt_output "$OPTARG" ;; p) opt_package "$OPTARG" ;; r) opt_release "$OPTARG" ;; - s) opt_size "$OPTARG" ;; + z) opt_size "$OPTARG" ;; -) case "$OPTARG" in help) -- cgit v1.2.3 From 293a1fa978c0dff81bdf6f37f89eef22066783c6 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 28 Dec 2022 10:19:07 +0100 Subject: update pod2man documentation * Rename debvm-create -s to -z. * Add long options. * Improve documentation of debvm-create -p and -z. --- debvm-create | 24 +++++++++++++----------- debvm-run | 6 +++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/debvm-create b/debvm-create index 37fa514..b39330b 100755 --- a/debvm-create +++ b/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> I] [B<-m> I] [B<-o> I] [B<-p> I] [B<-r> I] [B<-s> I] [B<--> I] +B [B<-a> I] [B<-h> I] [B<-k> I] [B<-m> I] [B<-o> I] [B<-p> I] [B<-r> I] [B<-z> I] [B<--> I] =head1 DESCRIPTION @@ -26,48 +26,50 @@ No user account is created and root can login without specifying a password. =over 8 -=item B<-a> I +=item B<-a> I, B<--architecture>=I Specify a Debian architecture name. By default, the native architecture is being used. A suitable kernel image is automatically selected and installed into the image. -=item B<-h> I +=item B<-h> I, B<--hostname>=I Set the hostname of the virtual machine. By default, the hostname is B. -=item B<-k> I +=item B<-k> I, B<--sshkey>=I Install the given ssh public key file into the virtual machine image for the root user. This option also causes the ssh server to be installed. By default, no key or server is installed. -=item B<-m> I +=item B<-m> I, B<--mirror>=I Specify the Debian mirror to be used for downloading packages and to be configured inside the virtual machine image. By default, B is being used. -=item B<-o> I +=item B<-o> I, B<--output>=I Specify the file name of the resulting virtual machine image. By default, it is written to B. -=item B<-p> I +=item B<-p> I, B<--package>=I Request additional packages to be installed into the virtual machine image. This option can be specified multiple times and packages can be separated by a comma. Package recommendations are not honoured. +If a linux-image is passed here, it will replace the one selected by default. -=item B<-r> I +=item B<-r> I, B<--release>=I Use the given Debian release. By default, B is being used. -=item B<-s> I +=item B<-z> I, B<--size>=I -Specify the image size in giga bytes. -The default image size is 1 GB. +Specify the minimum image size in giga bytes. +The resulting image will be grown as a sparse file to this size if necessary. +The default is 1 GB. =item B<--> I diff --git a/debvm-run b/debvm-run index 58bf2f7..d6a5422 100755 --- a/debvm-run +++ b/debvm-run @@ -24,17 +24,17 @@ A net interface configured for user mode is added automatically. =over 8 -=item B<-g> +=item B<-g>, B<--graphical> By default, the option B<-nographic> is passed to B and one interacts with the serial console of the machine. This configuration is skipped in the presence of this option. -=item B<-i> I +=item B<-i> I, B<--image>=I This option specifies the location of the virtual machine image file. By default B in the working directory is used. -=item B<-s> I +=item B<-s> I, B<--sshport>=I If given, B is configured to pass connections to I<127.0.0.1:sshport> to port 22 of the virtual machine. -- cgit v1.2.3 From 365fd80e150e940e045be185bd58aac16363c4a8 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 28 Dec 2022 17:03:36 +0100 Subject: debvm-create: do clean downloaded .debs What should remain is downloaded package lists. --- debvm-create | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debvm-create b/debvm-create index cddab8f..da660cb 100755 --- a/debvm-create +++ b/debvm-create @@ -221,7 +221,7 @@ if test -n "$SSHKEY"; then "$@" fi -set -- --skip=cleanup/apt "$@" +set -- --skip=cleanup/apt/lists "$@" # We need /var/lib/dpkg/available for dpkg --set-selections to work. set -- '--customize-hook=chroot "$1" apt-cache dumpavail | chroot "$1" dpkg --update-avail' "$@" -- cgit v1.2.3 From c5e12d0fa598aaf3112b43e050d18e93d29903ee Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 28 Dec 2022 20:46:31 +0100 Subject: tests: do not attempt to update a known hosts file This makes testing work in situations where $HOME isn't writeable. --- tests/create-and-run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/create-and-run.sh b/tests/create-and-run.sh index 0e2a3ca..0425e63 100755 --- a/tests/create-and-run.sh +++ b/tests/create-and-run.sh @@ -20,7 +20,7 @@ debvm-create -k ssh_id.pub -o test.ext4 -a "$1" -r "$2" timeout 240s debvm-run -s 2222 -i test.ext4 & timeout=5 -sshopt="-o StrictHostKeyChecking=no $(if test "$2" = jessie; then echo -o PubkeyAcceptedKeyTypes=+ssh-rsa; fi)" +sshopt="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $(if test "$2" = jessie; then echo -o PubkeyAcceptedKeyTypes=+ssh-rsa; fi)" ts=$(sleepenh 0 || [ $? -eq 1 ]) for i in $(seq 30); do rv=0 -- cgit v1.2.3 From c00b63fc4c642bec5be44577771170dc8b2ac5e0 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 28 Dec 2022 21:33:03 +0100 Subject: test: wait for qemu to terminate --- tests/create-and-run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/create-and-run.sh b/tests/create-and-run.sh index 0425e63..aafd41d 100755 --- a/tests/create-and-run.sh +++ b/tests/create-and-run.sh @@ -33,3 +33,4 @@ for i in $(seq 30); do fi done ssh $sshopt -i ssh_id -p 2222 root@localhost poweroff +wait -- cgit v1.2.3