Origin: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1021802
Forwarded: not-needed
From: Antonio Terceiro <terceiro@debian.org>
Date: Sat Oct 15 02:06:02 UTC 2022
Subject: fix(debootstrap plugin): set architecture for later stages
 debootstrap takes an architecture argument, but does not propagate that
 to later stages of the image build. This causes, for example, the GRUB
 plugin to fail to install the correct packages when creating an images
 for a foreign archiecture.
 .
 The call to dpkg --print-architecture to discover the native
 architecture is already done when state is first populated, so there is
 no need to do it again in the grub plugin.
 .
 This patch has been accepted in the upstream Git repo (commits 28813c,
 395bb4). It should be dropped in the next upstream release.

Index: vmdb2/arm64-uefi.vmdb
===================================================================
--- vmdb2.orig/arm64-uefi.vmdb
+++ vmdb2/arm64-uefi.vmdb
@@ -3,7 +3,7 @@
 
 steps:
   - mkimg: "{{ output }}"
-    size: 4G
+    size: 1G
 
   - mklabel: gpt
     device: "{{ output }}"
@@ -11,12 +11,12 @@ steps:
   - mkpart: primary
     device: "{{ output }}"
     start: 0%
-    end: 1G
+    end: 20M
     tag: efi
 
   - mkpart: primary
     device: "{{ output }}"
-    start: 1G
+    start: 20M
     end: 100%
     tag: /
 
@@ -30,26 +30,35 @@ steps:
 
   - mount: /
 
-  # Using the virtual-filesystems plugin here upsets qemu-debootstrap,
-  # which ends up unable to create /dev/fd within the chroot, causing
-  # the qemu-debootstrap phase to fail. Until we get to the bottom
-  # that, don't enable the plugin.
-  #- virtual-filesystems: /
+ - unpack-rootfs: /
 
-  - unpack-rootfs: /
-
-  - qemu-debootstrap: buster
+  - debootstrap: bullseye
+    variant: minbase
     arch: arm64
     mirror: http://deb.debian.org/debian
     target: /
     unless: rootfs_unpacked
 
+  - chroot: /
+    shell: apt-get clean
+
   - apt: install
     packages:
+      - wget
+      - iproute2
       - linux-image-arm64
+      - systemd-sysv
     fs-tag: /
     unless: rootfs_unpacked
 
+  - copy-file: /etc/systemd/network/eth0.network
+    src: eth0.network
+    unless: rootfs_unpacked
+
+  - chroot: /
+    shell: systemctl enable systemd-networkd
+    unless: rootfs_unpacked
+
   - cache-rootfs: /
     unless: rootfs_unpacked
 
@@ -61,3 +70,6 @@ steps:
   - grub: uefi
     tag: /
     efi: efi
+    console: serial
+
+# vim: ft=yaml
Index: vmdb2/vmdb/plugins/debootstrap_plugin.py
===================================================================
--- vmdb2.orig/vmdb/plugins/debootstrap_plugin.py
+++ vmdb2/vmdb/plugins/debootstrap_plugin.py
@@ -51,10 +51,8 @@ class DebootstrapStepRunner(vmdb.StepRun
         install_keyring = values["install_keyring"]
         include = values["include"]
         require_empty = values["require_empty_target"]
-        arch = (
-            values["arch"]
-            or subprocess.check_output(["dpkg", "--print-architecture"]).strip()
-        )
+        arch = values["arch"] or state.arch
+        state.arch = arch
         variant = values["variant"]
         components = values["components"]
 
@@ -113,3 +111,7 @@ class DebootstrapStepRunner(vmdb.StepRun
                 ]
                 + remove_pkgs,
             )
+
+    def run_even_if_skipped(self, values, settings, state):
+        if values["arch"]:
+            state.arch = values["arch"]
