The following is a true idiot's guide - not for idiots, but written by an idiot - so please correct/extend/update as appropriate. == Download == First of all we need to download the kernel sources. There are three different ways you can do this, depending on what you want to do with the kernel. If you only want to recompile your kernel to add extra device drivers or change other kernel configfuration parameters, then by far your best course is to install/use the kernel sources package that comes with the Linux Distribution you're using. The same is true if you just want to learn about how the kernel works. If for some reason you need the latest kernel, and are willing to work with an unstable version, then you can download one of the tarballs from kernel.org. If you think you've reached the stage where you may eventually need to submit some changes back to the kernel development tree, then you need to use Git (the kernel source code control system) to get the latest and greatest versions, and to keep up to date with them. == Download Using a Distribution Kernel Source Code Package == The method of downloading the package will vary according to the distribution you are using, so you're pretty much on your own there. Note that the source code will probably be placed in a sub-directory under /usr/src. When using this method you need to be very careful that your newly compiled kernel won't overwrite the existing one (or you might not be able to boot any more...). Most distributions keep the two separately, but you need to understand how your system boots, and how kernels are selected before going too far down this route. == Download Using a Tarball from kernel.org == * Download your tarball from ftp.XX.kernel.org where XX is your [http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm 2 character country code]. If there isn't a mirror for your country, just pick a near one. * Unpack the tarball in your home directory {{{ bzip2 -dc linux-2.6.0.tar.bz2 | tar xvf - }}} (Replace bzip2 with gzip if you downloaded the .gz) == Download Using Git == Git is the source code control system used in the kernel. You need to download and install it. Next you need to choose a repository. The different kernel repositories are listed at [http://git.kernel.org/]. Most new developers will be contributing to an existing project, so the best way to find out which is the correct repository is to go to the home page for that project, and look there. For example, the USB project is hosted at [http://www.linux-usb.org/]. We'll use the linux/kernel/git/linville/wireless-2.6.git repository for the rest of this example. Create a new directory (which can be under your home directory), and cd to it, and run: {{{ git clone git://git.kernel.org/pub/scm/ + project path }}} which in our example would be: {{{ git clone git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-2.6.git wireless-2.6 }}} == Compile == === Configure the Kernel === You need to update the .config file in the root of your kernel tree to specify which facilities/drivers are built into the kernel. If you have used your distribution's source code distribution then it may have come with a suitably configured .configure. Alternatively there may be a suitable configure file in /boot that you can use with {{{make oldconfig}}} If you're using a tarball, or git to get the source code, then using an old .config file is a bit risky as it may not have all the new options defined for the new version of the kernel. You probably need to fall back on editing whatever .config came with your sourcode using either {{{make xconfig}}} or {{{make gconfig}}} depending on which one runs on your system. If you are running on a system with a SATA interface disk, then the default kernel configuration probably won't build. You'll need to convert some device drivers from modules to being compiled into the kernel. === Build the Kernel === {{{ make && sudo make install }}} === Configure the Boot System === You need to configure your boot system to make the new kernel one of the options. You probably don't want it to be the default at this stage. ==== Grub ==== The build should have installed the kernel in /boot and told you what it's called. If you're using grub, you now need to edit /boot/grub/menu.lst to add it to the list of possible kernels to boot from. You need an entry something like: {{{ title My development kernel root /dev/sda1 kernel /boot/vmlinuz-2.6.24-rc3 root=/dev/sda1 ro }}} root=UUID options don't seem to work at this stage. == Test == === Run the Kernel === Reboot, and select your development kernel from the list of kernels. === Useful Commands === dmesg will print out the kernel's ring buffer of trace messages.