You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Having a problem logging in? Please visit this page to clear all LQ-related cookies.

Introduction to Linux - A Hands on Guide

This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.

"Who am I? I am but the sum of my experiences..and today I am more than I was yesterday" - Terrabyte

Introduction

Welcome, I'm assuming that in coming here you've made the decision to have a go at compiling and using a new kernel so I won't go into the numerous reasons to make this decision. Compiling and setting up a kernel for the first time can be a daunting task even for users who are comfortable in everyday Linux use so I hope this guide will make the process a little easier and help get your new kernel up and running as fast as possible. Before I go on I must mention a few things, firstly if you are new to Linux or looking to get started then you are probably in the wrong place. I would recommend going to http://www.linuxiso.org and grabbing one of the distros from there which come with preconfigured kernel source's and nice graphical installers. They contain all you will need and there is a flavour for all users. Secondly, this guide is exactly what it claims to be, "Quick and dirty", (and not in _that_ way you perv :P ). I assume a level of competency with basic Linux commands and the environment. Also I wanted to keep this guide as short as possible so I won't be going into specific parts of the kernel or troubleshooting methods should something go wrong. If you need further assistance (although you shouldn't) check out the references section at the end of this document which explain the process in detail. Now, on with the show.....

Getting the kernel source

The kernel source can be downloaded from kernel.org. It is best to get one of the major releases (e.g 2.6.15) as opposed to one of the incremental increases between these (e.g. 2.6.15.6). By getting the major release you can patch to any of the incremental releases but you can also patch straight to the next major release (e.g. 2.6.16). This is more difficult if you get one of the incremental releases. Once you have the source move it into /usr/src. Also get the latest patch (at the time of writing this was 2.6.15.6) from kernel.org.
Unzip the kernel source and apply the patch as follows:

tar jxvf Linux-2.6.15.tar.bz2

cp -lR Linux-2.6.15 Linux-2.6.15.4

cd Linux-2.6.15.4

bzip2 -dc ../patch-2.6.15.4.bz2 | patch -p1 --dry-run

bzip2 -dc ../patch-2.6.15.4.bz2 | patch -p1

Step (iv) will show the exact same output as step (v) but it doesn't actually touch your kernel source tree. By using the dry-run option it will check to ensure that the kernel patch can be cleanly applied without screwing up your kernel source tree.

Configuring your new kernel

First you need to determine what type of hardware you have. This can be done using the command 'lspci'
You'll particularly need to know the IDE Chipset, Audio Controller, and the Ethernet Controller. You won't normally need to know your VGA Controller type when compiling the kernel. There are several methods of configuring the kernel with version 2.6

make config <--similar to 2.4. Most simplistic. Asks you about each option one at a time

make oldconfig <-- same as above but it uses your current .config file and only asks about new or changed options

make menuconfig <-- similar to menuconfig in 2.4.

make xconfig <-- QT based graphical system

make gconfig <-- Clone of xconfig except using GTK libraries.

We will be using make menuconfig. Its relatively simple to use and doesn't have many requirements. All you need are the ncurses dev files. In my opinion the QT and GTK installers just add unnecessary fluff. On debian a simple apt-get install libncurses5-dev should take care of that.

Now its really just a matter of going through the options an various menus and picking what suits your hardware and set up. If your unsure on anything you can highlight the option your unsure of and press ?. You can chose to compile things directly into the kernel (fill the box beside them with a * by pressing the space bar) or compile them as a module and insert them into the kernel as needed (by filling the box with an M). Certain things that are required to boot the kernel are best to be built in (such as IDE drivers etc) but for other non-critical stuff then its just as good, if not better, to build them as modules. At a later stage if you need to upgrade a driver thats compiled as a module you can just plug it out and insert the new one into the kernel but if its compiled in then a recompile of the kernel will be required.

NOTE: Support for your file system must be built into the kernel not as a module. Select the correct filesystem for the system you are currently running (e.g reiserfs, ext2, ext3 etc)

Building the new kernel

sudo make bzImage

Go make a cup of coffee or the beverage of your choice.

sudo make modules
Again, more drink (Starting to see a pattern? ;) )

sudo make modules_install
And more drink

If you wanted to minimise interruptions to your drinking time you could do
sudo make bzImage && make modules && make modules_install

You can also combine the make bzImage and make modules by typing 'make'. So the above command would become
make && make modules_install

The above commands can take quiet a while, as in close to an hour. If its a stock kernel from kernel.org (or elsewhere) it will be much faster than any of the distributions as it will have less to compile by default.

The modules will be copied into /lib/modules/KERNELVERSION

Installing the new kernel

Now its just a matter of copying the newly compiled kernel and System.map into /boot.
For me it looked like this

Now that the kernel is in place we just have to edit our boot loaders config file and add the new kernel.

If you are using the grub boot loader (and you probably are) this file is normally in /boot/grub and is called menu.lst. As I'm using Debian I can only guarantee it is there for my particular install. If you're using a different OS then check out its documentation for the correct location. Look at the other entries and copy their structure to add your new kernel to the list. You must be root. Ignore the initrd option as we haven't created one and they aren't normally necessary. For further info on editing your grub config file check out the GRUB manual.

If your boot loader is Lilo then you need to edit /etc/lilo.conf and then as root run /sbin/lilo to write the info to the MBR.