# Raspberry Pi Kernel-o-Matic

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/022/818/medium800thumb/raspberry_pi_pngn_kernelomatic_with_logos.jpg?1448315686)

If you're ever needed to compile the Linux Kernel on a Raspberry Pi, you've probably noticed that it takes a long time. We sure have.

If you have a desktop computer or a laptop with decent hardware specs, it seems like there ought to be an easy way to use all that processing power to generate a new kernel for your Pi, but it can be tricky to figure out the specifics. Enter the [Adafruit Pi Kernel-o-Matic](https://github.com/adafruit/Adafruit-Pi-Kernel-o-Matic), which uses **Vagrant** to run a virtual machine pre-configured for compiling kernels and produces a package suitable for installation on a Raspbian machine.

Vagrant is for "creating and configuring virtual development environments".&nbsp; What does that mean?&nbsp; Well, really, it's a simple way to set up a virtual machine (VM) running an operating system of your choice. It uses&nbsp; **VirtualBox** to run VMs, and works on OS X, Windows, and Linux.

Getting a new kernel can be (almost!) as simple as:

```auto
cd Adafruit-Pi-Kernel-o-Matic
vagrant up
vagrant ssh
sudo ./build.sh
```

Interested? You'll just need to install a bit of software. Read on for specifics.

# Raspberry Pi Kernel-o-Matic

## Installing Dependencies

You'll need a couple of things installed on your workstation to get started. The Kernel-o-Matic runs inside of a Vagrant&nbsp;configured&nbsp;virtual machine running Ubuntu. You will need to have the **latest versions of Vagrant and VirtualBox** installed to use the Kernel-o-Matic.

Once installed, Vagrant will handle downloading and configuring the Ubuntu VM for compiling the Raspberry Pi Kernel. Use the links below to download and install the appropriate versions of VirtualBox and Vagrant for your operating system.

[VirtualBox](https://www.virtualbox.org/wiki/Downloads)
[Vagrant](https://www.vagrantup.com/downloads.html)
After you have installed Vagrant and VirtualBox, you can grab a copy of the latest version of Adafruit Kernel-o-Matic, and unzip the archive&nbsp;into a directory of your choosing.

[Kernel-o-Matic](https://github.com/adafruit/Adafruit-Pi-Kernel-o-Matic/archive/master.zip)
If you are comfortable with _git_, you can also clone a copy of the Kernel-o-Matic repo.

```auto
git clone https://github.com/adafruit/Adafruit-Pi-Kernel-o-Matic
```

Next, we'll look at how to launch and connect to&nbsp;the&nbsp;virtual machine.

# Raspberry Pi Kernel-o-Matic

## Starting the VM

Now that you have the required software, you can start the virtual machine (VM). To do that, open up a terminal or command prompt and&nbsp; **cd** into the directory where you extracted (or cloned) the Kernel-o-Matic.

Danger: 

![](https://cdn-learn.adafruit.com/assets/assets/000/022/802/medium800thumb/raspberry_pi_00_cd.jpg?1448315437)

Next we need to download, start, and provision the virtual machine. Luckily, Vagrant makes this simple, and we&nbsp;can do this all in one step by running&nbsp; **vagrant up.** &nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/022/804/medium800thumb/raspberry_pi_01_vagrant_up.jpg?1448315457)

It will take a few minutes for Vagrant to download and start your VM, and you'll see a long stream of text that describes in detail what Vagrant is currently working on. You may see something like&nbsp;"_Box 'ubuntu/trusty32' could not be found. Attempting to find and install..."._&nbsp;This is&nbsp;normal if you are using a fresh vagrant install.

You will be returned to the command prompt after Vagrant has finished setting up the virtual machine. You can connect to the VM by running **vagrant ssh.**

![](https://cdn-learn.adafruit.com/assets/assets/000/022/806/medium800thumb/raspberry_pi_03_vagrant_ssh.jpg?1448315495)

Now that you are connected to the Ubuntu VM, we are ready to look at the kernel build helper we wrote to make the process easier. The next section&nbsp;will show you the basics of using&nbsp; **adabuild**.

# Raspberry Pi Kernel-o-Matic

## Build the Kernel

Now that you have connected to the virtual machine, we&nbsp;can start the build process. First let's look at some of the build options included with the **build** kernel build helper.

You can view the build options by entering `sudo ./build -h`&nbsp;and pressing return.

```auto
$ sudo ./build -h
usage: build [options]
 This will build the Raspberry Pi Kernel.
 OPTIONS:
    -h        Show this message
    -r        The remote github repo to clone
              Default: raspberrypi/linux
    -b        The git branch to use
              Default: Default git branch of repo
    -1        The config file to use when compiling for Raspi v1
              Default: arch/arm/configs/bcmrpi_defconfig
    -2        The config file to use when compiling for Raspi v2
              Default: arch/arm/configs/bcm2709_defconfig
```

Let's look at the config options in more detail:

- **-h** &nbsp;shows you the usage instructions shown above.
- **-r** &nbsp;allows you to pass a&nbsp;GitHub repo in username/repo format that will be used instead of the official Raspberry Pi linux&nbsp;repo found here:&nbsp;[https://github.com/raspberrypi/linux](https://github.com/raspberrypi/linux)
- **-b** specifies the name of the git branch on the repo to use when compiling. If you do not supply a branch, the&nbsp;default branch of the selected git repo will be used.
- **-1** &nbsp;allows you to point to a custom config file for the Raspberry Pi v1 build. This can be an absolute path to a file on the virtual machine, or a relative path from the root of the selected git repo. By default the config file selected is&nbsp;[arch/arm/configs/bcmpri\_defconfig](https://github.com/raspberrypi/linux/blob/rpi-3.18.y/arch/arm/configs/bcmrpi_defconfig).
- **-2** &nbsp;allows you to point to a custom config file for the Raspberry Pi v2 build. This can be an absolute path to a file on the virtual machine, or a relative path from the root of the selected git repo. By default the config file selected is&nbsp;[arch/arm/configs/bcm2709\_defconfig](https://github.com/raspberrypi/linux/blob/rpi-3.18.y/arch/arm/configs/bcm2709_defconfig).

Now that you know what your options are, let's start a simple build of the latest version of the official Raspberry Pi kernel using&nbsp;the default build settings. To do that, we need to run `sudo build`.

![](https://cdn-learn.adafruit.com/assets/assets/000/022/808/medium800thumb/raspberry_pi_04_adabuild.jpg?1448315523)

After **build** &nbsp;finishes cloning a the required repos for building the kernel, you will be presented with a menu. This is the menu configuration for the kernel, where you can add or remove modules and capabilities. Tweak any options you want here; if you would like to use the defaults in the config file, it is safe to exit and save. Hit TAB and RETURN to exit, and RETURN again to confirm that you want to save.

![](https://cdn-learn.adafruit.com/assets/assets/000/022/809/medium800thumb/raspberry_pi_05_menuconfig.jpg?1448315545)

Now comes the part where you sit and watch a kernel compile. It takes about 15 minutes on a 2Ghz Intel i7 with 8 cores working to finish the kernel for the Raspberry Pi v1, but the compile time will vary depending on your machine.

![](https://cdn-learn.adafruit.com/assets/assets/000/022/810/medium800thumb/raspberry_pi_06_wait.jpg?1448315555)

Once the kernel for v1 has finished, you will be presented with the same menu again to configure the options for the Raspberry Pi v2 kernel build. Configure, exit and save the configuration to start building the kernel for the Raspberry Pi v2.

Once both builds have finished, **build** will create a tar.gz archive that you can transfer to&nbsp;your Raspberry Pi. The archive&nbsp;will be available in the Kernel-o-Matic folder on your host computer.

![](https://cdn-learn.adafruit.com/assets/assets/000/022/959/medium800/raspberry_pi_archive.png?1423500579)

If you would like to build something other than the current official kernel, you can use the options we went over earlier to change the git repo, git branch, and config files&nbsp;the compiler uses. Let's say you wanted to compile&nbsp;the _rpi-3.15.y_ branch of the [Adafruit fork of the Raspberry Pi kernel](https://github.com/adafruit/adafruit-raspberrypi-linux/tree/rpi-3.15.y), and use the [adafruit\_defconfig](https://github.com/adafruit/adafruit-raspberrypi-linux/blob/rpi-3.15.y/arch/arm/configs/adafruit_defconfig) configuration file&nbsp;found in the repo for the Raspberry Pi v1 build. The build command would look like this:

```auto
$ sudo build -r https://github.com/adafruit/adafruit-raspberrypi-linux -b rpi-3.15.y -1 arch/arm/configs/adafruit_defconfig
```

## Custom PiTFT Builds

If you would like to build a custom kernel with our PiTFT additions included, you should&nbsp;use the [pitft branch of the Kernel-o-Matic repo](https://github.com/adafruit/Adafruit-Pi-Kernel-o-Matic/tree/pitft). First, switch to the **pitft** branch in the cloned Kernel-o-Matic folder on your host machine.

```auto
git fetch && git checkout pitft
```

SSH back into the Kernel-o-Matic VM.

```auto
vagrant ssh
```

Then, run **build** with no arguments. The _pitft_ branch is pointed to the proper linux repo, branch, device tree overlays, and custom defconfigs for the PiTFT&nbsp;hardware.

```auto
sudo build
```

The rest of the build process will look the same as using the default settings described earlier, and you can use both instances of menuconfig to make any changes you would like to the kernel for both versions of the Raspberry Pi. A custom pitft tar.gz archive will be available in the Kernel-o-Matic folder on the host machine when the build has finished. In the next section, we'll show you how to install the custom kernel on your Raspberry Pi.

# Raspberry Pi Kernel-o-Matic

## Install the Kernel

Info: 

The easiest way to copy the resulting .tar.gz&nbsp;archive on to your Raspberry Pi is to mount a FAT32 formatted USB flash&nbsp;drive&nbsp;on your computer and copy the archive to that. The build process will output the archive&nbsp;to the Kernel-o-Matic folder with a name that starts with&nbsp; **custom\_kerne** l.

You can also use the latest version of the [Adafruit Pi Finder](https://github.com/adafruit/Adafruit-Pi-Finder#adafruit-raspberry-pi-finder)&nbsp;to copy the archive to your Pi over the local network.

![](https://cdn-learn.adafruit.com/assets/assets/000/022/958/medium800/raspberry_pi_Screen_Shot_2015-02-09_at_11.36.00_AM.png?1423499794)

[Adafruit Pi Finder](https://github.com/adafruit/Adafruit-Pi-Finder/releases/latest)
Now that you have the .tar.gz archive copied to your Raspberry Pi, you can extract the archive using **tar**. In this example, the archive we will be using is called _custom\_kernel\_1.20150207-1.tar.gz_. Replace the name of the example archive with the name of your custom kernel  
tar.gz archive.

```auto
$ tar xf custom_kernel_1.20150207-1.tar.gz
```

Next, we can use the bundled install script&nbsp;to install the package on your&nbsp;Raspberry Pi.&nbsp; **cd** into the extracted folder and run&nbsp; **sudo ./install.sh** to start the installation.

![](https://cdn-learn.adafruit.com/assets/assets/000/022/960/medium800thumb/raspberry_pi_install.jpg?1448315725)

If you don't see any errors from the install process, you can answer " **y**" to the reboot prompt to apply the changes **.**

![](https://cdn-learn.adafruit.com/assets/assets/000/022/961/medium800thumb/raspberry_pi_reboot.jpg?1448315731)

Finally, after the reboot, we can check to make sure that the package installed with&nbsp; **dpkg -s raspberrypi-bootloader.**

![](https://cdn-learn.adafruit.com/assets/assets/000/022/962/medium800/raspberry_pi_Screen_Shot_2015-02-09_at_12.15.26_PM.png?1423502145)

As you can see above, the custom build&nbsp;is the currently installed version on the Raspberry Pi.

That's all there is to building your own kernel! If you notice any bugs, please use the link below to file an issue on GitHub.

[Report a Bug](https://github.com/adafruit/Adafruit-Pi-Kernel-o-Matic/issues)

## Related Guides

- [Adafruit's Raspberry Pi Lesson 6. Using SSH](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh.md)
- [Running Minecraft on a Raspberry Pi](https://learn.adafruit.com/running-minecraft-on-a-raspberry-pi.md)
- [An Illustrated Guide to Shell Magic: Typing Less & Doing More](https://learn.adafruit.com/an-illustrated-guide-to-shell-magic-typing-less-and-doing-more.md)
- [Resizing the Raspberry Pi Boot Partition](https://learn.adafruit.com/resizing-raspberry-pi-boot-partition.md)
- [Set up and Blink - MATLAB and Simulink with Raspberry Pi](https://learn.adafruit.com/how-to-use-matlab-and-simulink-with-raspberry-pi.md)
- [Adafruit's Raspberry Pi Lesson 4. GPIO Setup](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup.md)
- [Using an External Drive as a Raspberry Pi Root Filesystem](https://learn.adafruit.com/external-drive-as-raspberry-pi-root.md)
- [Skill Badge Requirements: Raspberry Pi](https://learn.adafruit.com/skill-badge-requirements-raspberry-pi.md)
- [Adafruit Speaker Bonnet for Raspberry Pi](https://learn.adafruit.com/adafruit-speaker-bonnet-for-raspberry-pi.md)
- [Adafruit's Raspberry Pi Lesson 12. Sensing Movement](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-12-sensing-movement.md)
- [Teddy Ruxpin Rebuild](https://learn.adafruit.com/teddy-ruxpin-rebuild.md)
- [Synergy on Raspberry Pi](https://learn.adafruit.com/synergy-on-raspberry-pi.md)
- [Chumby Hacker Board](https://learn.adafruit.com/chumby-hacker-board.md)
- [A Quick Linux VM on Windows with Vagrant](https://learn.adafruit.com/a-quick-linux-vm-on-windows-with-vagrant.md)
- [Raspberry Pi Hosting Node-Red](https://learn.adafruit.com/raspberry-pi-hosting-node-red.md)
