Linux Kernel

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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".
  6. Type "make dep"
  7. Type "make clean"
  8. Type "make bzImage" or "make zImage" if the kernel is small.
  9. Type "make modules"
  10. Type "make modules_install"
  11. Copy the file "/usr/src/linux/arch/i386/boot/bzImage" to "/boot/vmlinuz".
  12. 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
  13. 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.
  14. Make sure the /etc/lilo.conf file is correct (image=/boot/vmlinuz)
  15. 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.
    • Type "lsmod" and look to see if the "loop" module is loaded. If it is skip the next step.
    • Type "insmod /lib/modules/2.2.14/block/loop.o"
      Use this command if the loopback module is not installed. This assumes you compiled the support into your kernel. In my example, I used kernel version 2.2.14, but your kernel version may have a different number. Substitute the appropriate values.
    • Type "mkinitrd /boot/initrd-2.2.14.img 2.2.14"
      Again, this example is for kernel version 2.2.14. This command will create a RAM image module for your kernel to load into.
    • Add an entry similar to "initrd=/boot/initrd-2.2.14.img" to the "/etc/lilo.conf" file for the stanza that is used to boot this kernel. An example of the stanza follows.
       image=/boot/vmlinuz
        label=rhl
        initrd=/boot/initrd-2.2.14.img
        read-only
        root=/dev/hda2
        
      Read the section about LILO for more information or read the lilo and lilo.conf man pages.
  16. 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.

Comments

Popular posts from this blog

Running web ssh client on port 443 /80 with nginx as reverse proxy

Running cockpit behind nginx reverse proxy with nginx ssl and cockpit non ssl

Setup VOD streaming server with nginx using RTMP on Ubuntu 18.04