Building obsolete software, with debootstrap and chroot

One of my ongoing projects has been to build pretty much all major versions of GCC, mainly so that I can test the performance of the compilers over time.  For the last 7 or 8 versions, that’s not so hard – they build more or less okay on a current Ubuntu system.  Unfortunately, the further back you go, the more breakage there is.  For example, the C++ runtime in gcc 3.3 and 3.4 appears not to work with the current version of GNU libc.  And I can’t very well downgrade glibc without breaking, well, everything.

Happily, the combination of the chroot and debootstrap tools offers a rather painless alternative.

debootstrap is a tool that lets you install a particular version of Debian (or Ubuntu) to a subdirectory of an existing system.  Almost any version from the past 6 years is supported, and the installation is guaranteed not to interfere with the existing system.

chroot meanwhile works to confine a system to a particular directory – changing the apparent root of the system, and preventing the system from accessing anything not in that directory.

Using debootstrap and chroot you can therefore get a more or less full Linux environment with all the tools and libraries of the older system to test with, without having the slightest possibility of harming the running system.  And unlike with a virtualization solution like VMWare, everything is readily accessible on the main host filesystem, and there’s no meaningful performance penalty.

Here are some basic instruction for how I got gcc 3.4 installed and fully running in a chroot environment for Debian Sarge (i386 version).  Note that root access is needed (the chroot call requires root access).

Set up the chroot environment:

sudo bash
export DIST=sarge
export CHROOT=$DIST-chroot
apt-get install dchroot debootstrap
mkdir $CHROOT
debootstrap –arch=i386 $DIST $CHROOT
mount -t proc proc $CHROOT/proc
mount -t devpts devpts $CHROOT/dev/pts
chroot $CHROOT /bin/bash –login

Inside the chroot jail, set up ssh and set a password for the root user (note – this password is only in the chroot installation, it has nothing to do with your real root password): 

apt-get install locales ssh
dpkg-reconfigure locales
vi /etc/ssh/sshd_config – change port to 2022
/etc/init.d/ssh restart

Now you can log in directly:

ssh root@localhost -p 2022
apt-get install bzip2 make patch gcc libc6-dev

Then just follow the standard gcc install instructions…

Comments are closed.