Compiling a Linux Kernel

Make files and make targets

Build and install a versione 3 kernel

Dracut amd mkinitrd

runttime tools

  • Introduction to Compiling Kernels


Download latest kernel from


It sould be expanded into /usr/src/kernels/  where it will create  its own sub-directory structure

expanded in  /usr/src/kernels

sudo tar Jxvf linux-3.18.5.tar.xz -C /usr/src/kernels

Link your source to the working directyory /usr/src/linux

create simbol link ls -s

sudo ls -s /usr/src/kernels/linux-3.18.5 /usr/src/linux

Install prerequisite software

yum grouplist “Development Tools”

sudo yum grouplist “Development Tools”

Additionally, we need to install ncurses-devel  package to provide an ncurses based menu for module selection


  • Ensuring the Pre-requisites Are Met

Ensuring the Pre-requisites Are Met.


sudo tar -Jxvf linux-3.128.5.xz -C /usr/src/kernels/

ls /usr/src/kernels/linux-3.18.5/

we have all the information  for compiling kernel

we create simbol link

sudo ln -s /usr/src/kernels/linux-3.18.5/  / usr/src/linux

cd /usr/src/linux/

Ensuring the Pre-requisites Are Met


yum grouplist “Development Tools” 

double check

yum groupinfo “Development Tools”  – list package available with package group

sudo yum groupinstall “Development Tools”

sudo yum install ncurses-devel

sudo yum install ncurses-devel.png




  • Understanding the Steps in Compiling a Kernel


Compiling a Kernel in /usr/src/linux

make mrproper 

make dist clean 

make menuconfig 

make bzImage

make modules

make modules_install

make install


  • Compiling a Version 3 Kernel



pwd -P


make clean

make menu config

make menu config


Kernel configuration


File System

Kernel File System

Kernel File System 2



ls -a

see the .config  file

make bzImage  <– start compiling a Kernel


start compiling a Kernel


Kernel: arch/x86/boot/bzImage is ready (#1)

make modules

(for 1 hours or 2 hours )

make modules_install

make install  

copy across a kernel create system map files, copy acrso config file, edit grub file , create initialization ramdisk , edit the group file

copy across the kernel create system files.png


less /etc/grub.conf   –> check groub configuration


ls /boot      with system map conf gile


uname -r



make install

the last step  in the compilation process that we have just seen is a real time server,

mkinitrd and dracurt


mkinitrd  – generate the inintrd ram disck

as a kernel is compiled the ram disk may also need to change

Contains drivers not compiled into the kernel that are required to access to root files-system




mkinitrd now calls dracut

still creates an initramfs

dracut relies on udev and scripts to lessen the amount of hard-coded activity in the initramfs

reducing boot-time and size of initramfs


  • Kernel Runtime Tools and Troubleshooting

Device Drivers

These are tuypically kernel modules that are loaded as required into the running kernel. They are managed with lsmod and modprobe along with options that can be configured in /etc/modprobe.d/


Display all Drivers

modprobe -l

List Loaded Drivers

lsmod   – list all drivers currently loaded

cat /proc/modules


Unload a Loaded Driver


modprobe -r sr_mod     (-r unload the driver)

modprobe -rv sr_mod  (-v show in the verbose mode)

In the background rmmod is used




modprobe sr_mod

modprobe -v sr_mod

inmod  dependecy

view dependecy

modinfo sr_mod


Loading Modules with Options



for automate we can add to  modprobe.conf

Loading modules with Options


View loaded module options

Having loaded a module with options or parameters these can be viewed in


cat /sys/module/sr_mod/parameters/xa_test


  • Using Troubleshooting Tools

cat /proc/modules

modprobe -l

modprobe -r sr_mod

modprobe -rv sr_mode   

modinfo sr_mod

Using Troubleshooting Tools


load module

modprobe -v sr_mod  xa_test=1

cat /sys/module/sr_mod/parameters/xa_test

cd /etc/modprobe.d/



create a new file

vi sr_mod    

options sr_mod xa_test=1

modprobe -rv sr_mod


mv sr_mod sr_mod.conf

modprobe -v sr_mod

modprobe example



summary Compiling a Linux Kernel.png