Creating 32bit Debian packages in 64bit environments
i386 systems are dying off and therefore building 32bit Debian packages in 64bit environments is important if you still need packages for i386. For some recent projects I had to set up 64bit-only environments with the need to provide 32bit packages for i386 as well as according i386 Linux kernel packages.
1) Common Debian packages
Just prepend the “linux32” command to the build commands and use the “-a386” option of dpkg-buildpackage(1). So use “linux32 dpkg-buildpackage -ai386”, “linux32 git-buildpackage -ai386”, “linux32 debuild -ai386”,… or whatever build tool you prefer to work with. I personally like using “git-buildpackage … -S” together with cowbuilder. When using cowbuilder it’s easy to get i386 Debian packages:
# create initial cow base directory, needs to be executed just once: cowbuilder --create --basepath /var/cache/pbuilder/wheezy32.cow \ --architecture i386 --distribution wheezy --mirror http://ftp.de.debian.org/debian # the "debbuildopts -b" says I want a binary-only build, see dpkg-buildpackage(1): linux32 cowbuilder --build --basepath /var/cache/pbuilder/wheezy32.cow \ ~/foobar_0.42.dsc --debbuildopts "-b"
2) Debian Kernel packages
If you’re building your own kernel images you might be aware of setting ARCH for the common make targets, like:
ARCH=i386 make oldconfig
To build a linux-image Debian package you can use upstream’s deb-pkg target, like:
ARCH=i386 make deb-pkg
This should provide you according linux-headers, linux-firmware-image, linux-libc-dev and linux-image i386 Debian packages.
But if you need the according source and doc packages as well you might prefer make-kpkg of kernel-package instead, using options like:
DEB_HOST_ARCH=i386 setarch i386 make-kpkg --revision "$KERNELVERSION" \ --cross-compile - --arch=i386 --us --uc --initrd \ --rootcmd fakeroot kernel-image kernel-headers kernel-doc kernel-source
3) Debian linux-2.6 kernel packages
If you’re interested in building Debian kernel images the same way as the Debian kernel team does (AKA linux-2.6) make sure to check out the kernel-handbook.
After installing essential software packages I had to set up some symlinks for building:
apt-get install build-essential fakeroot devscripts fakeroot apt-get build-dep linux-2.6 ln -s /usr/bin/gcc-4.4 /usr/bin/i486-linux-gnu-gcc-4.4 ln -s /usr/bin/ld /usr/bin/i486-linux-gnu-ld ln -s /usr/bin/ar /usr/bin/i486-linux-gnu-ar ln -s /usr/bin/objcopy /usr/bin/i486-linux-gnu-objcopy ln -s /usr/bin/nm /usr/bin/i486-linux-gnu-nm ln -s /usr/bin/objdump /usr/bin/i486-linux-gnu-objdump ln -s /usr/bin/strip /usr/bin/i486-linux-gnu-strip
Then executing:
apt-get source linux-2.6 cd linux-2.6* debuild -ai386 -us -uc
provided the according Debian packages (linux-doc, linux-headers, linux-image, linux-libc-dev, linux-manual, linux-patch-debian, linux-source, linux-support and linux-tools).
4) Out-of-tree kernel module packages
If you want to build external modules which are available as $MODULENAME-source in Debian (e.g. tp-smapi-source) using module-assistant then use the DEB_HOST_ARCH environment variable, like:
DEB_HOST_ARCH=i386 m-a -v --text-mode -k /home/mika/linux-$KERNELVERSION -l $KERNELVERSION build tp-smapi
If the external module is not available for use with module-assistant then compile the module running:
make -C /lib/modules/$KERNELVERSION/build M=$(pwd)
whereas /lib/modules/$KERNELVERSION/build is pointing to the build directory of your 32bit kernel.