diff options
author | Helmut Grohne <helmut@subdivi.de> | 2023-01-17 14:54:10 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2023-01-17 14:54:10 +0100 |
commit | 013b5b24017f524720a2d34d5d83b0090187c99c (patch) | |
tree | 80d6b0301ce17aa71f91fabf3336f83225595d88 | |
parent | 8961c87b6b1289d50e7e53cbca497f5ee9ed7b3c (diff) | |
download | debvm-013b5b24017f524720a2d34d5d83b0090187c99c.tar.gz |
debvm-create: install only one kernel image
The apt pattern ?or does not short-circuit. It installs any pattern
matching one of the arguments. On amd64, we thus get both the cloud and
the non-cloud variant.
There aren't that many good options to fix this, so the next best way is
using a hook and running apt again, which is suboptimal in terms of
repeated triggers, but likely the best we can do at present.
-rwxr-xr-x | bin/debvm-create | 30 | ||||
-rwxr-xr-x | share/customize-kernel.sh | 56 |
2 files changed, 59 insertions, 27 deletions
diff --git a/bin/debvm-create b/bin/debvm-create index 637d613..c554165 100755 --- a/bin/debvm-create +++ b/bin/debvm-create @@ -72,7 +72,8 @@ cmdline and passes it as C<TERM> to B<agetty>. =item B<kernel> 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. +This can be useful to install a kernel without a package. +If a kernel is installed via B<mmdebstrap> option C<--include>, automtatic kernel installation is automatically skipped. =item B<packagelists> @@ -224,33 +225,8 @@ check_skip() { esac } -KERNEL_ARCH=$ARCHITECTURE -case "$ARCHITECTURE" in - armhf) - KERNEL_ARCH=armmp - ;; - hppa) - KERNEL_ARCH=parisc - ;; - i386) - KERNEL_ARCH=686-pae - ;; - mips64el) - KERNEL_ARCH=5kc-malta - ;; - mipsel) - KERNEL_ARCH=4kc-malta - ;; - ppc64) - KERNEL_ARCH=powerpc64 - ;; - ppc64el) - KERNEL_ARCH=powerpc64le - ;; -esac - if ! check_skip kernel; then - set -- "--include=?not(?virtual)?or(?exact-name(linux-image-cloud-$KERNEL_ARCH),?exact-name(linux-image-$KERNEL_ARCH),?exact-name(linux-image-generic))" "$@" + set -- "--customize-hook=$SHARE_DIR/customize-kernel.sh" "$@" fi # construct mmdebstrap options as $@: diff --git a/share/customize-kernel.sh b/share/customize-kernel.sh new file mode 100755 index 0000000..fa94df7 --- /dev/null +++ b/share/customize-kernel.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# +# Copyright 2022 Helmut Grohne <helmut@subdivi.de> +# SPDX-License-Identifier: MIT +# +# This is a mmdebstrap customize hook that installs a kernel image. The name +# of the kernel image depends on the architecture, derivative and release. + +set -eu + +TARGET="$1" + +if dpkg-query --root="$TARGET" --showformat='${db:Status-Status}\n' --show 'linux-image-*' 2>/dev/null | grep -q '^installed$'; then + exit 0 +fi + +ARCHITECTURE=$(cat "$TARGET/var/lib/dpkg/arch") + +KERNEL_ARCH="$ARCHITECTURE" +case "$ARCHITECTURE" in + armhf) + KERNEL_ARCH=armmp + ;; + hppa) + KERNEL_ARCH=parisc + ;; + i386) + KERNEL_ARCH=686-pae + ;; + mips64el) + KERNEL_ARCH=5kc-malta + ;; + mipsel) + KERNEL_ARCH=4kc-malta + ;; + ppc64) + KERNEL_ARCH=powerpc64 + ;; + ppc64el) + KERNEL_ARCH=powerpc64le + ;; +esac + +export APT_CONFIG="$MMDEBSTRAP_APT_CONFIG" + +if test "${MMDEBSTRAP_MODE:-}" = chrootless; then + set -- \ + -oDPkg::Options::=--force-not-root \ + -oDPkg::Options::=--force-script-chrootless \ + -oDPkg::Options::=--root="$TARGET" \ + -oDPkg::Options::=--log="$TARGET/var/log/dpkg.log" +else + set -- -oDPkg::Chroot-Directory="$TARGET" +fi + +apt-get --yes satisfy "$@" "linux-image-cloud-$KERNEL_ARCH | linux-image-$KERNEL_ARCH | linux-image-generic" |