kernel

Linux Kernel cross compilation recipe on amd64 for i386 on Debian

  • Article Currently 2.23/5
  • 1
  • 2
  • 3
  • 4
  • 5

 Rating : 2.2/5 (30 votes cast)

Following my Linux Kernel compilation recipe on Debian here is another tip on how to cross compil a kernel on an amd64 machine for an i386 one.
 ##install necessary packages 
iman@debian:~$ sudo apt-get install libncurses5 libncurses5-dev libssl-dev kernel-package fakeroot build-essential util-linux
##get kernel 3.19.3
iman@debian:~$ wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.19.3.tar.xz

iman@debian:~$ tar -xvf linux-3.19.3.tar.xz
iman@debian:~$ cd linux-3.19.3

##config-3.16.0-4-686-pae is Debian config file from its current kernel (available in the distribution linux-image .deb)
iman@debian:~/linux-3.19.3$ cp ~/config-3.16.0-4-686-pae .config && yes "" | linux32 make oldconfig

##optional : configure kernel
#iman@debian:~/linux-3.19.3$ make menuconfig
##if not first compilation
#iman@debian:~/linux-3.19.3$ make-kpkg clean

##set compil at full speed
iman@debian:~/linux-3.19.3$ export CONCURRENCY_LEVEL=`grep "cpu cores" /proc/cpuinfo | head -1 | cut -d":" -f2 | cut -c2-`
##compil kernel image and kernel headers (headers are optional)
iman@debian:~/linux-3.19.3$ fakeroot linux32 make-kpkg --cross-compile - --arch=i386 --initrd --revision=1+i --append-to-version=-`date +%Y%m%d` kernel-image kernel-headers

##at this point you have a 32bit kernel inside a linux-image-3.19.3-20150326_1+i_amd64.deb package and headers in linux-headers-3.19.3-20150326_1+i_amd64.deb but both labeled for 64bit arch

##let's label it i386
iman@debian:~/linux-3.19.3$ cd ..
iman@debian:~$ mkdir linux-image-3.19.3-20150326_1+i_i386 && cd linux-image-3.19.3-20150326_1+i_i386
##extract .deb
iman@debian:~/linux-image-3.19.3-20150326_1+i_i386$ ar x ../linux-image-3.19.3-20150326_1+i_amd64.deb
##extract control.tar.gz & data.tar.xz
iman@debian:~/linux-image-3.19.3-20150326_1+i_i386$ mkdir DEBIAN && tar xf control.tar.gz -C DEBIAN && rm control.tar.gz
iman@debian:~/linux-image-3.19.3-20150326_1+i_i386$ tar xf data.tar.xz && rm data.tar.xz
iman@debian:~/linux-image-3.19.3-20150326_1+i_i386$ rm debian-binary

##edit DEBIAN/control and replace "Architecture: amd64" by "Architecture: i386"
iman@debian:~/linux-image-3.19.3-20150326_1+i_i386$ sed -i 's/Architecture: amd64/Architecture: i386/g' DEBIAN/control
cd ..

##repackage the modified .deb
iman@debian:~$ dpkg-deb -b linux-image-3.19.3-20150326_1+i_i386
##now you've got your linux-image-3.19.3-20150326_1+i_i386.deb
##same method applies for linux-headers-3.19.3-20150326_1+i_amd64.deb

##copy .deb to your 32bit machine and install :
iman@msiwind:~$ sudo dpkg -i linux-image-3.19.3-20150326_1+i_i386.deb linux-headers-3.19.3-20150326_1+i_i386.deb

##reboot then :
iman@msiwind:~$ uname -a
Linux msiwind 3.19.3-20150326 #1 SMP Thu Mar 26 20:10:01 CET 2015 i686 GNU/Linux


ThnxX :
sukhanov.net
linuxfr.org

Linux Kernel compilation recipe on Debian

  • Article Currently 2.44/5
  • 1
  • 2
  • 3
  • 4
  • 5

 Rating : 2.4/5 (39 votes cast)

 ##install necessary packages 
iman@debian:~$ sudo apt-get install libncurses5 libncurses5-dev libssl-dev kernel-package fakeroot build-essential
##get kernel 3.10
iman@debian:~$ wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.tar.xz

iman@debian:~$ tar -xvf linux-3.10.tar.xz
iman@debian:~$ cd linux-3.10

iman@debian:~/linux-3.10$ cp /boot/config-`uname -r` .config && yes "" | make oldconfig

##optional : configure kernel
#iman@debian:~/linux-3.10$ make menuconfig
##if not first compilation
#iman@debian:~/linux-3.10$ make-kpkg clean

##set compil at full speed
iman@debian:~/linux-3.10$ export CONCURRENCY_LEVEL=`grep "cpu cores" /proc/cpuinfo | head -1 | cut -d":" -f2 | cut -c2-`
##compil kernel image and kernel headers
iman@debian:~/linux-3.10$ fakeroot make-kpkg --initrd --revision=1+i --append-to-version=-`date +%Y%m%d` kernel-image kernel-headers

iman@debian:~/linux-3.10$ cd ..
iman@debian:~$ sudo dpkg -i linux-image-3.10.0-20130701_1+i_amd64.deb linux-headers-3.10.0-20130701_1+i_amd64.deb

##reboot then :
iman@debian:~$ uname -a
Linux debian 3.10.0-20130701 #1 SMP Mon Jul 1 09:55:44 CEST 2013 x86_64 GNU/Linux