Linux Kernel

From wiki-ben
Jump to: navigation, search

Basic Kernel Commands

Get the Kernel Version with:

uname -a

List all Loaded Modules in the Kernel with:


Remove a module (example removes the sound module):

rmmod sb

Insert a module (example inserts the sound module):

insmod sb

A better way to insert a module:

modprobe sb

Recompile The Linux Kernel

A custom kernel can be better for several reasons:

  1. Speed. When optimized for your particular hardware, the system will run faster.
  2. Convenience. A custom kernel that supports your hardware exactly will be easier to administer because you will not have to manually load modules if kerneld occasionally fails.
  3. Memory. A customized kernel may use slightly less memory.
  4. Security – Backdoors, malware, etc

The Linux kernel is released using a dotted triplet notation for the version number, e.g., 4.0.5. The first number indicates the major version, the second number indicates the minor version, and the third number indicates the patch level. Even numbered minor versions indicate a stable or production release. Odd numbered minor versions indicate development releases. It is also a very good idea to append a build number when building kernel, for example 4.0.5-r1. A monolithic kernel contains all the device drivers; it is configured for your current architecture. It runs marginally faster at boot time and uses a constant amount of RAM. A modular kernel loads and unloads drivers as needed and is less secure.

CAVEAT: Do NOT delete the existing kernel. Recompile the kernel, giving the new kernel a name that is different from the old kernel's name. As part of the compile process, new entries will be added to the /boot/grub2/grub.cfg file. Then reboot your system

Kernel Configuration

Using one of the build utilities we will first configure the kernel options to be compiled. These utilities must be run from the /usr/src/kernels directory. Whichever utility you choose, you will be offered a large number of kernel options to either select or unselect. Kernel features that can be modularized can be specified to be built as modules ("m"), built into the kernel ("y"), or not compiled at all ("n").Before configuring and compiling the kernel, ensure that the following packages have been installed:

  • glibc-devel
  • ncurses and ncurses-devel
  • gcc
  • kernel-source

Make Options

  • make clean: removes the temporary files from the source tree.
  • make: builds the complete source tree
  • make modules_install compiles the modules and installs them to /lib/modules
  • make install: installs all the newly built files and modules into the system directories.

Note: All source files are kept in /usr/src/kernels

Instalation Process

Steps go along as this

  2. Extract the tar file and copy to /usr/src/kernels</code
  3. You can configure the kernel with <code>make menuconfig. Note there are various other tools available aswell. Note you will need all dependencies listed in the "Kernel Configuration" section for menuconfig to work
  4. Go through the menu options and configure your kernel
    1. With menuconfig go to General Setup > Local Version and append "-R1" or some kind of extra signature to the end to identify your custom kernel
    2. With menuconfig you select "Save" and then "Exit" when you have finished
  5. Run make clean to clean the source files and remove any previous builds
  6. Run make -j 4. This will compile the kernel. The "-j" parameter is the number of cores the make process will use. Typically this step takes about 20 minutes with 4 cores
  7. After it has compiled run make modules_install
  8. Then run make install. This will install the kernel onto the system. There is very little screen activity on this step and the system may appear to be frozen. But it is fine, this step can take up to 5 minutes

Additional: GRUB Config

With modern Kernel compilers these steps are no longer necessary. This is helpful notes for configuring the GRUB on which kernel to boot into. By default it will be your newest kernel, you can change that though with the following:

Locate the grub.cfg file located in /boot/efi/EFI/fedora/grub.cfg for Fedora 22 and view the content. The file contains stanzas of each menu item that will be listed. By default you should see your custom one on the top of the list. You can identify your custom one with the appended "-R1" or other value added to its name.

To make your kernel default, place its section first on the list if it is not or change the default entry number to the appropriate number (note that it starts counting at 0) in the /etc/default/grub file.

For Example:


Alternativetly, specify the menu entry title. This is particularily useful if you a number of menu entries across various script files

GRUB_DEFAULT="Fedora Linux"

From now on, when the system boots you will see all of the available GRUB boot options corresponding to each of the stanzas in grub.cfg. The default kernel will be highlighted so if you do not press any keys the system will simply boot that one. Alternatively you can scroll to the desired kernel and boot that one

You can tell which kernel you are using with the uname -a OR uname -r commands