The Kernel and its Modules
Most kernels are compiled so modular support is required except many used on floppy boot disks.
The package modules.tar.gz contains all the programs needed to manage modules. This should already be installed on most distributions. The kernel modules are usually in a directory pertinent to the kernel version in /lib/modules. Modules can be found in "lib/modules/2.2.12-20" for kernel version 2.2.12-20. They are loadable modules ending in ".o" that are used to support the kernel.
To load a module type "insmod module" where "module" is the name of the module to load. Ex: insmod /lib/modules/2.2.12-20/misc/ftape.o
Programs used to manage modules are:
- lsmod - Lists all the currently loaded kernel modules
- rmmod - Unloads modules, Ex: rmmod ftape
- depmod - Creates a dependency file, "modules.dep", later used by modprobe to automatically load the relevant modules.
- modprobe - Used to load a module or set of modules. Loads all modules specified in the file "modules.dep".
Modules are loaded from startup script files using "modprobe" to handle loadable modules automatically.
|modprobe -l |more||Lists all the modules available for your kernel|
|rmmod module_name||Remove a module from the kernel|
Finding the Kernel
Locate the kernel image on your hard disk. It should be in the file /vmlinuz, or /vmlinux. In some installations, /vmlinuz is a soft link to the actual kernel, so you may need to track down the kernel by following the links.
On Redhat 6.1 it is in "/boot/vmlinuz". To find the kernel being used look in "/etc/lilo.conf".
Type "uname -a" to see the kernel version.
Compiling the Kernel
- Backup the present kernel which is in "/boot" for most systems. You can tell where it is by looking at "/etc/lilo.conf" . sometimes lilo.conf will point to a link file. Trace the link file and backup the file being pointed to.
- Have an alternate way to boot such as another linux system on your computer or an emergency boot disk that you can access your filesystem from in case your new kernel crashes.
- Back up your kernel modules in the directory "/modules". There is probably a directory full of modules so you should be able to back it up using "cp –dpr dir1 dir2" where dir1 is the name of the directory where your modules are and dir2 is where you want to put them.
- Go to "/usr/src/linux". There is a "/usr/src/linux/.config" file used to do the compile. It is modified by typing "make config" and the values in it are used to determine defaults while doing the "make config". Back this file up to keep your original settings if you want.
- Type "make config" and answer the hundreds of questions asked. On another terminal, open the file "/usr/src/linux/Documentation/Configure.help" to determine what each configuration is. Also you can type "make menuconfig" or from an X session "make xconfig".
- Type "make dep"
- Type "make clean"
- Type "make bzImage" or "make zImage" if the kernel is small.
- Type "make modules"
- Type "make modules_install"
- Copy the file "/usr/src/linux/arch/i386/boot/bzImage" to "/boot/vmlinuz".
- Copy the file "System.map" from "/usr/src/linux" to the "/boot" directory. Rename it "System.map=w.x.y" and make sure there is a link file called "System.map" pointing to it. This step will keep you from getting warning messages when you boot. It seems to be a step they forgot to include in the kernel-howto.
- cp /usr/src/System.map /boot/System.map-2.2.14
- cd /boot
- rm System.map
- ln –s System.map-2.2.14 System.map
- Run rdev on the new kernel image to verify the root filesystem device. "rdev /boot/vmlinuz /dev/hda2". Please note that this step may be optionally dependent on whether you want to use the boot loader, lilo, to point to the root device.
- Make sure the /etc/lilo.conf file is correct (image=/boot/vmlinuz)
- If your kernel has a feature supported by a module that is required to boot, you will need to make a RAM disk boot image or your system won't boot.
- Run lilo by typing "lilo". If you didn't set the root device in step 12, you will need a line like "root=/dev/hda2" in /etc/lilo.conf in the group of commands for your kernel. This will tell the kernel where your root filesystem is.
This step may be necessary if you are using a kernel previous to the 2.2 series. In the directory "/usr/include" may be several link files such as "asm", "linux", and "scsi". These are normally softlinks through "/usr/src/linux". If they are, you can direct the softlink file "usr/src/linux" to your new kernel file which may be in the form "linux-2.2.14". If you don't have the "linux" softlink file and don't want to create it, you will need to remove and redirect the softlink files in "/usr/include" to the proper location of your new kernel source.
The sysctl tool
This tool is worth mentioning in this section since it is used to manipulate kernel parameters. If you type "sysctl -a |more" you will see a long list of kernel parameters. You can use this sysctl program to modify these parameters. However, I have been unable to add new parameters.