2

Let's say for example the host system is running Debian amd64. And on that system, another Debian i386 has been installed inside a folder using debootstrap. Then assume a shell script is running inside the chroot.

From inside the chroot, dpkg-architecture / uname -a show only what architecture the host system has (amd64).

How do I detect the [package] architecture of the chroot? (i386)

adrelanos
  • 1,836
  • 7
  • 30
  • 58

1 Answers1

5

dpkg-architecture and dpkg --print-architecture work for me.

/root# chroot /f/32
{3}/# uname -m
x86_64
{3}/# file /bin/ls
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=152184668fe2d58ef2ef49e8c40d044880f8e318, stripped
{3}/# dpkg --print-architecture
i386
{3}/# dpkg-architecture
DEB_BUILD_ARCH=i386
DEB_BUILD_ARCH_BITS=32
DEB_BUILD_ARCH_CPU=i386
DEB_BUILD_ARCH_ENDIAN=little
DEB_BUILD_ARCH_OS=linux
DEB_BUILD_GNU_CPU=i586
DEB_BUILD_GNU_SYSTEM=linux-gnu
DEB_BUILD_GNU_TYPE=i586-linux-gnu
DEB_BUILD_MULTIARCH=i386-linux-gnu
DEB_HOST_ARCH=i386
DEB_HOST_ARCH_BITS=32
DEB_HOST_ARCH_CPU=i386
DEB_HOST_ARCH_ENDIAN=little
DEB_HOST_ARCH_OS=linux
DEB_HOST_GNU_CPU=i586
DEB_HOST_GNU_SYSTEM=linux-gnu
DEB_HOST_GNU_TYPE=i586-linux-gnu
DEB_HOST_MULTIARCH=i386-linux-gnu
DEB_TARGET_ARCH=i386
DEB_TARGET_ARCH_BITS=32
DEB_TARGET_ARCH_CPU=i386
DEB_TARGET_ARCH_ENDIAN=little
DEB_TARGET_ARCH_OS=linux
DEB_TARGET_GNU_CPU=i586
DEB_TARGET_GNU_SYSTEM=linux-gnu
DEB_TARGET_GNU_TYPE=i586-linux-gnu
DEB_TARGET_MULTIARCH=i386-linux-gnu

That being said, you should probably make programs in the chroot think they're running on a 32-bit system. You can do that by running them with the right personality. The setarch utility (part of util-linux) does that, or simply

linux32 chroot /path/to/chroot

If you set up your chroot with schroot, declaring the personality as linux32 in the chroot definition takes care of that.