Kernel Introduced
Kernel is the core of operating system; it is the program that controls the basic services that are utilised by user programs; it is this suite of basic services in the form of system calls that make an operating system “UNIX”.
The kernel is also responsible for:
-CPU resource scheduling (with the associated duties of process management)
-Memory management (including the important implementation of protection)
-Device control (including providing the device-file/device-driver interface)
-Security (at a device, process and user level)
-Accounting services (including CPU usage and disk quotas)
-Inter Process Communication (shared memory, semaphores and message passing)
The Unix kernel acts as a mediator for your programs. First, it does the memory management for all of the running programs (processes), and makes sure that they all get a fair share of the processor’s cycles. In addition, it provides a nice, fairly portable interface for programs to talk to your hardware.
The kernel is physically a file that is usually located in the /boot directory. Under Linux, this file is called vmlinuz.
bash-2.05a# ls -l /boot/vm*
-rwxr-xr-x 1 root root 3007276 Mar 14 04:10 vmlinux-2.4.18-27.7.x
lrwxrwxrwx 1 root root 21 Mar 28 23:20 vmlinuz -> vmlinuz-2.4.18-27.7.x
You can see in this instance that the “kernel file” is actually a link to another file containing the kernel image. The actual kernel size will vary from machine to machine. The reason for this is that the size of the kernel is dependant on what features you have compiled into it, what modifications you’ve make to the kernel data structures and what (if any) additions you have made to the kernel code.
vmlinuz is referred to as the kernel image. At a physical level, this file consists of a small section of machine code followed by a compressed block. At boot time, the program at the start of the kernel is loaded into memory at which point it uncompresses the rest of the kernel.
An umcompressed kernel is really a giant object file; the product of C and assembler linking - the kernel is not an “executable” file (i.e. you just can’t type vmlinuz at the prompt to run the kernel). The actual source of the kernel is stored in the /usr/src/ directory; a typical listing may produce:
[bash-2.05a# /usr/src/ ls -l
total 8
lrwxrwxrwx 1 root root 19 Mar 28 23:19 linux-2.4 -> linux-2.4.18-27.7.x
drwxr-xr-x 17 root root 4096 Mar 28 23:19 linux-2.4.18-27.7.x
drwxr-xr-x 7 root root 4096 Mar 28 23:08 redhat
/usr/src/linux is a soft link to /usr/src/ - this means you can store several kernel source trees - however - you MUST change the soft link of /usr/src/linux to the version of the kernel you will be compiling as there are several components of the kernel source that rely on this.
Take note of the /boot/vmlinux* file - this is the uncompressed kernel! Notice the size? [vmlinuz is the .z (or compressed) version of vmlinux plus the decompression code]
Within this directory hierarchy are in excess of 1300 files and directories which consists of around 400 C source code files, 370 C header files, 40 Assembler source files and 46 Makefiles. These, when compiled, produce around 300 object files and libraries.
While this may seem like quite a bit of code, much of it actually isn’t used in the kernel. Quite a large portion of this is driver code; only drivers that are needed on the system are compiled into the kernel, and then only those that are required at run time (the rest can be placed separately in things called modules).
In the case of Linux, the following steps are performed to boot the kernel:
1) The boot loader program (e.g. lilo or grub) starts by loading the vmlinuz from disk into memory, then starts the code executing.
2) After the kernel image is decompressed, the actual kernel is started. This part of the code was produced from assembler source; it is totally machine specific. Technically at this point the kernel is running. This is the first process (0) and is called swapper. Swapper does some low level checks on the processor, memory and FPU availability, then places the system into protected mode. Paging is enabled.
3) Interrupts are disabled (every one) though the interrupt table is set up for later use. The entire kernel is realigned in memory (post paging) and some of the basic memory management structures are created.
4) At this point, a function called start_kernel is called. start_kernel is physically located in /usr/src/linux-2.4.18-27.7.x/init/main.c and is really the core kernel function - really the equivalent of the void main(void). main.c itself is virtually the root file for all other source and header files.
5) start_kernel sets up the memory, interrupts and scheduling. In effect, the kernel has now has multi-tasking enabled. The console already has had several messages displayed to it.
6) The kernel command line options are parsed (those passed in by the boot loader) and all embedded device driver modules are initialised.
7) Further memory initialisations occur, socket/networking is started and further bug checks are performed.
8. The final action performed by swapper is the first process creation with fork whereby the init program is launched. Swapper now enters an infinite idle loop.
It is interesting to note that as a linear program, the kernel has finished running! The timer interrupts are now set so that the scheduler can step in and pre-empt the running process. However, sections of the kernel will be periodically executed by other processes.



















