I have built my Linux kernel (3.0.1) for my Raspberry Pi with these following steps:

1. Downloading kernel source
2. tar xvf source.tar.bz2
3. downloading arm cross compilation tool.
4. tar xvf arm-2010q1-202-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
5. setting up path for cross tool export PATH=$PATH:/home/shan/<cross tool folder>/bin/
6. after entering linux source dir make ARCH=arm versatile_defconfig (is this reliable   with raspberry pi)
7. make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-
8. zImage is generated in /arch/arm/boot

My question is, how can I build kernel.img? I think it contains zImage + ramdisk but how can I build this?

Can anyone guide me to making ramdisk and pack these two into kernel.img file? I want to boot this kernel on my Raspberry Pi.

  • This is a great question that I'm surprised hasn't been asked yet.
    – Jivings
    Commented Oct 14, 2012 at 22:27
  • Why are you using kernel 3.0.1? Is this vanilla kernel found on kernel.org site? Commented Oct 15, 2012 at 9:09
  • yes, I have found this from kernel.org Commented Oct 15, 2012 at 9:19
  • I have added a new question about qemu and crosscompiled raspberry pi-2 kernel with busybox in initramfs: raspberrypi.stackexchange.com/questions/56302/…
    – 42n4
    Commented Oct 13, 2016 at 15:33

2 Answers 2


kernel.img file

When using Linux kernel, kernel.img file is just a renamed linux/arch/arm/boot/Image. It should also be possible (or at least it was possible last time I checked) to use compressed version of this file - zImage. It can contain integrated initramfs (ramdisk) but it is not required. For example, stock kernel.img file does not contain initramfs while kernel_emergency.img does.

Note: Official kernel compilation guide on eLinux wiki suggest that you should use imagetool-uncompressed.py tool to prepare kernel.img file. It was necessary in early days of RaspberyPi but nowadays bootloader can handle regular Image and zImage files.

Kernel sources issue

What is very important is that when building kernel for RaspberryPi, you can't just use any version of it. Only special version that is ported to RaspberryPi will work. Unfortunately, current upstream version (found on kernel.org site) is not compatible with RaspberryPi. Also, versatil_config is not good for RaspberryPi, you should use bcmrpi_defconfig instead (found on RaspberryPi compatible kernel sources) or bcmrpi_emergency_defconfig if your plan on using buildin initramfs.

Kernel building instructions

The best place to grab kernel sources for RaspberryPi is on foundation github. You can also find some useful explaination on how to get it and how to compile it on official RasbperryPi wiki. Here's my little simplified version of the steps involved (NOTE: I assume you want to crosscompile the kernel. It is much faster and should create the same results but building kernel natively on RaspberryPi is also possible):

  1. Download official toolchain on create your own. Eigher way, I asssume it's installed in /usr/bin/arm-linux-gnueabi-*. If you have it in other place, you should change CROSS_COMPILE option in all your make commands.

  2. Go to https://github.com/raspberrypi/linux site where you can find official RapsberryPi kernel sources. You can download the code in two ways:

    • As a compressed file (to use this option you don't have to install git utility and you can do this even on RapsberryPi itself): Click on ZIP icon, a little below Code tab at the top of site. This should let you download lates source files as zip file. You could use git to do this instead but that (as described on the wiki) will need a lot more space and time. Then decompress the file to get source tree.
    • Using git utility (this didn't work for me on RaspberryPi as there is small amount of RAM probably but should work OK on desktop systems (note --depth 1 argument which prevents git from downloading whole history of the development (which is huge):

      git clone --depth 1 git://github.com/raspberrypi/linux.git
  3. Use default config supplied by foundation:

    cp arch/arm/configs/bcmrpi_defconfig .config
  4. Run make oldconfig and answer some questions (it should be ok to hit enter in each question leaving default answer):

    make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
  5. Compile the kernel:

    make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-
  6. Copy kernel modules to /tmp/modules:

    make ARCH=arm modules_install INSTALL_MOD_PATH=/tmp/modules
  7. Use Image file as kernel.img

  8. Upload all the modules to from /tmp/modules/lib/modules/ in your computer to /lib/modules/ directory on your RaspberryPi rootfs.

Adding initramfs

This does not provide instructions on how to create initramfs, however. Since this is very broad topic (basically, you have to create working Linux userspace environment ant there is really no limit on how complicated it can be), I won't cover this here now. I will only note that initramfs can be used in two different forms - standalone one, where it's separate file and buildin where it is integrated with kernel image file (like it's in kernel_emergency.img). The second option should be supported by RaspberryPi bootloader but there some rumors that it's broken on current firmware version so you should probably use buildin version.

The best way to start is to use working initramfs content (that is being used for kernel_emergency.img) by downloading it from another foundation github repository and only after you are able to boot the kernel using this iniramfs image, try building your own. All that should be needed for this is to point to the downloaded directory uing CONFIG_INITRAMFS_SOURCE kernel configuration option.

Final notes

So you should do this in 3 steps:

  1. Try building and booting kernel without initramfs file.
  2. Try adding ready initramfs content to your kernel.
  3. Change this initramfs content to suit your needs.
  • 1
    Great write up, but you shouldn't use zip; git efficiently transfers the files and you can use depth=1 to prevent downloading history (I think). Commented Oct 15, 2012 at 9:49
  • Yes, this is true but trying to do this on RaspberryPi itself is not really good idea. Downloading zip is working great, on the other hand. I will add short note about using git too. Commented Oct 15, 2012 at 9:51
  • Compiling the kernel on the Raspberry Pi is an awful idea in itself. Commented Oct 15, 2012 at 10:13
  • @AlexChamberlain: It's really slow but definitly possible (I've done this myself). It takes one night so it's not really that bad. Other than that, why is it so awful? Commented Oct 15, 2012 at 10:19
  • if I use bcmrpi_emergency_defconfig would it contains initramfs ?? Commented Oct 16, 2012 at 6:08

If you are running the same version of Debian on both, using X-Apt, dpkg-cross etc... and the emdebian tools can work very well.

Source: used to develop c++ apps for embedded ARM systems running emdebian.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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