21.08.24, 16:56 +0200, Steve Keller:

> Can I run a container for a different CPU architecture using
> systemd-nspawn?

No. systemd-nspawn does indeed simply run a container. You can think of
that as a chroot on steroids. This means, everything inside the
container is run using the host kernel. Or to put it the other way
round: what the host kernel can't execute won't run.

If you want to run stuff for an architecture the host kernel cannot cope
with, you need a virtual machine (manager like QEMU). You can run one
using something like
qemu-system-aarch64 [...]
but it's probably much easier to use some helper like libvirt.

>  I can easily install on my amd64 host a Debian
> container of the same architecture and run that:
> 
>   # debootstrap stable deb12-amd64
>   # systemd-nspawn -D deb12-amd64
> 
> and get a shell running in that container.  I can also install a
> Debian system of a different architecture and run binaries from it
> like this (using qemu-user-binfmt):
> 
>   # debootstrap --arch=arm64 --foreign stable deb-arm64
>   # QEMU_LD_PREFIX=/usr/aarch64-linux-gnu deb-arm64/bin/date
>   Wed Aug 21 16:43:40 CEST 2024
> 
> But the following doesn't work
> 
>   # QEMU_LD_PREFIX=/usr/aarch64-linux-gnu systemd-nspawn -D deb-arm64
>   Spawning container deb-arm64 on /usr/local/deb-arm64.
>   Press ^] three times within 1s to kill container.
>   execv(/bin/bash, /bin/bash, /bin/sh) failed: No such file or directory
>   Container deb-arm64 failed with error code 1.
> 
> I'd like to know if it's also possible to run the whole container in
> arm64 architecture using systemd-nspawn like above for amd64.
As said above: no.

-- 
Regards
  mks

Reply via email to