Developing on a native Linux platform
These instructions assume you're running a variant of Ubuntu (like 12.04 LTS).
Install some packages
Tip: You may want to pin the terminal app for easy access. Do that by hitting the Windows logo key, moving your mouse over the terminal icon on the left vertical menu, right clicking, and chosing "Lock to Launcher". You can make the menu go away by hitting the escape key.
sudo apt-get install vim libncurses5-dev gcc make git exuberant-ctags
Setup your Linux kernel code repository
mkdir -p git/kernels; cd git/kernels
Tip: mkdir creates directories, and cd changes the current working directory to a different directory. You can learn more about any command by reading the manual pages. Simply prefixing the command with the word "man", e.g. man mkdir.
Then use the revision control system called git to clone Greg Kroah-Hartman's staging tree repository:
git clone -b staging-next git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
That's going to take a while. Why don't you read up on Linux Device Drivers in the meantime? The first couple of chapters, especially the ones on kernel modules, will be useful. (Note that LDD3 is a bit outdated; the high-level overviews still make sense, but a few of the code examples are out of date. Still recommended to get a view of the kernel landscape, though.)
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
Building the kernel
Let that compile, and maybe read some more of the 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. A faster way to simply chose all the defaults is to run make menuconfig.This will set default values for unset features. Don't forget to save when you exit.
Installing the kernel
To install a kernel, you will need to either manually update your GRUB configuration file, or have an installkernel script. This script installs the kernel to /boot/, installs modules to /lib/modules/X.Y.Z/ (where X.Y.Z is something like 3.1.5), and updates file /boot/grub/grub.conf. Fortunately, Ubuntu provides an installkernel script in /sbin/installkernel. The grubby RPM provides it for RPM based systems.
sudo make modules_install install
su -c "make modules_install install"
Running your kernel
Linux stores both old and new kernel versions, so you can boot into your old kernel if you run into issues with your new kernel. The bootloader program called grub lets you chose which kernel you want to boot into.
The grub bootloader usually presents users with a choice of kernels and you can reboot into a known good kernel if your new compile doesn't work. Some distros (like Ubuntu) use a default grub configuration that hides that menu. You can usually get the menu to appear by mashing the ESC key during boot after the BIOS display disappears.
sudo vim /etc/default/grub
sudo apt-get install esmtp
Now you will be able to send email through git-send-email. However, we also recommend having a mail client installed that can handle plain text patch format. Our recommendation is a text-based email client called mutt:
sudo apt-get install mutt
sudo apt-get install git-email
sudo apt-get install gitk
gitk is a graphical git repository browser. You can use it to look at the state of your repository and the commits you've made on top of upstream. Just type gitk from within your kernel source directory.
That will make ctags for the source code. When you start editing code in vim from the base directory (git/kernels/staging/), you can use the CTRL+] to look up the definition of a function. See the ctags entry in the vim tips wiki for more info.
Yay, you're done setting up your kernel development environment! Now go start at these directions to get more instructions for how to modify the Linux kernel and send your first patch.