Compiling the Raspbian kernel and modules

If you want to enable a Linux component that isn't provided by default in the Raspbian kernel or as a kernel module, you can compile a new kernel, or compile a module for the existing one (though you'll still need to compile the kernel to do that.)

I am not an expert at this. However, the steps below work for me.

Install Ubuntu (Desktop or Server). I use a VirtualBox virtual machine in bridged networking mode.

Get your Pi's IP address with ip addr and look next to "inet". Note it for later.

Then, on Ubuntu:
sudo apt-get -y update
sudo apt-get -y install build-essential git
git clone git://
git clone git://
scp pi@X.X.X.X:\{/usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz,/proc/config.gz\} .
  (substitute your Pi's address for X.X.X.X, then enter your Pi's password; default is "raspberry")
cd ~/linux
fwhash=$(zcat ~/changelog.Debian.gz | grep -m 1 'as of' | awk '{print $NF}')
linuxhash=$(wget -qO-$fwhash/extra/git_hash)
git checkout $linuxhash
make mrproper
zcat ~/config.gz > ./.config
make ARCH=arm menuconfig
  (choose your kernel options; M means module, * means built into kernel)
~/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf- -k
mkdir -p modules
make modules_install ARCH=arm INSTALL_MOD_PATH=modules CROSS_COMPILE=\

You will find the modules in ~/linux/modules/lib/modules/*/kernel, and you can copy them to your Pi using
scp moduleName pi@X.X.X.X:
Once on your Pi, you can move or copy them from your home folder to the corresponding place inside /lib/modules/*/kernel.

If you want to use the newly built kernel, then on Ubuntu, type:
cd ~/tools/mkimage
./ ~/linux/arch/arm/boot/zImage
scp kernel.img pi@X.X.X.X:

Once the new kernel is on your Pi, you can move or copy it from your home folder to /boot, and restart to use it. I strongly recommend you first rename /boot/kernel.img to something like /boot/kernel_orig.img first so you can revert to it if needed.


Raspberry Pi Party