Previous | Next
Objectives|
Introduction|
Kernel Responsibilities of the Systems Administrator|
Valid Kernels|
Configuring the Kernel|
Modifying the Kernel|
Compiling the Kernel|
Conclusions|
Review Questions
Section 15
THE KERNEL
This section aims to introduce you to the kernel of a UNIX operating system. It will use the Linux kernel and its associated procedures as an example. By the end of the section you should
- be able to explain what a UNIX kernel is and what its responsibilities are,
- be able to list the components of a kernel,
- know what a patch file is,
- be familiar with the commands diff and patch,
- know the Systems Administration's responsibilities with respect to the kernel,
- be aware of what is involved with configuring the kernel,
- talk about the importance of keeping backup working kernels, and
- be able to compile, install and use a new kernel.
Anyone who states that the UNIX operating systems is harder to use than Windows is wrong. What they really mean to say is that the interface of Windows is easier to use than the UNIX interface (the shell).
The UNIX operating system (sometimes referred to as the kernel) is actually a conglomeration of functions, procedures and data structures that perform a variety of tasks. The only way in which someone may use the operating system is via a number of function calls called system calls.
The specific responsibilities of the operating system kernel are to
- provide a simple, efficient interface and management of the hardware of the computer, and
- provide a number of additional services for the use of other programs.
A Simple Interface
Writing programs that directly access computer hardware is difficult and hard to do correctly. In addition the ability to directly access the hardware of a computer means that it is very easy to bring a machine to its knees (just ask anyone who has learnt how to program in C on an MS-DOS box). An operating system kernel provides an easy to use interface to the hardware of the computer as well as protecting the bare hardware from interference.
The interface provided by the operating system is the set of system calls it understands. System calls are basically function calls that are used by user programs to access the services provided by the operating system.
The system calls that are understood by a UNIX operating system will be listed in the second section of the manual page (remember man 2 kill). All a user program knows about the operating system is the set of system calls it will understand.
Additional Services
The kernel also provides a number of "value added" services that are used by the systems processes. A UNIX kernel provides a number of services including
- managing the CPU,
- executing programs,
- scheduling input/output tasks,
- performing accounting and quotas,
- providing a logical file system,
- providing device drivers that control the variety of physical devices and how information is transferred between them and the computer,
- allocate and de-allocate memory between the various programs,
- provide a variety of security and protection abilities, and
- many more.
Most UNIX operating systems will come with the code of the kernel. The Linux operating system typically places the kernel code in the directory /usr/src/linux.
Exercise 15.1. Examine the kernel code for your system. List some of the different functionality included in the kernel.
Exercise 15.2. Count the number of separate source files and directories that make up the kernel source code. HINT: use a combination of the find and wc commands.
Exercise 15.3. Discover the list of system calls supported by your system. (Hint: examine the manual page for the man command and in particular look for mention of a shell variable MANPATH.)
The Systems Administrator has a number of responsibilities related to the kernel including
- ensuring the system has a valid kernel to boot with,
- configuring the kernel to represent the system's make up,
- modifying the kernel code, and
- compiling the kernel.
When a UNIX system boots, the bootstrap program will examine certain set places for a kernel. On most systems it will attempt to use a particular file from the root directory. The Systems Administrator must ensure that there is always a valid, working kernel in this location. If the kernel is incorrectly configured the system will not boot.
Reserve Kernels
When the Systems Administrator starts recompiling and installing new kernels there is always the possibility that a mistakes will be made. For example, in specifying the interrupt address for a network card you might enter the wrong value.
These types of mistakes may cause the kernel to freeze during initialisation. If the only bootable version of the kernel freezes during initialisation it can be very difficult to get the operating system functioning.
There should always be at least one backup method of starting the system including a backup kernel. The reserve kernel is used in cases where the primary boot method has failed for a variety of reasons.
In most cases the reserve kernel will be kept on
- a floppy disk,
- a CD-ROM, or
- a magnetic tape.
Exercise 15.4. Prepare a reserve kernel for your system. The process will be system specific. Under Linux examine the contents of the /usr/src/linux directory for instructions.
Exercise 15.5. Use the reserve kernel to reboot your system.
The kernel source tree will contain the code for a wide variety of purposes. In some cases it may not be necessary to include all of this source into the final kernel. For example, the kernel might contain code for a sound card driver. If you do not have a sound card then there is no point in including that device driver in the kernel.
The kernel does not contain code alone. It also includes a number of data structures used by the operating system.
For example:
Under Linux information about every process is stored in an array
containing elements of the following structure.
struct task_struct {
/* these are hardcoded - don't touch */
volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
long counter;
long priority;
unsigned long signal;
struct sigaction sigaction[32];
.
/* file system info */
int link_count;
int tty; /* -1 if no tty, so it must be signed */
unsigned short umask;
struct inode * pwd;
struct inode * root;
struct inode * executable;
struct vm_area_struct * mmap;
.
}
The size of this array is controlled by the following macro.
By changing this value a large system can handle more processes.
/*
* This is the maximum nr of tasks - change it if you need to
*/
#define NR_TASKS 256
Configuring the kernel is the act of deciding
- what sections of the kernel source tree should be compiled and included into the kernel,
When the system boots the entire kernel is loaded into RAM and it stays there while the machine running. The less code included in the kernel, the smaller it will be and the more RAM there will be for user programs.
- the size of some of the data structures.
Larger machines will require larger data structures than smaller systems.
The method used to configure the kernel will differ from system to system. Currently under the Linux operating system it is performed using the command make config inside the root directory of the kernel source tree.
This command runs a shell script that asks a number of questions about what should or should not be included into the kernel.
An Example make config
The following section lists some of the questions that Linux will ask during a make config. It is included here to provide an idea of what may be included in the kernel of a UNIX operating system. In addition to the questions there are some annotations explaining the questions. (Some of the questions have been left out due to space considerations.)
kernel math emulation?
used on systems without a math co-processor (386)
normal harddisk support?
Normal means one of ide, rll, mfm, esdi, etc. SCSI is not normal.
Xt hard disk support?
For MFM, RLL, ESDI Type drives on an 8 bit controller.
Not needed if you have a 16 bit card, or only IDE or SCSI.
Networking support?
Needed if you are going to connect to a LAN or use serial line TCP/IP
protocols like SLIP or PPP. As a suggestion it should be all the time.
Limit Memory to below 16M?
Answer yes if your physical memory is below 16Mb OR your motherboard
design prevents you from caching any RAM above 16Mb (systems with 64Kb
cache). If your machine has 128Kb or 256Kb cache and more than 16Mb of
RAM answer no.
SysV IPC? YES
Includes interprocess communication primitives that originated in SysV
based UNIX. Includes shared memory and semaphores.
use -m486 flag?
Performs optimisations for 486 based processes. Answer yes if you have
any type of 486 processor (including Pentiums).
Network Questions.
TCP/IP ?
Answer yes to this all the time. Even if you aren't on a network you
can use the loopback device to practice with networking software.
SCSI support?
Answer yes if you have a SCSI interface of any sort (including SCSI-2
and SCSI-3). If you do have a SCSI interface you will be faced with a
range of SCSI options.
Network device support?
Yes if you plan to use Ethernet cards to connect to a LAN.
Dummy net driver?
Not really necessary but can be useful for network programming.
SLIP?
Do you plan to use SLIP (serial line internet protocol) to connect to
a network?
CSLIP?
CSLIP is compressed SLIP, same answer as you gave to the SLIP question.
PPP?
PPP (point-to-point protocol) is another serial line internet protocol.
Load balancing?
Very experimental and should be left out.
The next set of questions will ask whether or not to include drivers for specific network cards. Basically if you have the card you include the driver.
After the network cards it will ask a number of questions related to CD-ROM drives. The following is the list of CD-ROM drives Linux supports.
Sony?
Mitsumi?
Matushita/Panasonic/(Some Creative Labs too)
After CD-ROMs come the file systems questions. If you want your kernel to support a different file system (MS-DOS for example) you must compile into the kernel the code for that particular file system. File systems supported by Linux include:
minix?
extended?
second extended?
The major file system used by Linux.
xiafs?
msdos?
/proc?
nfs?
NFS is the network file system.
iso9660?
The standard CD-ROM file system.
os/2 hpfs?
system V and coherent?
parallel printer support?
Yes if you want to use a parallel printer.
The next questions are related to drivers for various "non-standard" mice. You include them if you have one.
logitech bus mouse?
ps/2 mouse?
microsoft busmouse (This refers to the bus mouse not the normal serial mouse)
Atixl busmouse?
selection?
Allows you to cut and paste on the normal text screens. I've never used it and so don't include it. It appears to cause problems with bus mice.
QIC-02?
Qic 117?
Both specify a type of tape-drive. If you don't have one there is no
need to include it.
Sound card support?
Yes if you have a sound card. You will have to answer a number of
questions about various sound card options if you do.
kernel profiling?
Only really used when you are developing kernel code. When turned on
will generally slow the system down.
Exercise 15.6. Perform the necessary operations to configure the kernel on your system.
Reasons why a kernel may have to be modified include
- the addition of new devices or systems,
The addition of a brand new device will require the addition of new device drivers.
- removing errors from the operating system, or
- making personal modifications to the operating system.
The kernel source code contains a large number of source files spread throughout a rather complex directory hierarchy (sometimes referred to as the kernel source tree). It is not uncommon for there to be slight mistakes hidden away within this large array of files.
If a vendor discovers these errors there are two ways in which the problem can be fixed
- send out a whole new kernel source tree, or
- send out a small set of patches.
Sending out a whole new kernel source tree would be expensive because of the size of the media needed to distribute it. In most cases a small set of patches will be distributed.
Patching the kernel means applying patches to the kernel source tree to produce a slightly modified version of the kernel source.
What are Patch Files?
A patch file is a text file that is produced by the output of the diff command. The diff command is used to compare the differences between two (or more) files. The output of diff is the changes between the first file and the second one (see Diagram 15.1).
-
Diagram 15.1. Using diff to produce a patch file.
To produce a patch file the output of the diff command is redirected to a file. The patch command can then be used to change a file that looks like the first file into the second file (see Diagram 15.2).
-
Diagram 15.2. Applying a patch file.
Applying patches using the patch command will typically result in two files being created. In Diagram 15.2 the two resulting files are
- first.file which contains the modified file, and
- first.file.orig that contains a backup copy of the original file.
Most versions of patch will keep a backup of the original file. Some may use a different extension instead of .orig.
Exercise 15.7. Create a file called abc.doc that contains a number of lines of text. Create another file called def.doc that contains a modified version of what is in abc.doc. Produce and use a patch file to transform abc.doc so that it is exactly the same as def.doc.
Once the kernel is configured it must then be compiled into one 'executable' file or image. On most UNIX systems this will entail using some form of the make command.
The make command is used to compile and link a large number of source files according to some user specified rules. These rules are usually laid down in a file called a Makefile (it usually uses that as a filename).
The make command will take a number of parameters that will effect the way it works. In the previous section you saw how the command make config (using the Makefile in /usr/src/linux) runs a configuration script. The Linux kernel Makefile will also accept a number of different command line parameters.
These parameters include
- dep,
This checks the dependencies of the source files. Amongst other things it checks to see that all the files required actually exist.
- clean,
This cleans out any existing targets. A target is usually the end product of a make. For example in this case one of the files deleted (cleaned) will be any existing version of the kernel in the kernel source tree. This typically will not be the kernel you booted the system with. The Makefile will usually compile a version of the kernel and place it in the root directory of the kernel source tree. The new kernel must be moved to the appropriate location if the machine is to be booted with it.
- zlilo, and
Will place the final kernel image in a specific location on the hard-drive. The next time the system is booted it will use the new kernel. (This only works if you have lilo installed properly). On most systems the kernel will be placed into the root directory of the root file system.
- zImage.
Will place the final kernel image in a file called zImage in the /usr/src/linux directory. The idea is that this file is copied onto a floppy disk and that disk will be used to boot the system.
To install a kernel image onto a floppy you have to execute the following commands
- cp zImage /dev/fd0 OR dd if=zImage of=/dev/fd0
Both these commands will place the kernel image onto the floppy disk.
- rdev -R /dev/fd0 1
This copies into the kernel information about which hard-drive partition is the root partition. The kernel needs to know how to find the root partition when it starts up (it needs to find all the startup scripts, the init program etc.).
Typically you will not be able to use a boot floppy from your system on someone else's system.
The main reason being is that their root partition is not always guaranteed to be the same as yours. So when the kernel goes looking for the root partition and the files it is supposed to contain it will end up being disappointed.
Exercise 15.8. Compile a new kernel for your system. (This will typically take quite sometime).
Exercise 15.9. Carry out the necessary tasks to reboot your system using the new kernel.
The kernel is the basic, essential component of the UNIX operating system. Without it none of the services and functionality required to run user programs will be available. The Systems Administrator is responsible for ensuring that the kernel of a system is correctly configured and will work.
User programs access the kernel's functions by using system calls.
The type of operations a Systems Administrator might perform on a kernel include
- patching the kernel,
- configuring the kernel,
- making or compiling the kernel, and
- booting with the kernel.
15.1. What is a kernel?
15.2. What are some of the kernel related responsibilities that a Systems Administrator must fulfil?
15.3. What is the purpose of the patch and diff commands?
Previous | Next
David Jones (author)
Chris Hanson (html 10/09/96)