Installing a 32bit build chroot
Sometimes it’s just easier to have a 32bit system to build 32bit packages on, but we don’t always have that option. And creating a virtual machine may just be too much overhead. After all, you just want some 32bit packages to be built on your 64bit system and not have to worry about multi-arch problems at build time. Here is how I usually solve the problem.
First, fool rpm into thinking this is a 32bit system:
mv /etc/rpm/platform /etc/rpm/platform.orig echo i686-redhat-linux > /etc/rpm/platform
Then make your target directory. In this case I’m doing Fedora 11:
mkdir -p /var/distro/Fedora11.i386 cd /var/distro/Fedora11.i386
Now you’re in the directory you’re going to install in. This is important as I reference this directory throughout this tutorial as $(pwd). If you cd out of this directory in the middle of these steps, you’re bound to run into problems.
Setup some basic items:
mkdir -p dev proc sys root etc var/{log/yum,lib/rpm}
mount -t proc none proc
mount -t sysfs none sys
cp /etc/resolv.conf etc/
You don’t need an fstab, but no harm in creating one. You’ll actually avoid some meaningless errors by creating it:
cat << EOF > etc/fstab /dev/xvda2 / ext3 defaults 1 1 /dev/xvda1 /boot ext2 defaults 1 2 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 EOF
Create your /dev/null device and give it the mark of the beast:
mknod dev/null c 1 3 chmod 666 dev/null
For Fedora 11:
rpm --root $(pwd) --import http://mirrors.kernel.org/fedora/releases/11/Fedora/i386/os/RPM-GPG-KEY-fedora wget http://mirrors.kernel.org/fedora/releases/11/Fedora/i386/os/Packages/fedora-release-11-1.noarch.rpm rpm --root $(pwd) --nodeps -ivh fedora-release-11-1.noarch.rpm
For CentOS 5:
rpm --root $(pwd) --import http://mirrors.kernel.org/centos/5/os/i386/RPM-GPG-KEY-CentOS-5 wget http://mirrors.kernel.org/centos/5/os/i386/CentOS/centos-release-5-3.el5.centos.1.i386.rpm rpm --root $(pwd) --nodeps -ivh centos-release-5-3.el5.centos.1.i386.rpm
Now install. This may take a while, depending on your internet connection speed.
yum --installroot=$(pwd) -y install kernel rootfiles passwd vim-enhanced wget strace grub \
openssh-server openssh-clients gcc patchutils diffutils gcc make rpm-build rpmdevtools sudo yum
Now wipe out the rpm db, it’ll get rebuilt next time it’s used:
rm -f var/lib/rpm/__db.00*
Lastly, don’t forget to restore your rpm arch configuration:
mv /etc/rpm/platform.orig /etc/rpm/platform
Now you can do this:
setarch i686 chroot $(pwd)
Anything you build while in this chroot is guaranteed to be completely 32bit and have no 64bit related build problems.