KernelNewbies:

Developing on a native Linux platform

These instructions assume you're running a varient of Ubuntu (like 12.04 LTS).

Install some packages

First, open a terminal. Click the ubuntu logo at the top left corner and type "terminal". Click the terminal screen icon.

Next, run this command:

sudo apt-get install vim libncurses5-dev gcc make git exuberant-ctags

Setup your Linux kernel code repository

Once that finishes, run these two commands:

mkdir -p git/kernels
cd git/kernels

Then use the revision control system called [http://git-scm.com/ git] to clone Linus Torvalds' repository:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

That's going to take a while. Why don't you read up on [http://lwn.net/Kernel/LDD3/ Linux Device Drivers] in the meantime? The first couple of chapters, especially the ones on kernel modules will be useful.

Next, change into the linux directory:

cd linux

Now you need to compile the kernel. The first step is setting up your kernel configuration.

Setting up your kernel configuration

Many kernel drivers can be turned on or off, or built as modules. The .config file in the kernel source directory determines which drivers are built. When you download the source tree, it doesn't come with a .config file. You have several options on generating a .config file. The easiest is to duplicate your current config.

Duplicating your current config

If you're trying to see if a bug is fixed, you probably want to duplicate the configuration on your running kernel. That config file is stored somewhere in /boot/. There might be several files that start with config, so you want the one associated with your running kernel. You can find that by running uname -a and finding the config file that ends with your kernel version number. Copy that file into the source directory as .config. Or just run this command:

cp /boot/config-`uname -r`* .config

Changing your config

If you need to make any changes to your configuration, you can run one of the following commands. These require the curses tools to be installed.

make menuconfig

Building the kernel

Run

make

Or, if you have a multi-core processor, run

make -jX

Where X is a number like 2 or 4. If you have a dual core, 2 or 3 might be good. Quad core, 4 or 6. Do not run with really big numbers unless you want your machine to be dog-slow!

Let that compile, and maybe read some more of the [http://lwn.net/Kernel/LDD3/ Linux Device Drivers] book.

Note: when you run make with a .config file that was copied from a different kernel than the one you were building, you may be prompted to make choices about which new kernel features to enable. When in doubt, just choose the default choice. (You can do that by hitting enter.)

KernelNewbies: OutreachyfirstpatchAlt (last edited 2013-04-29 13:59:47 by SarahSharp)