|
|
|
|
Compiling the Linux kernel By Mayank Sarup <mayank@freeos.com> The Linux kernel is the heart of the operating system. This is the software that takes care of the programs that are currently running on your system as well as handling the interactions of those processes with your hardware. The kernel will decide how much CPU time and usage is allowed to the various programs. Why would you need to compile a kernel? Well, the Linux kernel is what interfaces with your hardware and newer hardware is always out in the market. A newer kernel will probably support that hardware. Hardware might not be the only reason you will want to upgrade to a newer kernel. The kernel is not flawless code. There are always going to be bugs found and fixed. The kernel will need to be patched and re-compiled with these fixes in place. Getting the source The kernel source code will be included in the distribution that you use. Red Hat has the kernel source RPM's named kernel-source-2.2.14-5.rpm, whereas SuSE names the kernel source as lx_suse-2.2.14.SuSE-12.i386.rpm. The source should already have been installed under /usr/src/linux-2.2.x if you chose the standard installation. If not then you should install it off your distribution CD. If you would like to get the latest bleeding edge kernel then you will probably have to look elsewhere. Most Linux distributions do not carry the latest kernel in their distributions. Kernel.org is a good place to download the latest kernel from. Kernel.org carries older kernels too. All the even numbered kernel versions are stable production releases whereas the odd numbered releases will be the development releases. The development releases are not renowned for their stability as new features are added/removed, bugs are fixed. They're basically for hardcore programmer to test, debug, work on. At the end of all the testing, programming and debugging lies the stable kernel release. So 2.2 is a stable kernel release whereas 2.3 will be the development kernel release. This doesn't mean that kernel 1.x was a development kernel and 2.x is the stable release. Only the minor version number is taken into account. The minor number will be the second number. Once you read the download area on kernel.org, you will have a choice of several files to download. The files with the extension .tar.gz use the old gzip compression whereas the files with the extension .tar.bz2 use the more efficient bzip2 compression. The bz2 files are always significantly smaller than the .gz so you will always want to go in for these archives. The 2.2 kernels will be 10 MB or thereabouts compressed and should takes something like 70 MB uncompressed. Make sure you have enough room. Unpacking the source After you have downloaded the kernel, you will need to un-tar it. Move to /usr/src. Check out what directories you have in there. The usual structure would be that there will be a directory named after the kernel version number and there will be a symlink named linux that will point to this directory. If you find some older kernel under a directory linux here then you should move it to some other name before you extract the new kernel here. SuSE puts the kernel source in linux-2.2.14-SuSE and also puts in a symlink which points to this kernel directory. General convention is that the linux symlink should point to the kernel that you are currently compiling. Most of the patches will look for your kernel in /usr/src/linux so this link should be in place. Now to un-compress the kernel. You should be in /usr/src. You will have to be root to compile the new kernel. If it's a tar.gz file tar zxvf linux-2.2.16.tar.gz or gzip -dc linux-2.2.16.tar.gz | tar xvf - For bzip'ed file tar xIvf linux-2.2.16.tar.bz2 or bzip2 -dc linux-2.2.16.tar.bz2 | tar xvf - This should create a directory named 'linux' in here containing the new kernel. You might want to move this to a new directory the reflects the Linux kernel version and set up a symlink named 'linux' to point to this new directory. mv linux linux-2.2.16 ln -s linux-2.2.16 linux Compiling Now move into this directory. The first thing you need to do is to
create a configuration to use for the kernel compile. Run the following
command make menuconfig This will bring up a menu based configuration interface. This requires ncurses to be installed. If you're in X then you can use 'make xconfig' to use a GUI interface to do the same. You will need tcl installed for this. Whatever you use, you will now be looking at a menu with various categories. Inside each category you will see various options with a box next to it. Possible options are Y(yes), N(no) and M(module). Yes would mean that support for that particular option is compiled right into the kernel. No would exclude that option. Choosing module will mean that support for that option will be built as a module. A module will include support for that particular option but instead of support for that component being included into the kernel, it will be created as a separate file that can be loaded into memory when required. The kernel is getting bigger and bigger all the time as support for more hardware and features are added. Using modules will help you reduce the size of the kernel. You should be careful with what you select as a module and what you compile or leave out of the kernel. Support for your sound card and your network card or printer can be a module, but, support for more essential hardware will need to be compiled right into the kernel. Support for the ext2 file system has to be compiled right into the kernel as does EIDE support for your block devices. If you are a newbie then I recommend that you leave the options selected by default and simply go ahead and compile the kernel. This should at least give you a good idea of what to expect when compiling the kernel. Once you have configured the kernel for your hardware and saved your configuration, you will need to run a 'make dep'. This will check that all the dependencies and include files are in place for compilation to take place. This will take only a short while. Next you will have to run 'make clean' to remove and old object files that may be have been left over from a previous version. This is not an essential step to take but it makes sense to do so anyway. 'make modules' will start compiling the various modules that you asked to build. 'make modules_install' will take the newly compiled modules and place
them in /lib/modules/ mv /lib/modules/2.2.16 /lib/modules/2.2.16.old
'make bzImage' starts the kernel compile. This will take a while
depending on your processing power and the options that you selected.
Watch the case here though. It is 'bzImage' and not 'bzimage'. This will
create a compressed kernel image. This reduces the size of the kernel and
is a good move unless you want a bulky kernel. Just about all kernels
these days are compressed. You do not have to make any special changes
your configuration to support compressed kernels. The kernel will
un-compress itself at boot.
You could also have put all the above commands in a single command-line
as
make dep clean modules modules_install bzImage
You can stop the kernel and module compilation at any time in between
by pressing Control-C. Then when you want to re-start the compile just run
'make modules' or 'make bzImage' again and the compile will start from the
point where you canceled it. If you make some changes to the configuration
at this point then you will need to run 'make dep' again and all
compilation will start right from the beginning.
The newly compiled kernel will be in usr/src/linux/arch/i386/boot as
bzImage. Here i386 should be replaced by the architecture that you're
compiling for.
Time to check out the new kernel. You will need to make a new lilo
entry for the new kernel. Do not simply replace your old kernel with the
new Edit /etc/lilo.conf and look for the entry that you use to boot into
Linux. This will look something like
image = /vmlinuz 'image = /usr/src/linux/arch/i386/boot/bzImage'
Also change the label to something like new
label = new
Leave the root entry as is.
Save the file and run /sbin/lilo to save the new settings.
Reboot your machine and at the lilo prompt enter 'new' to boot the new
kernel. If the system boots properly then one half of your work is done.
Now check out the various devices and see if you haven't missed out some
important device driver. If everything checks out then you can go ahead
and install the new kernel.
Go into /usr/src/linux and type 'make install'. This will install the
new kernel as /vmlinuz and install the new system map. Once that is done
you Jim Bradley has this additional advice if you have SCSI devices
and support has been compiled as a module.
With a scsi drive (or raid) the initial block device modules needed to
access the root filesystem are loaded in memory. When you recompile a
kernel, you also recompile the modules associated with that kernel, so you
need to remake the initrd images. With a scsi system, it was one of the
things that I had to learn first, because my new kernels never worked
unless I booted them off floppy.
Also check out the following URL for more information
http://mandrakeuser.org/install/kupgrade3.html
Hope this helps. If you have any problems or suggestions then please
send me a mail.
Kernel
Howto Other
articles by Mayank Sarup
Current Rating: [ 7.99 / 10 ] Number of Times Rated: [ 221 ]
|
|
© 1998-2004 FreeOS Technologies (I) Pvt. Ltd. All rights
reserved. [Privacy Policy]
|