An operating system consists of several layers
We have looked at many applications: editors, servers, shells, utilities, compilers, ...
The O/O services layer is often called the kernel
An O/S strictly only needs a kernel - the rest is just application layers on top
Linux kernels have version numbers e.g 2.6.29 (try uname -a
)
Kernel source code is available from the Linux Kernel Archives at www.kernel.org
Most CPUs can run in several modes
A CPU in supervisor/kernel mode can access all h/w
A CPU in user-space mode has less access rights
The kernel usually runs in kernel mode, applications in user mode
When an application needs an O/S service, it must aks the CPU to switch modes
From Wikimedia Commons:
The Linux kernel is a monolithic kernel
Less stable - any buggy device driver can crash it
Fewer context switches, may be faster
An application can be compiled
This wastes space, especially if lots of applications all use the same libraries
Instead, an application can be compiled with "stubs" to dynamic link libraries
The DLL is linked in at runtime when needed
Uses less space, but may crash at runtime if the DLL is not available
See what dlls an application needs by running ldd
on the binary
$ldd /bin/ls
linux-gate.so.1 => (0xb7fe6000)
librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb7fca000)
libselinux.so.1 => /lib/libselinux.so.1 (0xb7fb0000)
libacl.so.1 => /lib/libacl.so.1 (0xb7fa7000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7e44000)
Linux dlls are usually of the form libXXX.so.N where N is the major version number
Typically, libXXX.so.N is a symbolic link
to libXXX.so.N.M e.g.
$ls -l /lib/libc.so.6
lrwxrwxrwx 1 root root 11 2009-04-24 21:33 /lib/libc.so.6 -> libc-2.9.so
By default, dlls are stored in /lib and /usr/lib. Other directories may be added by setting the environment variable LD_LIBRARY_PATH or by configuring ldconfig
Kernel modules are dlls for the kernel
They usually have the code for device drivers
They end in .ko and exist in /lib/modules/....
By using modules, the kernel can stay small, with modules loaded only as needed
Every piece of hardware needs a software device driver
Windows drivers are supplied by the vendor; Linux drivers are usually written by volunteers
There are drivers for: video cards, usb devices, SCSI devices, TV tuner cards, network drivers, character devices, sound cards, file systems, ...
Most of these can be compiled statically into the kernel or as loadable modules
Get the source files as a .tar.xz file and unpack it
by tar Jxf ...
Change to the toplevel directory and type
make xconfig
Choose the options you want and quit and save
Run make
Run make install
You may also need to run make modules_install
This will install a copy of the kernel in /boot and make an entry in /boot/grub/menu.lst
Next time you boot, you get the option of the new kernel
Find the list of loaded modules by lsmod
Load a new module by modprobe module-name
Unload a module by rmmod module-name