From d1603fc20101de5b32030f314500fc0be65dcf29 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 4 Jan 2023 10:16:16 +0100 Subject: debvm-create: add a --skip option As with mmdebstrap, the --skip option can be used to skip over tasks that are enabled by default. For now, we just add an integration for --- debvm-create | 79 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 25 deletions(-) diff --git a/debvm-create b/debvm-create index 58094cc..f3f9895 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<-z> 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<-s> ] [B<-z> I] [B<--> I] =head1 DESCRIPTION @@ -66,6 +66,19 @@ If a linux-image is passed here, it will replace the one selected by default. Use the given Debian release. By default, B is being used. +=item B<-s> I, B<--skip>=I + +Skip a particular task or feature. +The option may be specified multiple times or list multiple tasks to be skipped by separating them with a comma. +By default, no tasks are skipped. +The following tasks may be skipped. + +=over 4 + +=item B skips installing B as well as automatic network configuration via B. + +=back + =item B<-z> I, B<--size>=I Specify the minimum image size in giga bytes. @@ -93,6 +106,7 @@ IMAGE=rootfs.ext4 INCLUDE_PACKAGES=init MIRROR="http://deb.debian.org/debian" SIZE=$((1024*1024*1024)) +SKIP=, SSHKEY= SUITE=unstable VMNAME=testvm @@ -123,6 +137,9 @@ opt_hostname() { opt_mirror() { MIRROR=$1 } +opt_skip() { + SKIP="$SKIP$1," +} opt_sshkey() { SSHKEY=$1 } @@ -139,7 +156,7 @@ opt_size() { SIZE=$(($1*1024*1024*1024)) } -while getopts :a:h:k:m:o:p:r:z:-: OPTCHAR; do +while getopts :a:h:k:m:o:p:r:s:z:-: OPTCHAR; do case "$OPTCHAR" in a) opt_architecture "$OPTARG" ;; h) opt_hostname "$OPTARG" ;; @@ -148,18 +165,19 @@ while getopts :a:h:k:m:o:p:r:z:-: OPTCHAR; do o) opt_output "$OPTARG" ;; p) opt_package "$OPTARG" ;; r) opt_release "$OPTARG" ;; + s) opt_skip "$OPTARG" ;; z) opt_size "$OPTARG" ;; -) case "$OPTARG" in help) usage ;; - architecture|hostname|mirror|output|package|release|size|sshkey) + architecture|hostname|mirror|output|package|release|size|skip|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=*) + architecture=*|hostname=*|mirror=*|output=*|package=*|release=*|size=*|skip=*|sshkey=*) "opt_${OPTARG%%=*}" "${OPTARG#*=}" ;; *) @@ -184,6 +202,13 @@ if test -n "$SSHKEY" && ! test -f "$SSHKEY"; then die "error: ssh keyfile '$SSHKEY' not found" fi +check_skip() { + case "$SKIP" in + *",$1,"*) return 0 ;; + *) return 1 ;; + esac +} + case "$SUITE" in jessie) DEBVER=8 @@ -251,17 +276,19 @@ if test -n "$SSHKEY"; then INCLUDE_PACKAGES="$INCLUDE_PACKAGES,openssh-server" fi -# add a DNS resolver -if test "$DEBVER" -ge 9; then - INCLUDE_PACKAGES="$INCLUDE_PACKAGES,libnss-resolve" -fi -if test "$DEBVER" -le 11; then - set -- '--customize-hook=chroot "$1" systemctl enable systemd-resolved.service' "$@" -fi -if test "$DEBVER" -le 9; then - set -- '--customize-hook=ln -fs ../run/systemd/resolve/resolv.conf "$1/etc/resolv.conf"' "$@" -elif test "$DEBVER" -le 11; then - set -- '--customize-hook=ln -fs ../run/systemd/resolve/stub-resolv.conf "$1/etc/resolv.conf"' "$@" +if ! check_skip systemdnetwork; then + # add a DNS resolver + if test "$DEBVER" -ge 9; then + INCLUDE_PACKAGES="$INCLUDE_PACKAGES,libnss-resolve" + fi + if test "$DEBVER" -le 11; then + set -- '--customize-hook=chroot "$1" systemctl enable systemd-resolved.service' "$@" + fi + if test "$DEBVER" -le 9; then + set -- '--customize-hook=ln -fs ../run/systemd/resolve/resolv.conf "$1/etc/resolv.conf"' "$@" + elif test "$DEBVER" -le 11; then + set -- '--customize-hook=ln -fs ../run/systemd/resolve/stub-resolv.conf "$1/etc/resolv.conf"' "$@" + fi fi # construct mmdebstrap options as $@: @@ -284,16 +311,18 @@ set -- \ # allow password-less root login set -- '--customize-hook=chroot "$1" passwd --delete root' "$@" -# dhcp on all network interfaces -SYSD_NET_MATCH='Name=en*\n' -test "$DEBVER" -le 8 && SYSD_NET_MATCH="${SYSD_NET_MATCH}Name=eth*\\n" -SYSD_NET_NET='DHCP=yes\n' -# This anchor is included by default since bullseye. Fails DNSSEC validation when missing. -test "$DEBVER" -le 11 && SYSD_NET_NET="${SYSD_NET_NET}DNSSECNegativeTrustAnchors=home.arpa\\n" -set -- \ - '--customize-hook=chroot "$1" systemctl enable systemd-networkd.service' \ - "--customize-hook=printf \"[Match]\\n$SYSD_NET_MATCH\\n[Network]\\n$SYSD_NET_NET"'\n[DHCP]\nUseDomains=yes\n" > "$1/etc/systemd/network/20-wired.network"' \ - "$@" +if ! check_skip systemdnetwork; then + # dhcp on all network interfaces + SYSD_NET_MATCH='Name=en*\n' + test "$DEBVER" -le 8 && SYSD_NET_MATCH="${SYSD_NET_MATCH}Name=eth*\\n" + SYSD_NET_NET='DHCP=yes\n' + # This anchor is included by default since bullseye. Fails DNSSEC validation when missing. + test "$DEBVER" -le 11 && SYSD_NET_NET="${SYSD_NET_NET}DNSSECNegativeTrustAnchors=home.arpa\\n" + set -- \ + '--customize-hook=chroot "$1" systemctl enable systemd-networkd.service' \ + "--customize-hook=printf \"[Match]\\n$SYSD_NET_MATCH\\n[Network]\\n$SYSD_NET_NET"'\n[DHCP]\nUseDomains=yes\n" > "$1/etc/systemd/network/20-wired.network"' \ + "$@" +fi # add ssh key for root if test -n "$SSHKEY"; then -- cgit v1.2.3 From a3fff16fd6cf180f36063d642671cbc3b4c9d2e1 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 7 Jan 2023 21:32:43 +0100 Subject: debvm-create: allow skipping package lists --- debvm-create | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/debvm-create b/debvm-create index f3f9895..1f5e8df 100755 --- a/debvm-create +++ b/debvm-create @@ -75,7 +75,16 @@ The following tasks may be skipped. =over 4 -=item B skips installing B as well as automatic network configuration via B. +=item B + +skips installing B as well as automatic network configuration via B. + +=item B + +reduces the package lists inside the image. +The B database for B is not created. +The package lists used by B are deleted. +This generally produces a smaller image, but you need to run B before installing packages and B does not work. =back @@ -332,10 +341,12 @@ if test -n "$SSHKEY"; then "$@" fi -set -- --skip=cleanup/apt/lists "$@" +if ! check_skip packagelists; then + 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' "$@" + # 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' "$@" +fi if test "$DEBVER" -le 8; then # Use obsolete and expired keys. -- cgit v1.2.3 From fe999e3cdb244bef2bd425918bc874b0018e94aa Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 8 Jan 2023 08:56:24 +0100 Subject: debvm-create: allow skipping the usrmerge hook --- debvm-create | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/debvm-create b/debvm-create index 1f5e8df..5ddbd2f 100755 --- a/debvm-create +++ b/debvm-create @@ -75,10 +75,6 @@ The following tasks may be skipped. =over 4 -=item B - -skips installing B as well as automatic network configuration via B. - =item B reduces the package lists inside the image. @@ -86,6 +82,15 @@ The B database for B is not created. The package lists used by B are deleted. This generally produces a smaller image, but you need to run B before installing packages and B does not work. +=item B + +skips installing B as well as automatic network configuration via B. + +=item B + +By default B adds a hook to enable merged-/usr without the B package given a sufficiently recent Debian release. +Without the hook, dependencies will pull the B package as needed, which may result in a larger installation. + =back =item B<-z> I, B<--size>=I @@ -355,7 +360,7 @@ if test "$DEBVER" -le 8; then set -- --hook-dir=/usr/share/mmdebstrap/hooks/jessie-or-older "$@" fi -if test "$DEBVER" -ge 12; then +if test "$DEBVER" -ge 12 && ! check_skip usrmerge; then # Avoid the usrmerge package set -- --hook-dir=/usr/share/mmdebstrap/hooks/merged-usr "$@" fi -- cgit v1.2.3 From 3e208bb0a0c713e58e5310d282e0382a14f625cd Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 13 Jan 2023 07:50:13 +0100 Subject: debvm-create: add --skip=kernel --- debvm-create | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/debvm-create b/debvm-create index 541519b..d21fd7b 100755 --- a/debvm-create +++ b/debvm-create @@ -59,7 +59,7 @@ By default, it is written to F. 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. +If a linux-image is passed here, it will also C<--skip=kernel>. =item B<-r> I, B<--release>=I @@ -75,6 +75,11 @@ The following tasks may be skipped. =over 4 +=item B + +skips installing a linux kernel image. +This can be useful to install a custom kernel or to install a different kernel variant than is selected by default. + =item B reduces the package lists inside the image. @@ -162,6 +167,9 @@ opt_output() { } opt_package() { INCLUDE_PACKAGES="$INCLUDE_PACKAGES,$1" + case "$1" in linux-image*) + opt_skip kernel + ;; esac } opt_release() { SUITE=$1 @@ -278,13 +286,9 @@ case "$ARCHITECTURE" in ;; esac -case ",$INCLUDE_PACKAGES," in - *,linux-image-*) - ;; - *) - INCLUDE_PACKAGES="$INCLUDE_PACKAGES,linux-image$KERNEL_SUFFIX" - ;; -esac +if ! check_skip kernel; then + INCLUDE_PACKAGES="$INCLUDE_PACKAGES,linux-image$KERNEL_SUFFIX" +fi if test -n "$SSHKEY"; then INCLUDE_PACKAGES="$INCLUDE_PACKAGES,openssh-server" -- cgit v1.2.3