Compiling x86_64/AMD64 Kernels on Debian i386

|

This is the final item I wrote some time ago that I am Typo-ifying and reprinting here. This one is shorter, so the whole thing is reproduced below.

In the past, I have worked on several Opteron systems that are running Debian's Sarge release for i386. I wanted to keep using the i386 userland provided with Sarge, for compatibility and support reasons (as of this writing, Sarge is Debian's stable release). I also want a 64 bit kernel in order to allow the kernel to take advantage of 64 bit features, and to be able to run 64 bit versions of certain programs. Debian provides pre-built kernel packages built for AMD64 based systems, but I wanted to build my own.

First, get gcc-3.4. I just did apt-get install gcc-3.4. Next, get this shell script. It is a wrapper to gcc-3.4 which will call it with -m64 most of the time, but with -m32 when the kernel specifically wants to build 32 bit stuff like i386 assembly code. Put this script some place in your path; I just used /usr/local/bin. Now, assuming you have extracted your kernel source to /usr/src or something already, go ahead and change to the source directory and

make ARCH=x86_64 menuconfig

(or xconfig, gconfig, or whatever). Configure away, making sure that you enable "IA32 Emulation" in "Executable file formats / Emulations". When you're done there,

make ARCH=x86_64 CC=amd64-linux-gcc

to compile the kernel, then install it with something like

make ARCH=x86_64 CC=amd64-linux-gcc install modules_install

Make sure you tell grub where to find the new kernel (or you can probably use lilo, but why?!?), hold your breath, and reboot. If you're lucky, you will boot into a system with a 64 bit kernel, which can address tons of memory, use more registers, execute 64 bit binaries, etc. and still have a mostly 32 bit userland. Once you are running a 64 bit kernel, you will need to still use the CC=amd64-linux-gcc bit in the above commands, but you won't need ARCH=x86_64 (because the kernel build process will be able to detect that your current arch is x86_64). You may want to install some packages like amd64-libs and amd64-libs-dev so you can build other 64 bit programs.

Archives