Can I run a container for a different CPU architecture using
systemd-nspawn?
I can easily install on my amd64 host a DebianAs said above: no.
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.
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.
Can I run a container for a different CPU architecture using
systemd-nspawn? I can easily install on my amd64 host a Debian
container of the same architecture and run that:
Don't know about systemd-nspawn but I do something like this using
unshare, binfmt-support and qemu-user-static.
I don't have to do anything at all other than create the file system
with the emulated architecture and then chroot into it with those
packages installed.
Perhaps systemd-nspawn would similarly work with those packages
installed.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 02:43:29 |
Calls: | 10,387 |
Calls today: | 2 |
Files: | 14,061 |
Messages: | 6,416,755 |