[RFC,2/2] rootfs: use host apt when installing in cross mode

Message ID 20260720105228.395364-2-felix.moessbauer@siemens.com
State New
Headers show
Series [RFC,1/2] rootfs: download packages with host apt | expand

Commit Message

Felix Moessbauer July 20, 2026, 10:52 a.m. UTC
Currently the apt inside the chroot is used to perform the extraction
and installation. This is really slow on non native architectures (esp.
on larger packages), as the whole operation is emulated.

We improve this by using the host apt for the dependency resolution,
unpack and configure operation. The dpkg chroots into the rootfs to run
the target maintainer scripts (emulated via qemu in cross builds),
mirroring how mmdebstrap installs. As we already have all packages in
the apt cache (since e09589d28), we don't need to mount the isar apt or
base apt - which would not work as the host apt would lookup the
absolute apt paths on the host (i.e. read /isar-apt from the host
instead of the chroot).

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/classes-recipe/rootfs.bbclass | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Patch

diff --git a/meta/classes-recipe/rootfs.bbclass b/meta/classes-recipe/rootfs.bbclass
index 6af29b40..95210f4c 100644
--- a/meta/classes-recipe/rootfs.bbclass
+++ b/meta/classes-recipe/rootfs.bbclass
@@ -390,9 +390,15 @@  rootfs_install_pkgs_install[network] = "${TASK_USE_SUDO}"
 rootfs_install_pkgs_install() {
     run_privileged_heredoc <<'EOF'
     set -e
+    # Unpack and configure packages using the host apt. Dependency resolution
+    # and the apt frontend run natively (-o Dir points at the rootfs), while
+    # dpkg chroots into the rootfs to run the target maintainer scripts
+    # (emulated via qemu in cross builds), mirroring how mmdebstrap installs.
     ${@insert_isar_mounts(d, d.getVar('ROOTFSDIR'), d.getVar('ROOTFS_MOUNTS')) if d.getVar('ISAR_CHROOT_MODE') == 'unshare' else ''}
-    chroot "${ROOTFSDIR}" \
-        /usr/bin/apt-get ${ROOTFS_APT_ARGS} --no-download ${ROOTFS_PACKAGES}
+    /usr/bin/apt-get -o APT::Architecture=${ROOTFS_ARCH} \
+        -o Dir="${ROOTFSDIR}" \
+        -o DPkg::Chroot-Directory="${ROOTFSDIR}" \
+        ${ROOTFS_APT_ARGS} --no-download ${ROOTFS_PACKAGES}
 EOF
 }