home   articles   archive   forum   masthead  
Published at 27.3.2000
Author: Jens Benecke
Translator: Andy Ziegler
Languages: de nl
Printer printer-version
Support Us!
 

Compile a kernel

Info For experienced Linux users, it is normal to frequently re-compile a new kernel because these users want the newest features and the latest tweaks for their PC.
Newbies are often shocked that it is possible to construct an OS built entirely from the source code. No surprise: Whoever compiled M$ Win with de-activated "features" before? No one!
Author: Jens Benecke

Short instruction

Become root and change directories to '/usr/src/linux'. Start a make menuconfig and everything that follows should be clearly described.

Comment: If X11 is running, make xconfig can be used and you can point and click to assemble your kernel components. You might have to execute xhost +localhost before. Now the root should be able to open an X windows on your X session. This would not be necessary if you started X as root, but you should avoid this because you expose the machine to many security problems.

Instead of starting X as root you should add root into the `.Xauthority' of the user who owned the X session. Now the root can access X without xhost. Look at

 
  >> man mkxauth
  

The first start-up of make xconfig could take a while because this configuration program is included with its source code and is compiled during the first call.

long instruction

The basic rule: Everything that is not absolute necessary for booting does not belong in the kernel and should to be loaded as a module. The exception should only be make if you constructed a stand alone firewall, a router or something similar. This is referred to as a "monolithic" kernel. On these machines usually are few hardware components and just a few programs are running.

But there are exceptions for everything. If a module did not work but it would function if you you included it into the kernel or just the other way around, then make it the way it works.

Please read the help for every component you select or deselect!
The default kernel has a quite good configuration that can be changed to your wishes. But if you tried something because it would sound cool you could be in big trouble. Also, the documentation should be read (RTFM - that's always recommended :D ).

The standard settings

You should activate the following options at least (also for computers without a network device)
  • Processor type and features: Select the CPU type and and also MTRR
  • Loadable Module Support: Enable loadable module support
  • Loadable Module Support: Kernel module loader (since 2.2 it is "kmod" and not "kerneld" any longer)
  • General Setup: Networking support, System V IPC, Process Accounting, Kernel support for ELF binaries
  • Plug and Play: Plug and Play support, Autoprobe for parallel devices
  • Block devices: Normal PC Floppy disk (as a module), loopback device (as a module)
  • Networking: TCP/IP networking, UNIX domain sockets
  • SCSI Support: Verbose SCSI error reporting (if a SCSI devices exist) to get more detailed error messages
  • Filesystems: Second extended filesystem support, Filesystems/Native Language Support: Codepage 437 and 850, ISO8859-1
  • Character devices: Virtual terminal, Support for console on virtual terminal, Standard generic (dumb) serial support, UNIX98 PTY support
  • Console drivers: VGA text console, Video mode selection support

As a module you should compile (if needed):

  • Basic Rule: everything you do not need for booting.
  • Network device support: except you mount the root file system via NFS or something similar.
  • every floppy, cdrom, tape, or other devices you do not boot from
  • every periphery device: serial/parallel, ISDN support
  • Binary support except of ELF (i.e. a.out, JAVA, "misc")
  • File system support except EXT2 (i.e. FAT, MSDOS, VFAT, ISO9660, etc)
  • PPP, SLIP, PLIP Support
  • sound card device
  • etc.

The reason is very simple: These rules save memory because the modules would be loaded only if they were really needed. After a specified time, the modules will be removed. It is more flexible because you can advise I/O addresses and IRQs in the moment you load the module. If the device were included in the kernel you would have to reload the system completely.

You should always set `Network support' to "YES" and at least bind one `dummy' network device into the system. Many programs use a network device even if no network card is included (because Linux is a network OS :). X windows is such a candidate; the printer spooler lpd also needs a network. If you own a real network you do not need the `dummy' device any longer, but it doesn't disturb anything if it's there.

After you finished the configuration, you `Exit', save with a click on `Yes' and type make dep clean modules zImage modules_install (the order after dep clean does not matter). Now it takes about 10 minutes (P166, 32MB) up to ten hours (386DX-33, 8MB) to compile the kernel. Of course, you can work on the computer in another console while you wait.

Installation of the kernel

After the compilation is finished, you will find a file with the name zImage at /usr/src/linux/arch/i386/boot/ which is the new kernel. You copy this one into the `root' directory (or to /boot, it is just important that the file has to be on the root partition) and add the following lines into the `/etc/lilo.conf' (if you used LILO to boot):

          image = /boot/zImage            # path to the new kernel file
          label = NewKernel               # max. 15 letters
  
This method requires a existing configured `lilo.conf' and does not change the existing settings (`root, boot, prompt', etc).

Execute a    /sbin/lilo

and lilo should use the new kernel as an additional option to boot from.
After a reboot, you can choose the new NewKernel at the `LILO:' prompt.
If the new kernel has run perfectly for a few days and you wanted to keep it as the standard kernel to boot you would edit the `/etc/lilo.conf' again. Just place the new lines in front of the lines of the first entry (or just add default=NewKernel to the first stanza of lilo.conf). Execute

/sbin/lilo
and everything is ready again.

It is not complicated to boot from a Dos or Windows via `LOADLIN'. Locate the old kernel you used before (usually on a DOS partition). Then you copy the new kernel e.g. called `new.img' in the same directory and use this one as the kernel file that is specified in the parameters of `LOADLIN' Read the docs on `LOADLIN' for more info.


This text is a part of the Linux USER FAQ and Jens Benecke allowed us to reprint it. He is one of the authors of this FAQ.

Links
   Author's homepage (Jens Benecke): http://www.jensbenecke.de
   Linux USER FAQ (German version): http://www.linuxfaq.de




Talkback Area




Enter Own Comment