# [SOLVED]Cross Compilling Kernel without genkernel

## Troopo

Hi,

I'm trying to build an i686 kernel on my amd64 machine for another machine.

Could not get clear instructions for that and spent a few hours trying to make it work.

Here are the steps i did, please take a look and tell me if something is missing:

```

sudo crossdev -t i686

sudo cp -r /usr/src/linux-4.4.6-gentoo/ /tmp/gen

cd /tmp/gen/

sudo make mrproper

sudo cp ~/Downloads/bla/config ./.config

sudo make ARCH=x86 CROSS_COMPILE=i686-pc-linux-gnu- all -j8

sudo make ARCH=x86 CROSS_COMPILE=i686-pc-linux-gnu- modules -j8

sudo make INSTALL_MOD_PATH=kernel_modules modules_install -j8

```

ThanksLast edited by Troopo on Sat Jun 25, 2016 8:14 pm; edited 1 time in total

----------

## Troopo

After that i copy everything to the other machine:

```

sudo genkernel --kernname=test --arch-override=x86 initramfs

sudo mv /boot/initramfs-test-x86-4.4.6-gentoo /mnt/test/iniramfs-test

sudo cp arch/x86/boot/bzImage /mnt/test/kernel-test

sudo cp System.map /mnt/test/System.map-test

sudo cp -r kernel_moudles/lib /mnt/test

```

And copy from test to the right places in the other machine /boot and /usr/lib

Then update grub2 cfg

Another question would be if there is a better\easier way to do this copy\install, initramfs and where does it say which modules folder does it use?

Hopefully i got everything right including the name conventions...

----------

## szatox

Hint:

```
alias make-armv7='make -j8 -l4 INSTALL_MOD_PATH=/usr/armv7a-hardfloat-linux-gnueabi/ INSTALL_PATH="/usr/armv7a-hardfloat-linux-gnueabi/boot/" ARCH=arm CROSS_COMPILE=/usr/bin/armv7a-hardfloat-linux-gnueabi-'
```

Now, the hard question: Why would you want to cross compile kernel for i686? Do you run your compilation on a SPARC?

If your build host is an x86_64 machine, you have 2 better options:

1) get 32 bit stage 3 and build in chroot

2) simply demand your native compiler to generate 32-bit code. It does work this way. I'm not sure which variable controls it, but I'd start with a close look at ARCH=

----------

## Troopo

 *szatox wrote:*   

> Hint:
> 
> ```
> alias make-armv7='make -j8 -l4 INSTALL_MOD_PATH=/usr/armv7a-hardfloat-linux-gnueabi/ INSTALL_PATH="/usr/armv7a-hardfloat-linux-gnueabi/boot/" ARCH=arm CROSS_COMPILE=/usr/bin/armv7a-hardfloat-linux-gnueabi-'
> ```
> ...

 

To be honest i'm rather new to this and didn't understand most of what you have said.

The example you gave seems to be related to ARM devices and most of what is there i already used as shown in my previous comments.

The situation is rather simple, i have 2 machines: first one is a PC which is the main one i use and it's x86_64 and the other is an old laptop which is only x86, i want to compile my kernel for the laptop in my main machine since it only takes a couple of mins while if i do this natively on the laptop it would take me about 11 hours.

So in short my host is x86_64 and my target is x86 only, i'm still having an issue figuring out the best way to create and initramfs as mentioned in my last comment.

Oh and all of this because that laptop seems to be having some kernel related issues with the FS so i'm experimenting with the options in order to fix it and that means multiple kernel compilations.

When i will have the time to go trough the options and optimize the kernel for my hardware that would be awesome but at the moment make all is the best i can do, and genkernel has an issue with cross compiling so i have to do it this way.

As a last note this is very educational for me  :Smile: 

Thanks.

----------

## bstaletic

There may be an even easier way. When you open kernel config there's an option that says something like "build 64bit kernel image". Try unchecking that and building as usual. There's also "-m32" flag for gcc, that tells gcc to produce 32bit code.

----------

## Hu

Compiling an x86-only kernel from an x86_64 system is natively supported without the use of a cross-compiler.  I had the same situation you describe: a powerful x86_64 and a slower x86-only and I routinely used the x86_64 to build for the x86.  I never installed an i686 cross-compiler.  You need to set ARCH=x86, either in the environment or on the Make command line.  You should start from a clean build area when you set that option for the first time.  If you still have trouble, please run make mrproper; export ARCH=x86; make menuconfig, make your choices, and then make.  If any steps fail, post which step failed and the output it produced.  You should not need to set compiler flags (such as -m32) explicitly.  Setting ARCH=x86 should cause the kernel build system to supply those flags automatically when they are appropriate.

Caution: make mrproper will delete your .config.  I prefer not trying to reuse a config across architectures, but you may want to save your existing config as a reference for what options to enable in the new x86 kernel.

----------

## Troopo

Thanks for your comments, i guess you are correct i don't really need to cross compile in this case but it was a possibility and cool one too  :Smile: 

I did learn a lot from this experience.

I'm marking this as resolved.

----------

