LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices

Reply
 
Search this Thread
Old 10-17-2008, 05:45 PM   #1
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Rep: Reputation: 48
Compile 32-bit kernel on a 64-bit machine


Hi,

I am running Debian Lenny on AMD X2 64-bit Dual Core processor.
Code:
Linux debian 2.6.26 #1 SMP Thu Oct 9 17:33:13 PDT 2008 x86_64 GNU/Linux
Now I am trying to compile a 2.6.26 kernel (32-bit kernel) for a 32-bit machine (target machine) on my current 64-bit machine (i.e. cross-compiling) but I am getting error when I run make-kpkg:

Code:
debian:/usr/src/linux-2.6.27# fakeroot make-kpkg --initrd --arch i386 kernel_image kernel_headers
exec debian/rules  DEBIAN_REVISION=2.6.27-10.00.Custom    KPKG_ARCH=i386  INITRD=YES  kernel_image kernel_headers 
dpkg-architecture: warning: Specified GNU system type i486-linux-gnu does not match gcc system type x86_64-linux-gnu.
dpkg-architecture: warning: Specified GNU system type i486-linux-gnu does not match gcc system type x86_64-linux-gnu.
dpkg-architecture: warning: Specified GNU system type i486-linux-gnu does not match gcc system type x86_64-linux-gnu.
dpkg-architecture: warning: Specified GNU system type i486-linux-gnu does not match gcc system type x86_64-linux-gnu.

====== making target CONFIG-common [new prereqs: testdir]======

====== making target CONFIG-common [new prereqs: stamp-conf]======
This is kernel package version 11.001-0.1.
====== making stamp-arch-conf because of  ======

====== making target CONFIG-arch [new prereqs: stamp-arch-conf]======
====== making conf.vars because of Makefile .config ======

/usr/src/linux-2.6.27/scripts/gcc-version.sh: line 25: i486-linux-gnu-gcc: command not found
/usr/src/linux-2.6.27/scripts/gcc-version.sh: line 26: i486-linux-gnu-gcc: command not found
make[1]: i486-linux-gnu-gcc: Command not found
====== making target CONFIG-arch [new prereqs: .config conf.vars]======
This is kernel package version 11.001-0.1.
====== making target CONFIG/linux-headers-2.6.27 [new prereqs: CONFIG-arch]======

====== making target CONFIG/linux-image-2.6.27 [new prereqs: CONFIG-arch]======

====== making target CONFIG/linux-uml-2.6.27 [new prereqs: CONFIG-arch]======

====== making target CONFIG/linux-xen0-2.6.27 [new prereqs: CONFIG-arch]======

====== making target CONFIG/linux-xenu-2.6.27 [new prereqs: CONFIG-arch]======

====== making stamp-configure-arch because of  ======
====== making target configure-arch [new prereqs: stamp-configure-arch]======
====== making stamp-indep-conf because of  ======

====== making target CONFIG-indep [new prereqs: stamp-indep-conf]======
====== making target debian/stamp-kernel-conf [new prereqs: .config Makefile]======
/usr/bin/make CROSS_COMPILE=i486-linux-gnu- ARCH=i386 \
                oldconfig
make[1]: Entering directory `/usr/src/linux-2.6.27'
scripts/kconfig/conf -o arch/x86/Kconfig
#
# configuration written to .config
#
make[1]: Leaving directory `/usr/src/linux-2.6.27'
/usr/bin/make CROSS_COMPILE=i486-linux-gnu- ARCH=i386 prepare
/usr/src/linux-2.6.27/scripts/gcc-version.sh: line 25: i486-linux-gnu-gcc: command not found
/usr/src/linux-2.6.27/scripts/gcc-version.sh: line 26: i486-linux-gnu-gcc: command not found
make[1]: i486-linux-gnu-gcc: Command not found
make[1]: Entering directory `/usr/src/linux-2.6.27'
scripts/kconfig/conf -s arch/x86/Kconfig
make[1]: Leaving directory `/usr/src/linux-2.6.27'
/usr/src/linux-2.6.27/scripts/gcc-version.sh: line 25: i486-linux-gnu-gcc: command not found
/usr/src/linux-2.6.27/scripts/gcc-version.sh: line 26: i486-linux-gnu-gcc: command not found
make[1]: i486-linux-gnu-gcc: Command not found
make[1]: Entering directory `/usr/src/linux-2.6.27'
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  CC      kernel/bounds.s
/bin/sh: i486-linux-gnu-gcc: command not found
make[2]: *** [kernel/bounds.s] Error 127
make[1]: *** [prepare0] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.27'
make: *** [debian/stamp-kernel-conf] Error 2
debian:/usr/src/linux-2.6.27#
So basically I am getting errors like:
Code:
make[1]: i486-linux-gnu-gcc: Command not found
As per "man make-kpkg":
Code:
  --arch foo
              This is useful for setting the architecture when you are cross compiling. If you are not cross compiling, the architecture  is  determined  automatically.  The
              same  effect  can be achieved by setting the environment variable KPKG_ARCH.  The value should be whatever DEB_HOST_ARCH_CPU contains when dpkg-architecture is
              run on the target machine, or it can be an other architecture in a multi-arch set (like i386/amd64).
On searching for "i486-linux-gnu-gcc" I found that the package that needs to be installed is gcc which is already installed on my system.

How do I resolve this issue?

EDIT Here is the solution.

Last edited by kushalkoolwal; 08-02-2009 at 03:58 PM.
 
Old 10-17-2008, 07:40 PM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Did you explicitly set up a cross-compiler or you just changed the "arch"?

It should be possible to build on your 64-bit compiler if you can pass the "-m32" flag. Most of the CPU-specific features are actually selected in the kernel config file, so "-m32" should generate 80386 code and other kernel config selections will provide support for other features of your target x86 CPU.

If you need to provide an initramfs image and so on for your target computer, you will also need a copy of the files to go into that image.
 
Old 10-17-2008, 07:48 PM   #3
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48
Quote:
Originally Posted by pinniped View Post
Did you explicitly set up a cross-compiler or you just changed the "arch"?
Not sure what you mean by "explicitly set up a cross-compiler". All I did was to pass the -arch flag as mentioned in my above post. I did not do anything else?

Quote:
Originally Posted by pinniped View Post
It should be possible to build on your 64-bit compiler if you can pass the "-m32" flag. Most of the CPU-specific features are actually selected in the kernel config file, so "-m32" should generate 80386 code and other kernel config selections will provide support for other features of your target x86 CPU.
where do I pass the "-m32" flag? I don't see any options in the make-kpkg?
 
Old 10-17-2008, 10:49 PM   #4
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Well, you didn't set up a cross-compiler then. You're just lucky that the compiler on x86_64 will also compile for x86. You can edit the Makefile and add "-m32" to the CFLAGS list.
 
Old 10-18-2008, 11:35 AM   #5
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48
Quote:
Originally Posted by pinniped View Post
Well, you didn't set up a cross-compiler then.
Thanks for the tips. Out of curiosity is there any documentation that explains how to set-up a cross-compiler? I am assuming that the cross-compiling method is different than adding "-m32" flag?
 
Old 10-18-2008, 05:27 PM   #6
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Quote:
Originally Posted by kushalkoolwal View Post
Thanks for the tips. Out of curiosity is there any documentation that explains how to set-up a cross-compiler? I am assuming that the cross-compiling method is different than adding "-m32" flag?
A genuine cross-compiler is very different; you have to build the entire compiler and tool chain - linker, assembler, etc. To be useful for building more than just a kernel, you'll also have to build at least a libc library. Basically, you build gcc and the various tools to run on your machine but generate code for another machine. Managing the search paths and where various things are stored on your machine is the tricky part.

You can find links to documentation on setting up cross-compilers from the GCC project website. You can also look at the CLFS project in the Linux From Scratch project for an example of setting up a cross-compiler.
 
Old 06-15-2009, 05:48 PM   #7
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 48
Alright, after a month of research I found some answers to my original question.

Solution
If you natively want to compile a 32-bit kernel then you need to have 32-bit cross-compiling stuff installed as also mentioned by one of the members. However there is another way also to do the same - using debootstrap.

Last edited by kushalkoolwal; 08-02-2009 at 03:59 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i tell if 32 bit or 64 bit ubuntu is installed on a machine? lel4866 Linux - Software 15 05-08-2012 12:18 AM
how do I install 32-bit compiler libraries onto a 64-bit machine? charleycat Linux - Software 1 08-16-2007 01:45 PM
Installing 32 bit SUSE 10 in 64 bit machine me4linux Linux - General 2 01-22-2007 01:55 AM
64-bit distro usable with 32-bit machine? JapanMtlExpat Linux - Software 7 10-05-2004 11:53 PM
32 bit kernel on 64 bit AMD machine dipsae Linux - Software 5 10-01-2004 10:03 AM


All times are GMT -5. The time now is 05:19 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration