Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to compile a kernel for a 32bit single-core Intel Atom machine. Needless to say, the compile is taking inordinate amounts of time. It's been going for 2 hours and it's still only halfway through the driver modules.

Compiling a kernel on my main desktop only takes 15 minutes but it's a 64bit machine. Can I cross compile to generate a 32bit kernel package from the better machine?

share|improve this question
    
Virtual machine can do it , but it will be slower –  Tachyons Nov 13 '12 at 12:25
    
Yeah and I could dual boot, but I'm sure it's possible to compile thing for other platforms from without leaving the current environment. –  Oli Nov 13 '12 at 12:47
    
That is interesting +1 ed –  Tachyons Nov 13 '12 at 13:03

2 Answers 2

up vote 23 down vote accepted
+200

While the kernel can be cross-compiled, the easiest way is to create a 32bit (i386) chroot and build it in there.

Install ubuntu-dev-tools:

$ sudo apt-get install ubuntu-dev-tools

Create an i386 chroot:

$ mk-sbuild --arch=i386 precise

(You will probably have to run that twice. The first time, it installs schroot etc. and sets up mk-sbuild)

Then enter the chroot:

$ schroot -c precise-i386

And build the kernel, as you would, normally.

share|improve this answer
9  
Building in a chroot is exactly the preferred method as used by developers in the Ubuntu kernel team. –  Colin Ian King Nov 14 '12 at 9:44
    
Those are some pretty fancy looking tools. I'll give it a shot tomorrow. Thanks. –  Oli Nov 14 '12 at 16:54
    
Please expand on "as you would normally". I would normally follow the instructions at help.ubuntu.com/community/Kernel/Compile but they do not work inside a chroot - the build dies with 'fatal error: linux/compiler.h: No such file or directory' –  Alistair Buxton Apr 28 '13 at 20:54

Afaik, in gcc, you can set -m32 flag to let it compile linux sources to 32bit executables. I don't have a wide knowledge about Makefiles, but you can tweak them.

edit: I wanted to add a question from stackoverflow here, in which it is told to set cflags:

export CFLAGS=-m32

And from the linux repository in Torvalds' github account, I found following section on the main makefile that you may find useful, as it tells that you can set a target architecture by setting an environment variable. Read the comments, currently, these lines are from this file, between lines 174-196:

# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
#
# When performing cross compilation for other architectures ARCH shall be set
# to the target architecture. (See arch/* for the possibilities).
# ARCH can be set during invocation of make:
# make ARCH=ia64
# Another way is to have ARCH set in the environment.
# The default ARCH is the host where make is executed.

# CROSS_COMPILE specify the prefix used for all executables used
# during compilation. Only gcc and related bin-utils executables
# are prefixed with $(CROSS_COMPILE).
# CROSS_COMPILE can be set on the command line
# make CROSS_COMPILE=ia64-linux-
# Alternatively CROSS_COMPILE can be set in the environment.
# A third alternative is to store a setting in .config so that plain
# "make" in the configured kernel build directory always uses that.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH        ?= $(SUBARCH)
CROSS_COMPILE   ?= $(CONFIG_CROSS_COMPILE:"%"=%)

# ...
# There are more architecture related stuff beyond this line
share|improve this answer

protected by Braiam Feb 14 at 3:01

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.