First steps

Choosing the Linux distribution

The first thing needed to start working with Raspberry Pi (like any other computer) is to choose and prepare the operating system. Even if we decide to use Linux we need to choose the right distribution. Although there are some official systems like Raspbian or Pidora (images are available here) based on popular Linux distributions and equipped with necessary drivers and configuration, we can also consider some less-known projects. My choice is the Minibian project – fast and lightweight distribution with low RAM and disk space requirements, without GUI environment. Unfortunately the project seems no longer supported but we are still able to compile new kernel versions from official repository.

Preparing SD card

To prepare working system we need one SD card (at least 1 GB) and the system image downloaded from project website. You can do it with your web browser or simply using wget.

tar -xf 2013-10-13-wheezy-minibian.tar.gz

After that you will have system image ready to put on the SD card. To do it first check the device name f.e. using lsblk command. For me it is /dev/sdc.

The next step is to unmount every /dev/sdc partition and copy the system image to the card, which will delete all data on it!

umount /dev/sdc1
umount /dev/sdc2
dd if=2013-10-13-wheezy-minibian.img of=/dev/sdc

For cards larger than 1GB there will be still some unused free space on the, which can be used to enlarge existing partition, or create new partitions. To do it you can use fdisk or gparted applications.

Your Pi is now ready to boot. Just put the SD card inside and power it on with the mini-USB cable (or charger). The system should boot automatically.

The more detailed description of the whole process can be found on Embedded Linux Wiki.

Connecting Pi

There are couple of ways to work with Pi. Personally, I think that the most convenient one is using SSH or serial cable. The first way is possible right after first boot. You need to connect Pi with your PC or router in local network with ethernet cable. There is a dhcp client running by default on Pi so find out its IP address and start the ssh connection (user: root, password: raspberry).

For the serial cable connection you need to configure the terminal in /etc/inittab file. Just uncomment and modify one line in the “Example how to put a getty on a serial line (for a terminal)” section (change the value 115200 to proper one for your serial adapter). This configuration is made for Adafruit serial cable.

You can do it on the Raspberry (during ssh session) or directly modifying the file on the SD card using host PC. In the first case reset will be required.

After that just connect with any serial terminal emulator, like screen.

sudo screen /dev/ttyUSB0 115200

Once again, you need to change the device name and speed for your own configuration.

Compiling a new Kernel

The last important thing is compiling a new kernel. It is necessary every time when we need to change the configuration or add new drivers or peripherals, so it is good to try it at the beginning of our adventure.

First we will need the kernel sourcecode and some tools to compile it. The newest kernel version and necessary software tools for Raspberry can be downloaded from official github repository. Although we could compile it on Raspberry it will took very long time. The better solution is to clone the source to host PC and use provided cross-compiler to build it. Following commands will create a local copy of last release of kernel and cross-compiler for Raspberry:

git clone
git clone

To make sure that there are no any other configurations and previously built files we should clean everything calling

make mrproper

It is necessary only if we want to make a fresh build. This can be skipped every time we want to use existing configurations and compiler output files, because building all files after every small change will take unnecessarily long time.

When we are dealing with fresh build (after downloading sources or calling make mrproper) we need to create new configuration file. The example file can be found inside the downloaded sources, so we only need to copy it to the main folder using:

cp arch/arm/configs/bcmrpi_defconfig .config

The compressed config file is also on the system partition inside /proc folder. We can copy it to the host from working Pi using scp command:

scp root@ .

Since we are building kernel for different hardware than our host PC, we need to tell the kernel’s makefile where the cross-compiler is. So let’s export its location to the CCPREFIX variable:

export CCPREFIX=/path/to/clonned/repository/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-

You can also add it to your PATH variable (for example inside the .profile in your home directory) and use only compiler prefix:


export CCPREFIX=arm-bcm2708hardfp-linux-gnueabi-

Before we start the kernel compilation we need to make sure our configuration fill is up to date. To do it we need to call:

make ARCH=arm CROSS_COMPILE=${CCPREFIX} oldconfig

This command completes the .config file with all missing parameters and needed by the new kernel. You will be asked to decide if some features should be enabled or disabled during the compilation. If you don’t know exactly what they mean you could leave everything default by pressing Enter.

Now it’s time to compile the kernel and its modules. Because the compilation takes place on the host, we can use more than one core to increase speed. It is possible by the -j option.

make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j6 modules

After the compilation ends we are ready to copy the newly built kernel on the SD card. It is good to first backup the old kernel (or just change its name). The kernel image is located inside the boot partition of SD card (the smaller one). Then juts copy the new image in the old’s place:

cp /media/8DFA-0D4E/kernel.img /media/8DFA-0D4E/kernel_old.img
cp arch/arm/boot/Image /media/8DFA-0D4E/kernel.img

/media/8DFA-0D4E is the mount point of my SD card boot partition.

The very last thing is to copy all the built modules to system partition by calling:
sudo make ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=/media/1b920f7d-119f-4ecf-8b95-e5cc6a67b8f1/ modules_install

/media/1b920f7d-119f-4ecf-8b95-e5cc6a67b8f1/ is the mount point of my SD card system partition, so you will need to change it.

Now you should be able to boot the Raspberry Pi with the newest kernel. If you want to check if you are running the one you’ve just compiled, type:

uname -a

The more detailed guide for kernel compiling is on


Leave a Reply

Your email address will not be published. Required fields are marked *