Overview
Modern Linux deployments run almost exclusively on 64-bit systems, yet engineering teams frequently encounter legacy 32-bit executables, proprietary drivers, or legacy toolchains that mandate backward compatibility. This walkthrough details how to configure multiarch support on an x86_64 Ubuntu installation using dpkg. We will set up the runtime environment, compile a dedicated 32-bit verification payload, and examine the resulting ELF headers and dynamic linker associations using native binary inspection utilities including file, ldd, and readelf.
Inspecting Base Architecture and Registering Foreign Multiarch Support
To query the primary architecture for which the local package manager was built, invoke dpkg --print-architecture.
The returned value amd64 verifies that the kernel and default userspace operate in native 64-bit x86_64 mode.
⚙️ [Core Options]
--print-architecture : Prints the underlying native packaging target architecture of the host.--print-foreign-architectures : Reports non-native (secondary) multiarch targets enabled on the machine.--add-architecture <arch> : Enrolls an additional foreign architecture into the package management database.--remove-architecture <arch> : De-registers a previously added foreign architecture from the system.

Querying secondary architecture registrations is accomplished via dpkg --print-foreign-architectures.
When executed on a pristine installation, this command yields an empty output, signifying that the package database currently restricts installations exclusively to native 64-bit binaries.

To provision support for legacy 32-bit x86 software, declare the secondary target by running sudo dpkg --add-architecture i386.
Executing this utility with administrative privileges instructs Debian packaging subsystems to track and resolve packages compiled for the i386 instruction set alongside native packages.

Re-evaluating foreign architecture status with dpkg --print-foreign-architectures confirms whether the configuration took effect.
The terminal output now displays i386, establishing that multiarch support for 32-bit software is active and ready on the host.

Provisioning 32-Bit Toolchains and Core Shared Libraries
Because the package repository indices lack metadata for the newly registered foreign architecture, synchronize repository channels with sudo apt-get update -qq.

Running 32-bit programs on 64-bit kernels requires 32-bit shared object files, runtime libraries, and multilib compiler toolchains. Install them simultaneously by executing sudo apt-get install -y libc6:i386 libstdc++6:i386 gcc-multilib binutils file.

Building and Validating an i386 Target Executable
Isolate testing artifacts into a separate workspace by preparing and navigating to a sandbox directory via mkdir -p ~/i386_test && cd ~/i386_test.

To definitively prove that an executable executes in 32-bit mode, create a C test source that evaluates sizeof(void*) using the following stream write: printf '#include <stdio.h>\nint main() { printf("Running i386 32-bit binary successfully! Pointer size: %%zu bytes\\n", sizeof(void*)); return 0; }\n' > test_i386.c.

Compile the newly authored code into an i386 target executable using gcc -m32 test_i386.c -o test_i386.
Passing the -m32 flag overrides the compiler’s default 64-bit target, enforcing code generation tailored strictly to the 32-bit x86 Application Binary Interface (ABI).

Directly invoke the resulting binary from your terminal using ./test_i386 to confirm execution within the x86_64 host.
The diagnostic output validates proper environment initialization by reporting a pointer size of exactly 4 bytes (32 bits), contrasting with the standard 8-byte pointer size found in 64-bit binaries.

Verifying ELF Architecture Headers and Dynamic Shared Libraries
Execute file test_i386 to extract container file metadata and target architecture properties.
The command yields ELF 32-bit LSB pie executable, Intel 80386, demonstrating unequivocally that the output file conforms to standard 32-bit Little-Endian x86 ELF specifications.

Investigate the dynamic shared library requirements and loader resolution paths of the binary using ldd test_i386.
The resulting dependency tree illustrates that the binary binds cleanly to the 32-bit dynamic linker (ld-linux.so.2) and 32-bit C runtime (libc.so.6) rather than their 64-bit equivalents.

For a granular verification of the low-level ELF header values, execute readelf -h test_i386 | grep -E 'Class|Machine'.
Parsing these specific header entries reveals that the executable is marked as ELF32 with the target machine explicitly defined as Intel 80386, leaving zero ambiguity regarding its execution mode.

Configuring multiarch on modern 64-bit Ubuntu instances ensures dependable compatibility when maintaining specialized legacy tooling or deploying mixed-architecture systems. By pairing dpkg architecture controls with utilities such as ldd and readelf, systems administrators and developers can rapidly validate runtime dependencies and confirm proper binary behavior across system boundaries.