Setting Up 32-Bit Runtime Support In 64-Bit Debian/Ubuntu Chroots
To enable execution of 32-bit binaries on a 64-bit Debian or Ubuntu system, we need to set up a 32-bit compatibility chroot environment. This involves installing required 32-bit libraries, mounting filesystems inside a chroot, installing additional 32-bit packages, and testing to validate 32-bit runtime support.
Prerequisites – 64-bit OS, Understanding of chroots
As a baseline requirement, we need a 64-bit installation of a Debian or Ubuntu Linux distribution. We’ll also be utilizing chroots extensively, so a conceptual understanding of chroots is necessary.
Specifically, a chroot jail allows us to create an isolated filesystem independent from the main OS. We can then install libraries and packages inside this jail without affecting the host system. This chroot approach is how we will set up the 32-bit environment.
Installing Required 32-bit Libraries
The first step is to install baseline 32-bit architecture support libraries using the apt command. This mainly involves the ia32 shared libraries package on Debian/Ubuntu systems.
apt command to install ia32 libraries
sudo apt install libc6:i386 libncurses5:i386 libstdc++6:i386
This will install the 32-bit versions of essential libc, ncurses, and gcc C++ support libraries.
explaining needed packages like libc6-i386
Specifically, the libc6:i386 package contains the GNU C standard library that interfaces with kernel syscalls during runtime. This provides the core userspace interaction support for 32-bit binaries on our 64-bit system.
The libncurses5:i386 package contains the 32-bit ncurses terminal handling library. This is required for any 32-bit CLI programs to function properly on our system.
Lastly, the libstdc++6:i386 package contains the GNU C++ standard library to provide full C++ runtime support for 32-bit programs compiled with g++.
Setting up the Chroot Environment
Now that we have the basic 32-bit libraries installed, we need to setup a chroot jail environment to isolate the 32-bit support. This involves mounting required filesystem resources inside the chroot.
mounting required systems with chroot
At a minimum, we’ll need to mount the /proc and /sys pseudo-filesystems along with a 32-bit /lib library path. Optionally, we can also mount other filesystems like /dev or /tmp.
sudo mount -t proc proc /chroot/proc sudo mount -t sysfs sysfs /chroot/sys sudo mount -o bind /path/to/ia32/libs /chroot/lib
example commands for mounting a chroot
Here is a full sequence of commands to setup an example 32-bit chroot environment:
sudo mkdir /chroot sudo mount -t proc proc /chroot/proc sudo mount -o bind /dev /chroot/dev sudo mount -t sysfs sysfs /chroot/sys sudo mkdir /chroot/lib sudo mount -o bind /usr/lib/i386-linux-gnu /chroot/lib sudo chroot /chroot
This will:
- Create a /chroot directory
- Mount required /proc, /dev, and /sys filesystems inside chroot
- Create /lib directory inside chroot
- Bind mount 32-bit system library path into chroot
- Finally chroot into this 32-bit environment
Installing Additional 32-bit Packages
If the chroot environment requires additional 32-bit libraries or packages, we can use apt’s multiarch support to install them.
specifying foreign architecture for other packages
The key is to specify the “:i386” architecture suffix with the apt install command. This will fetch and install the 32-bit version of the specified package inside the chroot.
example commands with “:i386” suffix
For instance, to install a 32-bit version of perl and its core modules inside the chroot environment:
apt install perl:i386 libperl5.26:i386
Other common 32-bit packages that may be needed are:
apt install libldap2-dev:i386 libssl-dev:i386 zlib1g-dev:i386
Testing 32-bit Runtime Support
As a final validation step, we should test execution of 32-bit binaries inside the chroot.
verifying with example 32-bit binaries
Copy some 32-bit ELF binaries into the chroot, set the execution permission bits, and run them:
cp /path/to/32bit/prog /chroot/test/ chmod +x /chroot/test/32bit-prog chroot /chroot /test/32bit-prog
Verify the program executes and functions properly within the 32-bit chroot.
checking expected output
For example, we can compile a simple 32-bit “hello world” C program on another system. Copy the binary into the chroot, execute it, and validate we see the expected printed output.
./32bit-helloworld Hello World!
If a binary crashes or fails with invalid opcode or illegal instruction errors, then additional 32-bit support libraries may need to be installed.
Troubleshooting Issues
There are a few common categories of errors when working with chroots and 32-bit support.
common chroot errors and fixes
Permission errors – Use sudo or become root for all chroot setup commands
Library missing errors – Install additional 32-bit packages per binary requirements
System resource failures – Mount required /proc, /sys, /dev, and /tmp filesystems
strace for debugging problems
For deeper troubleshooting, we can use strace to trace system calls and signals across the host/chroot boundary:
strace -e trace=desc,chdir,ioctl,socketcall 32bit-binary
This can help debug tricky chroot environment and 32-bit compatibility issues.